Commit 9033b08738d1976306c4f32bef8357e315ab3486

Authored by Taras Kozlovskyi
1 parent ad8efa9b

Added load_initial_data_from and improved log_object_data keywords

1 # -*- coding: utf-8 - 1 # -*- coding: utf-8 -
2 -  
3 -from munch import munchify, Munch 2 +import os
  3 +from munch import munchify, Munch, fromYAML
4 from .initial_data import ( 4 from .initial_data import (
5 test_tender_data, test_question_data, test_question_answer_data, 5 test_tender_data, test_question_data, test_question_answer_data,
6 test_bid_data 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 from openprocurement_client.client import Client 14 from openprocurement_client.client import Client
9 from datetime import datetime, timedelta 15 from datetime import datetime, timedelta
10 from StringIO import StringIO 16 from StringIO import StringIO
11 from robot.output import LOGGER 17 from robot.output import LOGGER
12 from robot.output.loggerhelper import Message 18 from robot.output.loggerhelper import Message
  19 +from robot.libraries.BuiltIn import BuiltIn
13 20
14 21
15 def prepare_api(key=''): 22 def prepare_api(key=''):
@@ -21,12 +28,20 @@ def prepare_test_tender_data(): @@ -21,12 +28,20 @@ def prepare_test_tender_data():
21 return tender 28 return tender
22 29
23 30
24 -def log_object_data(data): 31 +def log_object_data(data, file_name=""):
25 if not isinstance(data, Munch): 32 if not isinstance(data, Munch):
26 data = munchify(data) 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 def set_tender_periods(tender): 47 def set_tender_periods(tender):
@@ -44,19 +59,31 @@ def set_access_key(tender, access_token): @@ -44,19 +59,31 @@ def set_access_key(tender, access_token):
44 59
45 def upload_tender_document(api, tender): 60 def upload_tender_document(api, tender):
46 file = StringIO() 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 file.seek(0) 64 file.seek(0)
50 return api.upload_document(tender, file) 65 return api.upload_document(tender, file)
51 66
52 67
53 def patch_tender_document(api, tender, doc_id): 68 def patch_tender_document(api, tender, doc_id):
54 file = StringIO() 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 file.seek(0) 72 file.seek(0)
58 return api.update_document(tender, doc_id, file) 73 return api.update_document(tender, doc_id, file)
59 74
60 75
61 def create_approve_award_request_data(award_id): 76 def create_approve_award_request_data(award_id):
62 return munchify({"data": {"status": "active", "id": award_id}}) 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
  1 +bidders:
  2 + bidder0:
  3 + start_bid: 50000
  4 + start_url: ''
  5 + browser: chrome
  6 + bidder1:
  7 + last_bid: ''
  8 + start_bid: 49000
  9 + start_url: ''
  10 + browser: chrome
  11 +observer:
  12 + browser: chrome
  13 + start_url: ''
Please register or login to post a comment