-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
103 lines (75 loc) · 3.48 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Copyright 2018 kWh Analytics
# Licensed under the Apache License, Version 2.0 (the "License");
# pyou may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
import datetime
import shutil
import urllib2
import os.path
from lxml import etree
from solar_document_types import SystemInstallationSheet
from solar_document_types import MonthlyOperatingReport
from orange_config import VALIDATION_TARGET_DIR, VALIDATION_API_URL
from unit_map import UNIT_MAP
from example_concept_map import EXAMPLE_CONCEPT_MAP
def pipe_to_arelle_server(xml_filename):
# copy the file to the ixbrl directory
shutil.copy2(xml_filename, os.path.join(VALIDATION_TARGET_DIR, "ixbrl"))
# GET request to localhost:8080 where Arelle container is running:
validation_url = "%s%s" % (VALIDATION_API_URL, xml_filename)
result = urllib2.urlopen(validation_url)
lines = result.readlines()
tree = etree.fromstring( "\n".join(lines[1:]) ) # Skip blank line at beginning
# Get text from all table cells:
table_rows = [x.text for x in tree.iterdescendants() if 'td' in x.tag]
table_rows = [x.strip("\n") for x in table_rows]
return table_rows
class InstallationXBRLTest(unittest.TestCase):
def setUp(self):
self.temp_file = "test_output_installation.xml"
def tearDown(self):
pass
def test_is_valid_xml(self):
mySheet = SystemInstallationSheet(UNIT_MAP, EXAMPLE_CONCEPT_MAP)
mySheet.addSystem(1, {"installer": "These guys I know",
"COD": "2018-01-21"})
mySheet.addSite(1, {"latitude": 42, "longitude": -170})
mySheet.addArray(1, {"tilt": 20, "azimuth": 180,
"capacity_dc_kw": 4.5,
"panel_manufacturer": "Hanwha",
"panel_model": "ROYGBIV"})
mySheet.addArray(1, {"tilt": 20, "azimuth": 180,
"capacity_dc_kw": 5.5,
"panel_manufacturer": "Kyocera",
"panel_model": "MST3K"})
mySheet.addInverter(1, {"capacity_ac_kw": 8.0,
"inverter_manufacturer": "Enphase",
"inverter_model": "THX1138"})
mySheet.toXML(self.temp_file)
table_rows = pipe_to_arelle_server(self.temp_file)
for row in table_rows:
print row
class MonthlyOperatingReportXBRLTest(unittest.TestCase):
def setUp(self):
self.temp_file = "test_output_report.xml"
def tearDown(self):
pass
def test_is_valid_xml(self):
myReport = MonthlyOperatingReport()
myReport.addData("sys1", datetime.date(2018, 1, 1), 1000, 1000)
myReport.addData("sys1", datetime.date(2018, 2, 1), 1000, 1000)
myReport.addData("sys2", datetime.date(2018, 1, 1), 1000, 1000)
myReport.addData("sys2", datetime.date(2018, 2, 1), 1000, 1000)
myReport.toXML(self.temp_file)
table_rows = pipe_to_arelle_server(self.temp_file)
for row in table_rows:
print row
if __name__ == '__main__':
unittest.main()