def create_auction(self, initial_data=initial_data): data = deepcopy(initial_data) data['_id'] = data['id'] = uuid4().hex data['status'] = 'active' data['doc_type'] = "Auction" data['dateModified'] = get_now().isoformat() data['auctionID'] = "UA-EA-X" if self.initial_bids: data['bids'] = deepcopy(self.initial_bids) data['bids'][0]['id'] = uuid4().hex if self.initial_award: award = deepcopy(self.initial_award) award['id'] = uuid4().hex award['bid_id'] = data['bids'][0]['id'] award['date'] = get_now().isoformat() data['awards'] = [award] if self.initial_award_document: document = deepcopy(self.initial_award_document) document['id'] = uuid4().hex document['dateModified'] = get_now().isoformat() data['awards'][0]['documents'] = [document] if self.initial_document: document = deepcopy(self.initial_document) document['id'] = uuid4().hex document['dateModified'] = get_now().isoformat() data['documents'] = [document] self.db.save(data) data = self.db[data['id']] del data['_id'] del data['_rev'] del data['doc_type'] return data
def create_tender(self, initial_data=initial_data): data = deepcopy(initial_data) data['_id'] = data['id'] = uuid4().hex data['status'] = 'active' data['doc_type'] = "Tender" data['dateModified'] = get_now().isoformat() data['tenderID'] = "UA-X" if self.initial_lots: lots = [] for i in self.initial_lots: lot = deepcopy(i) lot['id'] = uuid4().hex lots.append(lot) data['lots'] = self.initial_lots = lots for i, item in enumerate(data['items']): item['relatedLot'] = lots[i % len(lots)]['id'] if self.initial_bids: bids = [] for i in self.initial_bids: if self.initial_lots: i = i.copy() i['id'] = uuid4().hex value = i.pop('value') i['lotValues'] = [{ 'value': value, 'relatedLot': l['id'], } for l in self.initial_lots] bids.append(i) data['bids'] = bids if self.initial_award: award = deepcopy(self.initial_award) award['id'] = uuid4().hex award['bid_id'] = bids[0]['id'] award['date'] = get_now().isoformat() data['awards'] = [award] if self.initial_award_complaint: award_complaint = deepcopy(self.initial_award_complaint) award_complaint['id'] = uuid4().hex award_complaint['date'] = get_now().isoformat() data['awards'][0]['complaints'] = [award_complaint] if self.initial_award_complaint_document: award_complaint_document = deepcopy( self.initial_award_complaint_document) award_complaint_document['id'] = uuid4().hex award_complaint_document['dateModified'] = get_now( ).isoformat() data['awards'][0]['complaints'][0]['documents'] = [ award_complaint_document ] if self.initial_document: document = deepcopy(self.initial_document) document['id'] = uuid4().hex document['dateModified'] = get_now().isoformat() data['documents'] = [document] self.db.save(data) data = dict(self.db[data['id']]) del data['_id'] del data['_rev'] del data['doc_type'] return data
def create_plan(self, initial_data=initial_data): data = deepcopy(initial_data) data['_id'] = data['id'] = uuid4().hex data['status'] = 'active' data['doc_type'] = "Plan" data['dateModified'] = get_now().isoformat() data['planID'] = "UA-X" if self.initial_document: document = deepcopy(self.initial_document) document['id'] = uuid4().hex document['dateModified'] = get_now().isoformat() data['documents'] = [document] self.db.save(data) data = self.db[data['id']] del data['_id'] del data['_rev'] del data['doc_type'] return data
def test_listing(self): response = self.app.get('/tenders') self.assertEqual(response.status, '200 OK') self.assertEqual(len(response.json['data']), 0) tenders = [] for i in range(3): offset = get_now().isoformat() tenders.append(self.create_tender()) ids = ','.join([i['id'] for i in tenders]) while True: response = self.app.get('/tenders') self.assertTrue(ids.startswith(','.join([i['id'] for i in response.json['data']]))) if len(response.json['data']) == 3: break self.assertEqual(len(response.json['data']), 3) self.assertEqual(set(response.json['data'][0]), set([u'id', u'dateModified'])) self.assertEqual(set([i['id'] for i in response.json['data']]), set([i['id'] for i in tenders])) self.assertEqual(set([i['dateModified'] for i in response.json['data']]), set([i['dateModified'] for i in tenders])) self.assertEqual([i['dateModified'] for i in response.json['data']], sorted([i['dateModified'] for i in tenders])) while True: response = self.app.get('/tenders?offset={}'.format(offset)) self.assertEqual(response.status, '200 OK') if len(response.json['data']) == 1: break self.assertEqual(len(response.json['data']), 1) response = self.app.get('/tenders?limit=2') self.assertEqual(response.status, '200 OK') self.assertNotIn('prev_page', response.json) self.assertEqual(len(response.json['data']), 2) response = self.app.get(response.json['next_page']['path'].replace(ROUTE_PREFIX, '')) self.assertEqual(response.status, '200 OK') self.assertIn('descending=1', response.json['prev_page']['uri']) self.assertEqual(len(response.json['data']), 1) response = self.app.get(response.json['next_page']['path'].replace(ROUTE_PREFIX, '')) self.assertEqual(response.status, '200 OK') self.assertIn('descending=1', response.json['prev_page']['uri']) self.assertEqual(len(response.json['data']), 0) response = self.app.get('/tenders', params=[('opt_fields', 'status')]) self.assertEqual(response.status, '200 OK') self.assertEqual(len(response.json['data']), 3) self.assertEqual(set(response.json['data'][0]), set([u'id', u'dateModified', u'status'])) self.assertIn('opt_fields=status', response.json['next_page']['uri']) response = self.app.get('/tenders', params=[('opt_fields', 'status,enquiryPeriod')]) self.assertEqual(response.status, '200 OK') self.assertEqual(len(response.json['data']), 3) self.assertEqual(set(response.json['data'][0]), set([u'id', u'dateModified', u'status', u'enquiryPeriod'])) self.assertIn('opt_fields=status%2CenquiryPeriod', response.json['next_page']['uri']) response = self.app.get('/tenders?descending=1') self.assertEqual(response.status, '200 OK') self.assertEqual(response.content_type, 'application/json') self.assertEqual(len(response.json['data']), 3) self.assertEqual(set(response.json['data'][0]), set([u'id', u'dateModified'])) self.assertEqual(set([i['id'] for i in response.json['data']]), set([i['id'] for i in tenders])) self.assertEqual([i['dateModified'] for i in response.json['data']], sorted([i['dateModified'] for i in tenders], reverse=True)) response = self.app.get('/tenders?descending=1&limit=2') self.assertEqual(response.status, '200 OK') self.assertNotIn('descending=1', response.json['prev_page']['uri']) self.assertEqual(len(response.json['data']), 2) response = self.app.get(response.json['next_page']['path'].replace(ROUTE_PREFIX, '')) self.assertEqual(response.status, '200 OK') self.assertNotIn('descending=1', response.json['prev_page']['uri']) self.assertEqual(len(response.json['data']), 1) response = self.app.get(response.json['next_page']['path'].replace(ROUTE_PREFIX, '')) self.assertEqual(response.status, '200 OK') self.assertNotIn('descending=1', response.json['prev_page']['uri']) self.assertEqual(len(response.json['data']), 0) test_tender_data2 = test_tender_data.copy() test_tender_data2['mode'] = 'test' self.create_tender(test_tender_data2) while True: response = self.app.get('/tenders?mode=test') self.assertEqual(response.status, '200 OK') if len(response.json['data']) == 1: break self.assertEqual(len(response.json['data']), 1) response = self.app.get('/tenders?mode=_all_') self.assertEqual(response.status, '200 OK') self.assertEqual(len(response.json['data']), 4)
u"locality": u"м. Львів" } }], u"contractNumber": u"contract #13111", u"period": { u"startDate": u"2016-03-18T18:47:47.155143+02:00", u"endDate": u"2017-03-18T18:47:47.155143+02:00" }, u"value": { u"currency": u"UAH", u"amount": 238.0, u"valueAddedTaxIncluded": True }, u"dateSigned": get_now().isoformat(), u"awardID": u"8481d7eb01694c25b18658036c236c5d", u"id": uuid4().hex, u"contractID": u"UA-2016-03-18-000001-1", u"tender_id": uuid4().hex, u"tender_token": uuid4().hex, u"owner": u"broker" } test_plan_data = {
u"region": u"м. Львів", u"locality": u"м. Львів" } } ], u"contractNumber": u"contract #13111", u"period": { u"startDate": u"2016-03-18T18:47:47.155143+02:00", u"endDate": u"2017-03-18T18:47:47.155143+02:00" }, u"value": { u"currency": u"UAH", u"amount": 238.0, u"valueAddedTaxIncluded": True }, u"dateSigned": get_now().isoformat(), u"awardID": u"8481d7eb01694c25b18658036c236c5d", u"id": uuid4().hex, u"contractID": u"UA-2016-03-18-000001-1", u"tender_id": uuid4().hex, u"tender_token": uuid4().hex, u"owner": u"broker" } test_plan_data = { "tender": { "procurementMethod": u"open", "procurementMethodType": u"belowThreshold", "tenderPeriod": { "startDate": (now + timedelta(days=7)).isoformat() }