def test_patch_contract(self): setup_routing(self.app, routes=["contract_patch"]) self.contract.data.description = 'test_patch_contract' patched_contract = self.client.patch_contract(self.contract) self.assertEqual(patched_contract.data.id, self.contract.data.id) self.assertEqual(patched_contract.data.description, self.contract.data.description)
def test_patch_credentials(self): setup_routing(self.app, routs=['tender_patch_credentials']) patched_credentials = self.client.patch_credentials( self.tender.data.id, self.tender.access['token']) self.assertEqual(patched_credentials.data.id, self.tender.data.id) self.assertNotEqual(patched_credentials.access.token, self.tender.access['token'])
def test_upload_tender_document_path_failed(self, mock_request): mock_request.return_value = munchify({'status_code': 204}) setup_routing(self.app, routes=["tender_document_create"]) file_name = "test_document.txt" file_path = ROOT + file_name with self.assertRaises(InvalidResponse): self.client.upload_document(file_path, self.tender)
def test_patch_tender(self): setup_routing(self.app, routs=["tender_patch"]) self.tender.data.description = 'test_patch_tender' patched_tender = self.client.patch_tender(self.tender) self.assertEqual(patched_tender.data.id, self.tender.data.id) self.assertEqual(patched_tender.data.description, self.tender.data.description)
def test_upload_tender_document_path(self): setup_routing(self.app, routs=["tender_document_create"]) file_name = "test_document.txt" file_path = ROOT + file_name doc = self.client.upload_document(file_path, self.tender) self.assertEqual(doc.data.title, file_name) self.assertEqual(doc.data.id, TEST_KEYS.new_document_id)
def test_upload_tender_document_path(self): setup_routing(self.app, routs=["tender_document_create"]) file_name = "test_document.txt" file_path = ROOT + file_name doc = self.client.upload_document(file_path, self.tender) self.assertEqual(doc.data.title, file_name) self.assertEqual(doc.data.id, TEST_KEYS.new_document_id)
def test_upload_contract_document(self): setup_routing(self.app, routes=['contract_document_create']) file_ = generate_file_obj('test_document.txt', 'test upload contract document text data') doc = self.client.upload_document(file_, self.contract) self.assertEqual(doc.data.title, file_.name) self.assertEqual(doc.data.id, TEST_CONTRACT_KEYS.new_document_id)
def test_patch_plan(self): setup_routing(self.app, routes=['plan_patch']) self.plan.data.description = 'test_patch_plan' patched_tender = self.client.patch_plan(self.plan) self.assertEqual(patched_tender.data.id, self.plan.data.id) self.assertEqual(patched_tender.data.description, self.plan.data.description)
def test_get_awards_documents(self): setup_routing(self.app, routs=["tender_award_documents"]) documents = munchify( {'data': self.tender['data']['awards'][0].get('documents', [])}) self.assertEqual( self.client.get_awards_documents( self.tender, self.tender['data']['awards'][0]['id']), documents)
def test_get_location_error(self): setup_routing(self.app, routs=["tender_subpage_item"]) self.assertEqual(self.client.get_question(self.empty_tender, question_id=TEST_KEYS.question_id), munchify(loads(location_error('questions')))) self.assertEqual(self.client.get_lot(self.empty_tender, lot_id=TEST_KEYS.lot_id), munchify(loads(location_error('lots')))) self.assertEqual(self.client.get_bid(self.empty_tender, bid_id=TEST_KEYS.bid_id, access_token=API_KEY), munchify(loads(location_error('bids'))))
def test_get_location_error(self): setup_routing(self.app, routs=["tender_subpage_item"]) self.assertEqual(self.client.get_question(self.empty_tender, question_id=TEST_KEYS.question_id), munchify(loads(location_error('questions')))) self.assertEqual(self.client.get_lot(self.empty_tender, lot_id=TEST_KEYS.lot_id), munchify(loads(location_error('lots')))) self.assertEqual(self.client.get_bid(self.empty_tender, bid_id=TEST_KEYS.bid_id, access_token=API_KEY), munchify(loads(location_error('bids'))))
def test_patch_bid_document(self): setup_routing(self.app, routs=["tender_subpage_document_patch"]) document = munchify({"data": {"id": TEST_KEYS.document_id, "title": "test_patch_document.txt"}}) patched_document = self.client.patch_bid_document( self.tender, document, TEST_KEYS.bid_id, TEST_KEYS.bid_document_id ) self.assertEqual(patched_document.data.id, document.data.id) self.assertEqual(patched_document.data.title, document.data.title)
def test_patch_qualification(self): setup_routing(self.app, routs=["tender_subpage_item_patch"]) qualification = munchify( {"data": {"id": TEST_KEYS.qualification_id, "description": "test_patch_qualification"}} ) patched_qualification = self.client.patch_qualification(self.tender, qualification) self.assertEqual(patched_qualification.data.id, qualification.data.id) self.assertEqual(patched_qualification.data.description, qualification.data.description)
def test_patch_cancellation(self): setup_routing(self.app, routs=["tender_subpage_item_patch"]) cancellation = munchify( {"data": {"id": TEST_KEYS_LIMITED.cancellation_id, "description": "test_patch_cancellation"}} ) patched_cancellation = self.client.patch_cancellation(self.limited_tender, cancellation) self.assertEqual(patched_cancellation.data.id, cancellation.data.id) self.assertEqual(patched_cancellation.data.description, cancellation.data.description)
def test_get_bid(self): setup_routing(self.app, routs=["tender_subpage_item"]) bids = tender_partition(TEST_KEYS.tender_id, part="bids") for bid in bids: if bid['id'] == TEST_KEYS.bid_id: bid_ = munchify({"data": bid}) break bid = self.client.get_bid(self.tender, bid_id=TEST_KEYS.bid_id, access_token=API_KEY) self.assertEqual(bid , bid_)
def test_delete_location_error(self): setup_routing(self.app, routs=["tender_subpage_item_delete"]) self.assertEqual( self.client.delete_bid(self.empty_tender, TEST_KEYS.error_id, API_KEY), munchify(loads(location_error("bids"))), ) self.assertEqual( self.client.delete_lot(self.empty_tender, TEST_KEYS.error_id), munchify(loads(location_error("lots"))) )
def test_get_question(self): setup_routing(self.app, routs=["tender_subpage_item"]) questions = tender_partition(TEST_KEYS.tender_id, part="questions") for question in questions: if question['id'] == TEST_KEYS.question_id: question_ = munchify({"data": question}) break question = self.client.get_question(self.tender, question_id=TEST_KEYS.question_id) self.assertEqual(question, question_)
def test_get_question(self): setup_routing(self.app, routs=["tender_subpage_item"]) questions = tender_partition(TEST_KEYS.tender_id, part="questions") for question in questions: if question['id'] == TEST_KEYS.question_id: question_ = munchify({"data": question}) break question = self.client.get_question(self.tender, question_id=TEST_KEYS.question_id) self.assertEqual(question, question_)
def test_delete_location_error(self): setup_routing(self.app, routs=["tender_subpage_item_delete"]) self.assertEqual( self.client.delete_bid(self.empty_tender, TEST_KEYS.error_id, API_KEY), munchify(loads(location_error('bids')))) self.assertEqual( self.client.delete_lot(self.empty_tender, TEST_KEYS.error_id), munchify(loads(location_error('lots'))))
def test_get_file(self): setup_routing(self.app, routs=["redirect", "download"]) file_name = 'test_document.txt' with open(ROOT + file_name) as local_file: test_file_data = local_file.read() url = HOST_URL + '/redirect/' + file_name doc = self.client.get_file(self.tender, url, API_KEY) self.assertEqual(test_file_data, doc[0]) self.assertEqual(file_name, doc[1])
def test_upload_tender_document(self): setup_routing(self.app, routes=["tender_document_create"]) file_ = StringIO() file_.name = 'test_document.txt' file_.write("test upload tender document text data") file_.seek(0) doc = self.client.upload_document(file_, self.tender) self.assertEqual(doc.data.title, file_.name) self.assertEqual(doc.data.id, TEST_TENDER_KEYS.new_document_id)
def test_get_file(self): setup_routing(self.app, routs=["redirect","download"]) file_name = 'test_document.txt' with open(ROOT + file_name) as local_file: test_file_data = local_file.read() url = HOST_URL + '/redirect/' + file_name doc = self.client.get_file(self.tender, url, API_KEY) self.assertEqual(test_file_data, doc[0]) self.assertEqual(file_name, doc[1])
def test_retrieve_contract_credentials(self): setup_routing(self.app, routes=['contract_patch_credentials']) patched_credentials = self.client.patch_credentials( self.contract.data.id, self.contract.access['token']) self.assertEqual(patched_credentials.data.id, self.contract.data.id) self.assertNotEqual(patched_credentials.access.token, self.contract.access['token']) self.assertEqual(patched_credentials.access.token, TEST_CONTRACT_KEYS['new_token'])
def test_get_lot(self): setup_routing(self.app, routs=["tender_subpage_item"]) lots = tender_partition(TEST_KEYS.tender_id, part="lots") for lot in lots: if lot['id'] == TEST_KEYS.lot_id: lot_ = munchify({"data": lot}) break lot = self.client.get_lot(self.tender, lot_id=TEST_KEYS.lot_id) self.assertEqual(lot, lot_)
def test_get_bid(self): setup_routing(self.app, routs=["tender_subpage_item"]) bids = tender_partition(TEST_KEYS.tender_id, part="bids") for bid in bids: if bid['id'] == TEST_KEYS.bid_id: bid_ = munchify({"data": bid}) break bid = self.client.get_bid(self.tender, bid_id=TEST_KEYS.bid_id, access_token=API_KEY) self.assertEqual(bid , bid_)
def test_get_lot(self): setup_routing(self.app, routs=["tender_subpage_item"]) lots = tender_partition(TEST_KEYS.tender_id, part="lots") for lot in lots: if lot['id'] == TEST_KEYS.lot_id: lot_ = munchify({"data": lot}) break lot = self.client.get_lot(self.tender, lot_id=TEST_KEYS.lot_id) self.assertEqual(lot, lot_)
def test_upload_contract_document(self): setup_routing(self.app, routs=["contract_document_create"]) file_ = StringIO() file_.name = 'test_document.txt' file_.write("test upload contract document text data") file_.seek(0) doc = self.client.upload_document(file_, self.contract) self.assertEqual(doc.data.title, file_.name) self.assertEqual(doc.data.id, TEST_CONTRACT_KEYS.new_document_id) file_.close()
def test_upload_award_document(self): setup_routing(self.app, routs=["tender_subpage_document_create"]) file_ = StringIO() file_.name = 'test_award_document.txt' file_.write("test upload award document text data") file_.seek(0) doc = self.client.upload_award_document(file_, self.tender, TEST_KEYS.award_id) self.assertEqual(doc.data.title, file_.name) self.assertEqual(doc.data.id, TEST_KEYS.new_document_id) file_.close()
def test_update_cancellation_document(self): setup_routing(self.app, routs=["tender_subpage_document_update"]) file_ = StringIO() file_.name = 'test_document.txt' file_.write("test upload tender document text data") file_.seek(0) doc = self.client.update_cancellation_document(file_, self.limited_tender, TEST_KEYS_LIMITED.cancellation_id, TEST_KEYS_LIMITED.cancellation_document_id) self.assertEqual(doc.data.title, file_.name) self.assertEqual(doc.data.id, TEST_KEYS_LIMITED.cancellation_document_id) file_.close()
def test_upload_contract_document(self): setup_routing(self.app, routs=["contract_document_create"]) file_ = StringIO() file_.name = 'test_document.txt' file_.write("test upload contract document text data") file_.seek(0) doc = self.client.upload_document(file_, self.contract) self.assertEqual(doc.data.title, file_.name) self.assertEqual(doc.data.id, TEST_CONTRACT_KEYS.new_document_id) file_.close()
def test_get_qualification_documents(self): setup_routing(self.app, routes=["tender_qualification_documents"]) documents = munchify({ 'data': self.tender['data']['qualifications'][0].get('documents', []) }) self.assertEqual( self.client.get_qualification_documents( self.tender, self.tender['data']['qualifications'][0]['id']), documents)
def test_update_cancellation_document(self): setup_routing(self.app, routs=["tender_subpage_document_update"]) file_ = StringIO() file_.name = 'test_document.txt' file_.write("test upload tender document text data") file_.seek(0) doc = self.client.update_cancellation_document(file_, self.limited_tender, TEST_KEYS_LIMITED.cancellation_id, TEST_KEYS_LIMITED.cancellation_document_id) self.assertEqual(doc.data.title, file_.name) self.assertEqual(doc.data.id, TEST_KEYS_LIMITED.cancellation_document_id) file_.close()
def test_upload_award_document(self): setup_routing(self.app, routs=["tender_subpage_document_create"]) file_ = StringIO() file_.name = 'test_award_document.txt' file_.write("test upload award document text data") file_.seek(0) doc = self.client.upload_award_document(file_, self.tender, TEST_KEYS.award_id) self.assertEqual(doc.data.title, file_.name) self.assertEqual(doc.data.id, TEST_KEYS.new_document_id) file_.close()
def test_upload_bid_qualification_document(self): setup_routing(self.app, routs=["tender_subpage_document_create"]) document_type = "qualificationDocuments" file_ = StringIO() file_.name = 'test_document.txt' file_.write("test upload tender document text data") file_.seek(0) doc = self.client.upload_bid_document(file_, self.tender, TEST_KEYS.bid_id, document_type) self.assertEqual(doc.data.title, file_.name) self.assertEqual(doc.data.id, TEST_KEYS.new_document_id) file_.close()
def test_patch_document(self): setup_routing(self.app, routes=['contract_subpage_item_patch']) document = munchify({ 'data': { 'id': TEST_CONTRACT_KEYS.document_id, 'title': 'test_patch_document.txt' } }) patched_document = self.client.patch_document(self.contract, document) self.assertEqual(patched_document.data.id, document.data.id) self.assertEqual(patched_document.data.title, document.data.title)
def test_update_bid_eligibility_document(self): setup_routing(self.app, routs=["tender_subpage_document_update"]) file_ = StringIO() file_.name = 'test_document.txt' file_.write("test upload tender eligibility_document text data") file_.seek(0) document_type = "eligibility_documents" doc = self.client.update_bid_document(file_, self.tender, TEST_KEYS.bid_id, TEST_KEYS.bid_eligibility_document_id, document_type) self.assertEqual(doc.data.title, file_.name) self.assertEqual(doc.data.id, TEST_KEYS.bid_eligibility_document_id) file_.close()
def test_patch_bid(self): setup_routing(self.app, routs=["tender_subpage_item_patch"]) bid = munchify({ "data": { "id": TEST_KEYS.bid_id, "description": "test_patch_bid" } }) patched_bid = self.client.patch_bid(self.tender, bid) self.assertEqual(patched_bid.data.id, bid.data.id) self.assertEqual(patched_bid.data.description, bid.data.description)
def test_patch_lot(self): setup_routing(self.app, routs=["tender_subpage_item_patch"]) lot = munchify({ "data": { "id": TEST_KEYS.lot_id, "description": "test_patch_lot" } }) patched_lot = self.client.patch_lot(self.tender, lot) self.assertEqual(patched_lot.data.id, lot.data.id) self.assertEqual(patched_lot.data.description, lot.data.description)
def test_patch_document(self): setup_routing(self.app, routs=["tender_subpage_item_patch"]) document = munchify({ "data": { "id": TEST_KEYS.document_id, "title": "test_patch_document.txt" } }) patched_document = self.client.patch_document(self.tender, document) self.assertEqual(patched_document.data.id, document.data.id) self.assertEqual(patched_document.data.title, document.data.title)
def test_upload_bid_qualification_document(self): setup_routing(self.app, routs=["tender_subpage_document_create"]) document_type = "qualificationDocuments" file_ = StringIO() file_.name = 'test_document.txt' file_.write("test upload tender document text data") file_.seek(0) doc = self.client.upload_bid_document(file_, self.tender, TEST_KEYS.bid_id, document_type) self.assertEqual(doc.data.title, file_.name) self.assertEqual(doc.data.id, TEST_KEYS.new_document_id) file_.close()
def test_update_bid_eligibility_document(self): setup_routing(self.app, routs=["tender_subpage_document_update"]) file_ = StringIO() file_.name = 'test_document.txt' file_.write("test upload tender eligibility_document text data") file_.seek(0) document_type = "eligibility_documents" doc = self.client.update_bid_document(file_, self.tender, TEST_KEYS.bid_id, TEST_KEYS.bid_eligibility_document_id, document_type) self.assertEqual(doc.data.title, file_.name) self.assertEqual(doc.data.id, TEST_KEYS.bid_eligibility_document_id) file_.close()
def setUp(self): self.app = Bottle() setup_routing(self.app) self.server = WSGIServer(('localhost', 20602), self.app, log=None) self.server.start() self.client = plan_client.PlansClient('', host_url=HOST_URL, api_version=API_VERSION) with open(ROOT + 'plans.json') as plans: self.plans = munchify(load(plans)) with open(ROOT + 'plan_' + TEST_PLAN_KEYS.plan_id + '.json') as plan: self.plan = munchify(load(plan))
def test_patch_contract(self): setup_routing(self.app, routs=["tender_subpage_item_patch"]) contract = munchify({ "data": { "id": TEST_KEYS_LIMITED.contract_id, "title": "test_patch_contract.txt" } }) patched_contract = self.client.patch_contract(self.limited_tender, contract) self.assertEqual(patched_contract.data.id, contract.data.id) self.assertEqual(patched_contract.data.title, contract.data.title)
def test_patch_award(self): setup_routing(self.app, routes=["tender_subpage_item_patch"]) award = munchify({ "data": { "id": TEST_TENDER_KEYS.award_id, "description": "test_patch_award" } }) patched_award = self.client.patch_award(self.tender, award) self.assertEqual(patched_award.data.id, award.data.id) self.assertEqual(patched_award.data.description, award.data.description)
def test_patch_question(self): setup_routing(self.app, routs=["tender_subpage_item_patch"]) question = munchify({ "data": { "id": TEST_KEYS.question_id, "description": "test_patch_question" } }) patched_question = self.client.patch_question(self.tender, question) self.assertEqual(patched_question.data.id, question.data.id) self.assertEqual(patched_question.data.description, question.data.description)
def setUp(self): self.app = Bottle() setup_routing(self.app) self.server = WSGIServer(('localhost', 20602), self.app, log=None) self.server.start() self.client = plan_client.PlansClient('', host_url=HOST_URL, api_version=API_VERSION) with open(ROOT + 'plans.json') as plans: self.plans = munchify(load(plans)) with open(ROOT + 'plan_' + TEST_PLAN_KEYS.plan_id + '.json') as plan: self.plan = munchify(load(plan))
def setUp(self): # self._testMethodName self.app = Bottle() setup_routing(self.app) self.server = WSGIServer(("localhost", 20602), self.app, log=None) self.server.start() self.client = ContractingClient(API_KEY, host_url=HOST_URL, api_version=API_VERSION) with open(ROOT + "contract_" + TEST_CONTRACT_KEYS.contract_id + ".json") as contract: self.contract = munchify(load(contract)) self.contract.update({"access": {"token": API_KEY}})
def test_patch_location_error(self): setup_routing(self.app, routs=["tender_subpage_item_patch"]) error = munchify({"data": {"id": TEST_KEYS.error_id}, "access": {"token": API_KEY}}) self.assertEqual(self.client.patch_question(self.empty_tender, error), munchify(loads(location_error('questions')))) self.assertEqual(self.client.patch_bid(self.empty_tender, error), munchify(loads(location_error('bids')))) self.assertEqual(self.client.patch_award(self.empty_tender, error), munchify(loads(location_error('awards')))) self.assertEqual(self.client.patch_lot(self.empty_tender, error), munchify(loads(location_error('lots')))) self.assertEqual(self.client.patch_document(self.empty_tender, error), munchify(loads(location_error('documents'))))
def setUp(self): #self._testMethodName self.app = Bottle() setup_routing(self.app) self.server = WSGIServer(('localhost', 20602), self.app, log=None) self.server.start() self.client = tender_client.TendersClient('', host_url=HOST_URL, api_version=API_VERSION) with open(ROOT + 'tenders.json') as tenders: self.tenders = munchify(load(tenders)) with open(ROOT + TEST_KEYS.tender_id + '.json') as tender: self.tender = munchify(load(tender))
def setUp(self): #self._testMethodName self.app = Bottle() setup_routing(self.app) self.server = WSGIServer(('localhost', 20602), self.app, log=None) self.server.start() self.client = client.Client(API_KEY, host_url=HOST_URL, api_version=API_VERSION) with open(ROOT + TEST_KEYS.tender_id + '.json') as tender: self.tender = munchify(load(tender)) self.tender.update({'access':{"token": API_KEY}}) with open(ROOT + TEST_KEYS.empty_tender + '.json') as tender: self.empty_tender = munchify(load(tender)) self.empty_tender.update({'access':{"token": API_KEY}})
def setUp(self): # self._testMethodName self.app = Bottle() setup_routing(self.app) self.server = WSGIServer(("localhost", 20602), self.app, log=None) self.server.start() self.client = tender_client.TendersClient(API_KEY, host_url=HOST_URL, api_version=API_VERSION) with open(ROOT + TEST_KEYS.tender_id + ".json") as tender: self.tender = munchify(load(tender)) self.tender.update({"access": {"token": API_KEY}}) with open(ROOT + TEST_KEYS.empty_tender + ".json") as tender: self.empty_tender = munchify(load(tender)) self.empty_tender.update({"access": {"token": API_KEY}}) with open(ROOT + TEST_KEYS_LIMITED.tender_id + ".json") as tender: self.limited_tender = munchify(load(tender)) self.limited_tender.update({"access": {"token": API_KEY}})
def test_patch_contract(self): setup_routing(self.app, routs=["tender_subpage_item_patch"]) contract = munchify({"data": {"id": TEST_KEYS_LIMITED.contract_id, "title": "test_patch_contract.txt"}}) patched_contract = self.client.patch_contract(self.limited_tender, contract) self.assertEqual(patched_contract.data.id, contract.data.id) self.assertEqual(patched_contract.data.title, contract.data.title)
def test_get_file_dont_exist_error(self): setup_routing(self.app, routs=["redirect","download"]) file_name = 'error.txt' url = HOST_URL + '/redirect/' + file_name self.assertRaises(tender_client.InvalidResponse, self.client.get_file, self.tender, url, API_KEY)
def test_get_file_no_token_error(self): setup_routing(self.app, routs=["redirect","download"]) file_name = 'test_document.txt' url = HOST_URL + '/redirect/' + file_name self.assertRaises(tender_client.NoToken, self.client.get_file, self.tender, url, '')
def test_upload_document_type_error(self): setup_routing(self.app, routs=["tender_document_create"]) self.assertRaises(TypeError,self.client.upload_document, (object, self.tender))
def test_offset_error(self): setup_routing(self.app, routs=['offset_error']) tenders = self.client.get_tenders() self.assertIsInstance(tenders, Iterable) self.assertEqual(tenders, self.tenders.data)
def test_get_tender_location_error(self): setup_routing(self.app, routs=["tender"]) tender = self.client.get_tender(TEST_KEYS.error_id) self.assertEqual(tender, munchify(loads(location_error('tender'))))
def test_get_tender(self): setup_routing(self.app, routs=["tender"]) tender = self.client.get_tender(TEST_KEYS.tender_id) self.assertEqual(tender, self.tender)
def test_delete_lot(self): setup_routing(self.app, routs=["tender_subpage_item_delete"]) lot_id = tender_partition(TEST_KEYS.tender_id, part="lots")[0]['id'] deleted_lot = self.client.delete_lot(self.tender, lot_id) self.assertFalse(deleted_lot)
def test_delete_bid(self): setup_routing(self.app, routs=["tender_subpage_item_delete"]) bid_id = tender_partition(TEST_KEYS.tender_id, part="bids")[0]['id'] deleted_bid = self.client.delete_bid(self.tender, bid_id, API_KEY) self.assertFalse(deleted_bid)