Skip to content

Commit d65e2b1

Browse files
author
Agarwal
committed
Initial Commit
0 parents  commit d65e2b1

10 files changed

+865
-0
lines changed

StationReport.html

+428
Large diffs are not rendered by default.

asserter.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from logger import Logger
2+
3+
4+
def assert_true(value, message):
5+
result = value is True
6+
assert result, message
7+
Logger.log_assertion(expression=message, result=result)
8+
9+
10+
def assert_equal(value, reference, entity_name, compare_types=False):
11+
if compare_types:
12+
result = value == reference
13+
else:
14+
result = str(value) == str(reference)
15+
assert result, f'{entity_name} actual value [{value}] is not equal to expected value [{reference}]'
16+
Logger.log_assertion(
17+
expression=f'{entity_name} actual value [{value}] is equal to expected value [{reference}]',
18+
result=result
19+
)

assets/style.css

+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
body {
2+
font-family: Helvetica, Arial, sans-serif;
3+
font-size: 12px;
4+
/* do not increase min-width as some may use split screens */
5+
min-width: 800px;
6+
color: #999;
7+
}
8+
9+
h1 {
10+
font-size: 24px;
11+
color: black;
12+
}
13+
14+
h2 {
15+
font-size: 16px;
16+
color: black;
17+
}
18+
19+
p {
20+
color: black;
21+
}
22+
23+
a {
24+
color: #999;
25+
}
26+
27+
table {
28+
border-collapse: collapse;
29+
}
30+
31+
/******************************
32+
* SUMMARY INFORMATION
33+
******************************/
34+
#environment td {
35+
padding: 5px;
36+
border: 1px solid #E6E6E6;
37+
}
38+
#environment tr:nth-child(odd) {
39+
background-color: #f6f6f6;
40+
}
41+
42+
/******************************
43+
* TEST RESULT COLORS
44+
******************************/
45+
span.passed,
46+
.passed .col-result {
47+
color: green;
48+
}
49+
50+
span.skipped,
51+
span.xfailed,
52+
span.rerun,
53+
.skipped .col-result,
54+
.xfailed .col-result,
55+
.rerun .col-result {
56+
color: orange;
57+
}
58+
59+
span.error,
60+
span.failed,
61+
span.xpassed,
62+
.error .col-result,
63+
.failed .col-result,
64+
.xpassed .col-result {
65+
color: red;
66+
}
67+
68+
/******************************
69+
* RESULTS TABLE
70+
*
71+
* 1. Table Layout
72+
* 2. Extra
73+
* 3. Sorting items
74+
*
75+
******************************/
76+
/*------------------
77+
* 1. Table Layout
78+
*------------------*/
79+
#results-table {
80+
border: 1px solid #e6e6e6;
81+
color: #999;
82+
font-size: 12px;
83+
width: 100%;
84+
}
85+
#results-table th,
86+
#results-table td {
87+
padding: 5px;
88+
border: 1px solid #E6E6E6;
89+
text-align: left;
90+
}
91+
#results-table th {
92+
font-weight: bold;
93+
}
94+
95+
/*------------------
96+
* 2. Extra
97+
*------------------*/
98+
.log {
99+
background-color: #e6e6e6;
100+
border: 1px solid #e6e6e6;
101+
color: black;
102+
display: block;
103+
font-family: "Courier New", Courier, monospace;
104+
height: 230px;
105+
overflow-y: scroll;
106+
padding: 5px;
107+
white-space: pre-wrap;
108+
}
109+
.log:only-child {
110+
height: inherit;
111+
}
112+
113+
div.image {
114+
border: 1px solid #e6e6e6;
115+
float: right;
116+
height: 240px;
117+
margin-left: 5px;
118+
overflow: hidden;
119+
width: 320px;
120+
}
121+
div.image img {
122+
width: 320px;
123+
}
124+
125+
div.video {
126+
border: 1px solid #e6e6e6;
127+
float: right;
128+
height: 240px;
129+
margin-left: 5px;
130+
overflow: hidden;
131+
width: 320px;
132+
}
133+
div.video video {
134+
overflow: hidden;
135+
width: 320px;
136+
height: 240px;
137+
}
138+
139+
.collapsed {
140+
display: none;
141+
}
142+
143+
.expander::after {
144+
content: " (show details)";
145+
color: #BBB;
146+
font-style: italic;
147+
cursor: pointer;
148+
}
149+
150+
.collapser::after {
151+
content: " (hide details)";
152+
color: #BBB;
153+
font-style: italic;
154+
cursor: pointer;
155+
}
156+
157+
/*------------------
158+
* 3. Sorting items
159+
*------------------*/
160+
.sortable {
161+
cursor: pointer;
162+
}
163+
164+
.sort-icon {
165+
font-size: 0px;
166+
float: left;
167+
margin-right: 5px;
168+
margin-top: 5px;
169+
/*triangle*/
170+
width: 0;
171+
height: 0;
172+
border-left: 8px solid transparent;
173+
border-right: 8px solid transparent;
174+
}
175+
.inactive .sort-icon {
176+
/*finish triangle*/
177+
border-top: 8px solid #E6E6E6;
178+
}
179+
.asc.active .sort-icon {
180+
/*finish triangle*/
181+
border-bottom: 8px solid #999;
182+
}
183+
.desc.active .sort-icon {
184+
/*finish triangle*/
185+
border-top: 8px solid #999;
186+
}

logger.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from datetime import datetime
2+
3+
4+
class Logger:
5+
6+
@classmethod
7+
def log(cls, text, to_console=True, to_file=True, with_date=True):
8+
if to_console:
9+
print(text)
10+
if to_file:
11+
cls.write_to_file(text, with_date)
12+
13+
@classmethod
14+
def log_request(cls, request_type, url, params, response_status_code):
15+
text = '\n'.join([
16+
f'Executed {request_type.__name__.upper()} request',
17+
f'URL: {url}',
18+
f'PARAMETERS: {params}',
19+
f'RESPONSE STATUS CODE: {response_status_code}'
20+
])
21+
cls.log(text)
22+
23+
@classmethod
24+
def log_assertion(cls, expression, result):
25+
text = '\n'.join([
26+
f'\nExecuted assertion:',
27+
f'EXPRESSION: {expression}',
28+
f'RESULT: {result}'
29+
])
30+
cls.log(text)
31+
32+
@classmethod
33+
def log_test_start(cls, test_function):
34+
cls.log(f'\n{"=" * 50}\n', to_console=False, with_date=False)
35+
text = f'TEST STARTED: {test_function.__name__}'
36+
cls.log(text)
37+
38+
@classmethod
39+
def log_test_finish(cls, test_function, execution_time):
40+
text = '\n'.join([
41+
f'\nTEST FINISHED: {test_function.__name__}',
42+
f'TIME ELAPSED: {execution_time}'
43+
])
44+
cls.log(text)
45+
46+
@classmethod
47+
def write_to_file(cls, text, with_date):
48+
current_date_n_time = datetime.now()
49+
if with_date:
50+
text = '\n'.join([f'{current_date_n_time} - {l}' for l in text.split('\n')])
51+
with open('tests_output.log', 'a', encoding='utf-8') as f:
52+
f.write(text)

session.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import json
2+
import requests
3+
from requests import RequestException
4+
from logger import Logger
5+
6+
7+
class HTTPSession:
8+
URL = 'https://api.test.virta-ev.com/v4/'
9+
10+
@staticmethod
11+
def send_request(request_type, endpoint, params):
12+
do_logging = params.pop('do_logging', True)
13+
try:
14+
response = request_type(endpoint, params)
15+
if do_logging:
16+
Logger.log_request(request_type, endpoint, params, response.status_code)
17+
return response.status_code, json.loads(response.text)
18+
except RequestException as e:
19+
Logger.log('Could not send {} request due to exception: {}'.format(request_type, e))
20+
21+
22+
class RequestTypes:
23+
GET = requests.get
24+
25+
26+
class Endpoints:
27+
STATIONS = HTTPSession.URL + 'stations'
28+
29+
30+
class StatusCodes:
31+
STATUS_200 = '200'

test_utils.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from datetime import timedelta
2+
from time import time
3+
from logger import Logger
4+
5+
6+
def decorate_test(test_function):
7+
def wrapper():
8+
Logger.log_test_start(test_function)
9+
time_delta, _ = measure_time(test_function)
10+
Logger.log_test_finish(test_function, timedelta(seconds=time_delta))
11+
12+
return wrapper
13+
14+
15+
def measure_time(function):
16+
start = time()
17+
result = function()
18+
end = time()
19+
return end - start, result
20+
21+
22+
class Constants:
23+
id = 'id'
24+
latitude = 'latitude'
25+
longitude = 'longitude'
26+
name = 'name'
27+
city = 'city'
28+
country = 'country'
29+
provider = 'provider'
30+
evses = 'evses'
31+
eves_group_name = 'groupName'
32+
eves_connectors = 'connectors'
33+
type = 'type'
34+
max_kw = 'maxKw'
35+
36+
37+
class DataModel:
38+
station_data_length = 1
39+
id_value = 8617
40+
latitude_value = 60.164102
41+
longitude_value = 24.899113
42+
name_value = 'Test station advanced pricing'
43+
city_value = 'Helsinki'
44+
country_value = 'FI'
45+
provider_value = 'Virta'
46+
evses_length = 2
47+
evses_id = 8616
48+
eves_group_name = ''
49+
evses_connector_type = "Mennekes"
50+
evses_connector_max_kw = 0
51+
52+
53+
class RequestParams:
54+
lat_min_key = 'latMin'
55+
lat_max_key = 'latMax'
56+
long_min_key = 'longMin'
57+
long_max_key = 'longMax'
58+
lat_min_value = 60.164101
59+
lat_max_value = 60.164104
60+
long_min_value = 24
61+
long_max_value = 25

tests/__init__.py

Whitespace-only changes.
164 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)