playtender_service.py
4.5 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# -*- coding: utf-8 -
from robot.libraries.BuiltIn import BuiltIn
from iso8601 import parse_date
def get_library():
return BuiltIn().get_library_instance('Selenium2Library')
def get_webdriver_instance():
return get_library()._current_browser()
# return of variable is None
def get_variable_is_none(variable):
if variable is None:
return True
return False
# check if condition is not none type and run specified keyword
def run_keyword_if_condition_is_not_none(condition, name, *args):
if get_variable_is_none(condition) == False:
BuiltIn().run_keyword(name, *args)
# return value for *keys (nested) in `element` (dict).
def get_from_dictionary_by_keys(element, *keys):
if not isinstance(element, dict):
raise AttributeError('keys_exists() expects dict as first argument.')
if len(keys) == 0:
raise AttributeError('keys_exists() expects at least two arguments, one given.')
_element = element
for key in keys:
try:
_element = _element[key]
except KeyError:
return None
return _element
# set scroll to element in view
def set_element_scroll_into_view(locator):
element = get_library()._element_find(locator, None, True)
get_webdriver_instance().execute_script(
'var $el = jQuery(arguments[0]); if($el.length) $el.get(0).scrollIntoView();',
element
)
# return text from hidden element
def get_invisible_text(locator):
element = get_library()._element_find(locator, None, True)
text = get_webdriver_instance().execute_script(
'return jQuery(arguments[0]).text();',
element
)
return text
# input text to hidden input
def input_text_to_hidden_input(locator, text):
element = get_library()._element_find(locator, None, True)
get_webdriver_instance().execute_script(
'jQuery(arguments[0]).val("' + text.replace('"', '\\"') + '");',
element
)
# select option by label for hidden select
def select_from_hidden_list_by_label(locator, label):
element = get_library()._element_find(locator, None, True)
get_webdriver_instance().execute_script(
'var $option = jQuery("option:contains(' + label.replace('"', '\\"') + ')", arguments[0]);' +
'if($option.length) jQuery(arguments[0]).val($option.attr("value"));',
element
)
# trigger change event for input by locator
def trigger_input_change_event(locator):
element = get_library()._element_find(locator, None, True)
get_webdriver_instance().execute_script(
'var $el = jQuery(arguments[0]); if($el.length) $el.trigger("change");',
element
)
# convert all numners to string
def convert_float_to_string(number):
return repr(float(number))
# prepare isodate in needed format
def isodate_format(isodate, format):
iso_dt = parse_date(isodate)
return iso_dt.strftime(format)
# prepare data
def prepare_procuring_entity_data(data):
try:
data['name'] = u"Playtender"
data.identifier['id'] = u"playtender"
data.identifier['legalName'] = u"Playtender"
data.identifier['scheme'] = u"UA-EDR"
if 'name_en' in data:
data['name_en'] = u"Playtender"
if 'legalName_en' in data.identifier:
data.identifier['legalName_en'] = u"Playtender"
if 'address' in data:
data.address['countryName'] = u"Україна"
data.address['locality'] = u"Київ"
data.address['postalCode'] = u"01111"
data.address['region'] = u"місто Київ"
data.address['streetAddress'] = u"вулиця Тестова, 220, 8"
if 'contactPoint' in data:
data.contactPoint['email'] = u"chuzhin@mail.ua"
data.contactPoint['faxNumber'] = u"+3801111111111"
data.contactPoint['telephone'] = u"+3801111111111"
data.contactPoint['name'] = u"Test"
if 'name_en' in data.contactPoint:
data.contactPoint['name_en'] = u"Test"
data.contactPoint['url'] = u"https://playtender.com.ua"
except Exception:
raise Exception('data is not a dictionary')
# prepare data
def prepare_buyers_data(data):
if type(data) is not list:
raise Exception('data is not a list')
# preventing console errors about changing buyer data in cases
if len(data) != 1:
return
item = next(iter(data), None)
item['name'] = u"Playtender"
item.identifier['id'] = u"playtender"
item.identifier['legalName'] = u"Playtender"
item.identifier['scheme'] = u"UA-EDR"