Commit 9033b08738d1976306c4f32bef8357e315ab3486
1 parent
ad8efa9b
Added load_initial_data_from and improved log_object_data keywords
Showing
2 changed files
with
50 additions
and
10 deletions
1 | 1 | # -*- coding: utf-8 - |
2 | - | |
3 | -from munch import munchify, Munch | |
2 | +import os | |
3 | +from munch import munchify, Munch, fromYAML | |
4 | 4 | from .initial_data import ( |
5 | 5 | test_tender_data, test_question_data, test_question_answer_data, |
6 | 6 | test_bid_data |
7 | 7 | ) |
8 | + | |
9 | +from dateutil.parser import parse | |
10 | +from dateutil.tz import tzlocal | |
11 | +from datetime import datetime, timedelta | |
12 | + | |
13 | +from json import loads as convert_from_string_to_dict | |
8 | 14 | from openprocurement_client.client import Client |
9 | 15 | from datetime import datetime, timedelta |
10 | 16 | from StringIO import StringIO |
11 | 17 | from robot.output import LOGGER |
12 | 18 | from robot.output.loggerhelper import Message |
19 | +from robot.libraries.BuiltIn import BuiltIn | |
13 | 20 | |
14 | 21 | |
15 | 22 | def prepare_api(key=''): |
... | ... | @@ -21,12 +28,20 @@ def prepare_test_tender_data(): |
21 | 28 | return tender |
22 | 29 | |
23 | 30 | |
24 | -def log_object_data(data): | |
31 | +def log_object_data(data, file_name=""): | |
25 | 32 | if not isinstance(data, Munch): |
26 | 33 | data = munchify(data) |
27 | - LOGGER.log_message( | |
28 | - Message(data.toYAML(allow_unicode=True, default_flow_style=False), "INFO") | |
29 | - ) | |
34 | + data = data.toYAML(allow_unicode=True, default_flow_style=False) | |
35 | + LOGGER.log_message(Message(data, "INFO")) | |
36 | + if file_name: | |
37 | + output_dir = BuiltIn().get_variable_value("${OUTPUT_DIR}") | |
38 | + with open(os.path.join(output_dir, file_name + '.yaml'), "w") as file_obj: | |
39 | + file_obj.write(data) | |
40 | + | |
41 | + | |
42 | +def load_initial_data_from(file_name): | |
43 | + with open(os.path.join(os.path.dirname(__file__), 'data/{}'.format(file_name))) as yaml_file: | |
44 | + return fromYAML(yaml_file) | |
30 | 45 | |
31 | 46 | |
32 | 47 | def set_tender_periods(tender): |
... | ... | @@ -44,19 +59,31 @@ def set_access_key(tender, access_token): |
44 | 59 | |
45 | 60 | def upload_tender_document(api, tender): |
46 | 61 | file = StringIO() |
47 | - file.name = 'test_file.txt' | |
48 | - file.write("test text data") | |
62 | + file.name = 'тест.txt' | |
63 | + file.write("test text dataaaфвфв") | |
49 | 64 | file.seek(0) |
50 | 65 | return api.upload_document(tender, file) |
51 | 66 | |
52 | 67 | |
53 | 68 | def patch_tender_document(api, tender, doc_id): |
54 | 69 | file = StringIO() |
55 | - file.name = 'test_file1.txt' | |
56 | - file.write("test text data 11111") | |
70 | + file.name = 'test1.txt' | |
71 | + file.write("контент") | |
57 | 72 | file.seek(0) |
58 | 73 | return api.update_document(tender, doc_id, file) |
59 | 74 | |
60 | 75 | |
61 | 76 | def create_approve_award_request_data(award_id): |
62 | 77 | return munchify({"data": {"status": "active", "id": award_id}}) |
78 | + | |
79 | + | |
80 | +def calculate_wait_to_date(date_stamp): | |
81 | + date = parse(date_stamp) | |
82 | + LOGGER.log_message(Message("date: {}".format(date.isoformat()), "INFO")) | |
83 | + now = datetime.now(tzlocal()) | |
84 | + LOGGER.log_message(Message("now: {}".format(now.isoformat()), "INFO")) | |
85 | + wait_seconds = (date - now).total_seconds() | |
86 | + wait_seconds += 2 | |
87 | + if wait_seconds < 0: | |
88 | + return 0 | |
89 | + return wait_seconds | ... | ... |
Please
register
or
login
to post a comment