Showing
8 changed files
with
383 additions
and
3 deletions
op_robot_tests/runner.py
0 → 100644
op_robot_tests/tests_files/ApiCommands.py
0 → 100644
1 | +# -*- coding: utf-8 - | ||
2 | + | ||
3 | +from munch import munchify, Munch | ||
4 | +from .initial_data import ( | ||
5 | + test_tender_data, test_question_data, test_question_answer_data, | ||
6 | + test_bid_data | ||
7 | +) | ||
8 | +from openprocurement_client.client import Client | ||
9 | +from datetime import datetime, timedelta | ||
10 | +from StringIO import StringIO | ||
11 | +from robot.output import LOGGER | ||
12 | +from robot.output.loggerhelper import Message | ||
13 | + | ||
14 | + | ||
15 | +def prepare_api(key=''): | ||
16 | + return Client(key) | ||
17 | + | ||
18 | + | ||
19 | +def prepare_test_tender_data(): | ||
20 | + tender = munchify({'data': test_tender_data}) | ||
21 | + return tender | ||
22 | + | ||
23 | + | ||
24 | +def log_object_data(data): | ||
25 | + if not isinstance(data, Munch): | ||
26 | + data = munchify(data) | ||
27 | + LOGGER.log_message( | ||
28 | + Message(data.toYAML(allow_unicode=True, default_flow_style=False), "INFO") | ||
29 | + ) | ||
30 | + | ||
31 | + | ||
32 | +def set_tender_periods(tender): | ||
33 | + now = datetime.now() | ||
34 | + tender.data.enquiryPeriod.endDate = (now + timedelta(minutes=2)).isoformat() | ||
35 | + tender.data.tenderPeriod.startDate = (now + timedelta(minutes=2)).isoformat() | ||
36 | + tender.data.tenderPeriod.endDate = (now + timedelta(minutes=4)).isoformat() | ||
37 | + return tender | ||
38 | + | ||
39 | + | ||
40 | +def set_access_key(tender, access_token): | ||
41 | + tender.access = munchify({"token": access_token}) | ||
42 | + return tender | ||
43 | + | ||
44 | + | ||
45 | +def upload_tender_document(api, tender): | ||
46 | + file = StringIO() | ||
47 | + file.name = 'test_file.txt' | ||
48 | + file.write("test text data") | ||
49 | + file.seek(0) | ||
50 | + return api.upload_document(tender, file) | ||
51 | + | ||
52 | + | ||
53 | +def patch_tender_document(api, tender, doc_id): | ||
54 | + file = StringIO() | ||
55 | + file.name = 'test_file1.txt' | ||
56 | + file.write("test text data 11111") | ||
57 | + file.seek(0) | ||
58 | + return api.update_document(tender, doc_id, file) | ||
59 | + | ||
60 | + | ||
61 | +def let_active_award(api, tender): | ||
62 | + awards = api.get_awards(tender) | ||
63 | + print "----_____ WE GOT AN AWARDS _____----" | ||
64 | + award_id = [i['id'] for i in awards.data if i['status'] == 'pending'][0] | ||
65 | + active_award = munchify({"data": {"status": "active", "id": award_id}}) | ||
66 | + award = api.patch_award(tender, active_award) |
1 | +*** Setting *** | ||
2 | +Resource keywords.robot | ||
3 | +Resource resource.robot | ||
4 | + | ||
5 | + | ||
6 | +*** Test Cases *** | ||
7 | +Tender process | ||
8 | + Create api wrapper | ||
9 | + Create tender | ||
10 | + Change tender title | ||
11 | + Upload tender documentation | ||
12 | + Change tender periods | ||
13 | + Create question | ||
14 | + Write answer on first question | ||
15 | + Wait to TenderPeriod | ||
16 | + Submit bids | ||
17 | + Review tender | ||
18 | + Wait to start of auction's worker | ||
19 | + Get particular urls for bids | ||
20 | + Review tender | ||
21 | + Wait to end of auction | ||
22 | + Review tender | ||
23 | + Activate award | ||
24 | + |
op_robot_tests/tests_files/__init__.py
0 → 100644
1 | +# |
op_robot_tests/tests_files/initial_data.py
0 → 100644
1 | +# -*- coding: utf-8 - | ||
2 | +from datetime import datetime, timedelta | ||
3 | +now = datetime.now() | ||
4 | +from munch import munchify | ||
5 | +from faker import Factory | ||
6 | +fake = Factory.create('uk_UA') | ||
7 | + | ||
8 | +test_tender_data = { | ||
9 | + "title": fake.catch_phrase(), | ||
10 | + "mode": "test", | ||
11 | + "submissionMethodDetails": "quick", | ||
12 | + "procuringEntity": { | ||
13 | + "name": fake.company(), | ||
14 | + "identifier": { | ||
15 | + "scheme": u"UA-EDR", | ||
16 | + "id": u"0000{}".format(fake.pyint()), | ||
17 | + "uri": fake.image_url(width=None, height=None) | ||
18 | + }, | ||
19 | + "address": { | ||
20 | + "countryName": u"Україна", | ||
21 | + "postalCode": fake.postalcode(), | ||
22 | + "region": u"м. Київ", | ||
23 | + "locality": u"м. Київ", | ||
24 | + "streetAddress": fake.street_address() | ||
25 | + }, | ||
26 | + "contactPoint": { | ||
27 | + "name": fake.name(), | ||
28 | + "telephone": fake.phone_number() | ||
29 | + } | ||
30 | + }, | ||
31 | + "value": { | ||
32 | + "amount": 500, | ||
33 | + "currency": u"UAH" | ||
34 | + }, | ||
35 | + "minimalStep": { | ||
36 | + "amount": 1, | ||
37 | + "currency": u"UAH" | ||
38 | + }, | ||
39 | + "items": [ | ||
40 | + { | ||
41 | + "description": fake.catch_phrase(), | ||
42 | + "classification": { | ||
43 | + "scheme": u"CPV", | ||
44 | + "id": u"44617100-9", | ||
45 | + "description": u"Cartons" | ||
46 | + }, | ||
47 | + "additionalClassifications": [ | ||
48 | + { | ||
49 | + "scheme": u"ДКПП", | ||
50 | + "id": u"17.21.1", | ||
51 | + "description": u"папір і картон гофровані, паперова й картонна тара" | ||
52 | + } | ||
53 | + ], | ||
54 | + "unit": { | ||
55 | + "name": u"item", | ||
56 | + "code": u"44617100-9" | ||
57 | + }, | ||
58 | + "quantity": fake.pyint() | ||
59 | + } | ||
60 | + ], | ||
61 | + "enquiryPeriod": { | ||
62 | + "endDate": (now + timedelta(days=1)).isoformat() | ||
63 | + }, | ||
64 | + "tenderPeriod": { | ||
65 | + "endDate": (now + timedelta(days=2)).isoformat() | ||
66 | + } | ||
67 | +} | ||
68 | + | ||
69 | + | ||
70 | +def test_question_data(): | ||
71 | + return { | ||
72 | + "data": { | ||
73 | + "author": { | ||
74 | + "address": { | ||
75 | + "countryName": "Україна", | ||
76 | + "locality": "м. Вінниця", | ||
77 | + "postalCode": "21100", | ||
78 | + "region": "м. Вінниця", | ||
79 | + "streetAddress": fake.street_address() | ||
80 | + }, | ||
81 | + "contactPoint": { | ||
82 | + "name": fake.name(), | ||
83 | + "telephone": fake.phone_number() | ||
84 | + }, | ||
85 | + "identifier": { | ||
86 | + "scheme": u"UA-EDR", | ||
87 | + "id": u"0000{}".format(fake.pyint()), | ||
88 | + "uri": fake.image_url(width=None, height=None) | ||
89 | + }, | ||
90 | + "name": fake.company() | ||
91 | + }, | ||
92 | + "description": fake.sentence(nb_words=10, variable_nb_words=True), | ||
93 | + "title": fake.sentence(nb_words=6, variable_nb_words=True) | ||
94 | + } | ||
95 | + } | ||
96 | + | ||
97 | + | ||
98 | +def test_question_answer_data(): | ||
99 | + return { | ||
100 | + "data": { | ||
101 | + "answer": fake.sentence(nb_words=40, variable_nb_words=True) | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | + | ||
106 | +def test_bid_data(): | ||
107 | + return munchify({ | ||
108 | + "data": { | ||
109 | + "tenderers": [ | ||
110 | + { | ||
111 | + "address": { | ||
112 | + "countryName": "Україна", | ||
113 | + "locality": "м. Вінниця", | ||
114 | + "postalCode": "21100", | ||
115 | + "region": "м. Вінниця", | ||
116 | + "streetAddress": fake.street_address() | ||
117 | + }, | ||
118 | + "contactPoint": { | ||
119 | + "name": fake.name(), | ||
120 | + "telephone": fake.phone_number() | ||
121 | + }, | ||
122 | + "identifier": { | ||
123 | + "scheme": u"UA-EDR", | ||
124 | + "id": u"0000{}".format(fake.pyint()), | ||
125 | + }, | ||
126 | + "name": fake.company() | ||
127 | + } | ||
128 | + ], | ||
129 | + "value": { | ||
130 | + "amount": 500 | ||
131 | + } | ||
132 | + } | ||
133 | + }) |
op_robot_tests/tests_files/keywords.robot
0 → 100644
1 | +*** Setting *** | ||
2 | +Library op_robot_tests.tests_files.ApiCommands | ||
3 | +Library String | ||
4 | +LIbrary Collections | ||
5 | + | ||
6 | + | ||
7 | +*** Keywords *** | ||
8 | +Create api wrapper | ||
9 | + ${API}= prepare_api ${api_key} | ||
10 | + Set Global Variable ${API} | ||
11 | + LOG ${API} | ||
12 | + Log Variables | ||
13 | + | ||
14 | +Set access key on tender | ||
15 | + ${tender}= set_access_key ${tender} ${access_token} | ||
16 | + Set Global Variable ${tender} | ||
17 | + | ||
18 | +Create tender | ||
19 | + ${init_tender_data}= prepare_test_tender_data | ||
20 | + Log object data ${init_tender_data} | ||
21 | + ${tender}= Call Method ${API} create_tender ${init_tender_data} | ||
22 | + Log object data ${tender} | ||
23 | + ${access_token}= Get Variable Value ${tender.access.token} | ||
24 | + Set Global Variable ${access_token} | ||
25 | + ${tender_id}= Get Variable Value ${tender.data.id} | ||
26 | + Set Global Variable ${tender_id} | ||
27 | + Log access_key: ${access_token} | ||
28 | + Log tender_id: ${tender_id} | ||
29 | + Log Variables | ||
30 | + Set Global Variable ${tender} | ||
31 | + [return] ${tender} | ||
32 | + | ||
33 | +Change tender title | ||
34 | + ${new_tender_sufix}= Generate Random String 3 [NUMBERS] | ||
35 | + ${new_tender_title}= Set Variable 1-QUINTA-KT-${new_tender_sufix} | ||
36 | + Log new title: ${new_tender_title} | ||
37 | + Log object data ${tender} | ||
38 | + ${tender.data.title}= Set Variable ${new_tender_title} | ||
39 | + ${tender.data.title_en}= Set Variable ${new_tender_title} | ||
40 | + ${tender.data.title_ru}= Set Variable ${new_tender_title} | ||
41 | + Log object data ${tender} | ||
42 | + ${tender}= Call Method ${API} patch_tender ${tender} | ||
43 | + Set Global Variable ${tender} | ||
44 | + Log object data ${tender} | ||
45 | + Set access key on tender | ||
46 | + | ||
47 | +Change tender periods | ||
48 | + Log object data ${tender} | ||
49 | + ${tender}= set_tender_periods ${tender} | ||
50 | + Log object data ${tender} | ||
51 | + ${tender}= Call Method ${API} patch_tender ${tender} | ||
52 | + Set Global Variable ${tender} | ||
53 | + Log object data ${tender} | ||
54 | + Set access key on tender | ||
55 | + | ||
56 | +Upload tender documentation | ||
57 | + ${file}= upload tender document ${API} ${tender} | ||
58 | + patch tender document ${API} ${tender} ${file.data.id} | ||
59 | + | ||
60 | +Create question | ||
61 | + ${question}= test question data | ||
62 | + Log object data ${question} | ||
63 | + ${question}= Call Method ${API} create_question ${tender} ${question} | ||
64 | + Log object data ${question} | ||
65 | + [return] ${question} | ||
66 | + | ||
67 | + | ||
68 | +Write answer on first question | ||
69 | + ${questions}= Call Method ${API} get_questions ${tender} | ||
70 | + Log object data ${questions} | ||
71 | + ${question}= Set Variable ${questions.data[0]} | ||
72 | + Log object data ${question} | ||
73 | + | ||
74 | + ${question}= Call Method ${API} get_question ${tender} ${questions.data[0].id} | ||
75 | + Log object data ${question} | ||
76 | + ${question}= set_access_key ${question} ${access_token} | ||
77 | + Log object data ${question} | ||
78 | + | ||
79 | + ${answer}= test_question_answer_data | ||
80 | + Log object data ${answer} | ||
81 | + ${question.data.answer}= Set Variable ${answer['data']['answer']} | ||
82 | + Log object data ${question} | ||
83 | + ${question}= Call Method ${API} patch_question ${tender} ${question} | ||
84 | + Log object data ${question} | ||
85 | + [return] ${question} | ||
86 | + | ||
87 | +Review tender | ||
88 | + ${tender}= Call Method ${API} get_tender ${tender_id} | ||
89 | + Set Global Variable ${tender} | ||
90 | + Log object data ${tender} | ||
91 | + Set access key on tender | ||
92 | + | ||
93 | +Wait to TenderPeriod | ||
94 | + Sleep 2 minutes 10 seconds Wait on TenderPeriod status | ||
95 | + | ||
96 | +Wait to start of auction's worker | ||
97 | + Sleep 4 minutes | ||
98 | + | ||
99 | +Submit bids | ||
100 | + ${bids} = Create Dictionary | ||
101 | + Log object data ${bids} | ||
102 | + :FOR ${index} IN RANGE 2 | ||
103 | + \ ${bid}= test bid data | ||
104 | + \ Log object data ${bid} | ||
105 | + \ ${temp_amount}= Evaluate ${bid['data']['value']['amount']} - ${index} | ||
106 | + \ Log ${temp_amount} | ||
107 | + \ ${bid.data.value.amount}= Get Variable Value ${temp_amount} | ||
108 | + \ ${bids_data}= Submit bid with data ${bid} | ||
109 | + \ Set To Dictionary ${bids} ${index} ${bids_data} | ||
110 | + Set Global Variable ${bids} | ||
111 | + Log object data ${bids} | ||
112 | + | ||
113 | + | ||
114 | + | ||
115 | +Submit bid with data | ||
116 | + [Arguments] ${bid} | ||
117 | + ${bid_data}= Call Method ${API} create_bid ${tender} ${bid} | ||
118 | + Log object data ${bid_data} | ||
119 | + [return] ${bid_data} | ||
120 | + | ||
121 | + | ||
122 | +Get particular urls for bids | ||
123 | + ${bids_items}= Get Dictionary Items ${bids} | ||
124 | + :FOR ${index} ${bid} IN @{bids_items} | ||
125 | + \ ${approved_bid}= Call Method ${API} get_bid ${tender} ${bid.data.id} ${bid.access.token} | ||
126 | + \ Log object data ${approved_bid} | ||
127 | + \ Log ${approved_bid.data.participationUrl} | ||
128 | + | ||
129 | + | ||
130 | +Wait to end of auction | ||
131 | + Sleep 45 minutes Wait to end of auction | ||
132 | + | ||
133 | + | ||
134 | +Activate award | ||
135 | + ${awards}= Call Method ${API} get_awards ${tender} | ||
136 | + Log object data ${awards} | ||
137 | + # :FOR ${award} IN @{awards.data} | ||
138 | + # \ | ||
139 | + # award_id = [i['id'] for i in awards.data if i['status'] == 'pending'][0] | ||
140 | + # active_award = munchify({"data": {"status": "active", "id": award_id}}) | ||
141 | + # award = api.patch_award(tender, active_award) | ||
142 | + # write_yaml('award_active.yaml', award) |
op_robot_tests/tests_files/resource.robot
0 → 100644
@@ -19,8 +19,11 @@ setup(name='op_robot_tests', | @@ -19,8 +19,11 @@ setup(name='op_robot_tests', | ||
19 | zip_safe=False, | 19 | zip_safe=False, |
20 | install_requires=[ | 20 | install_requires=[ |
21 | # -*- Extra requirements: -*- | 21 | # -*- Extra requirements: -*- |
22 | + 'robotframework' | ||
22 | ], | 23 | ], |
23 | - entry_points=""" | ||
24 | - # -*- Entry points: -*- | ||
25 | - """, | 24 | + entry_points={ |
25 | + 'console_scripts': [ | ||
26 | + 'openprocurement_tests = op_robot_tests.runner:runner', | ||
27 | + ], | ||
28 | + } | ||
26 | ) | 29 | ) |
Please
register
or
login
to post a comment