def test_insert_data(self): with session_scope(self.dal) as session: insert_data(session, self.data) result = [] with session_scope(self.dal) as session: notices = session.query(Notice).all() for n in notices: notice = object_as_dict(n) #pop the date and createdAt attributes since they're constructed programmatically notice.pop('date') notice.pop('createdAt') #pop this as it'll vary notice.pop('notice_type_id') result.append(notice) expected = [{ 'id': 1, 'solicitation_number': 'test', 'agency': 'agency', 'notice_data': { 'url': 'url', 'naics': 'test', 'office': 'office', 'subject': 'test', 'classcod': 'test', 'setaside': 'test', 'emails': ['*****@*****.**'] }, 'compliant': 0, 'feedback': None, 'history': None, 'action': None, 'updatedAt': None, 'na_flag': False }] self.assertCountEqual(result, expected)
def test_insert_data_with_new_notice_type(self): opp = self.data[0].copy() nnt = "new notice type" opp['notice type'] = nnt with session_scope(self.dal) as session: insert_data(session, [opp]) result = [] with session_scope(self.dal) as session: notices = session.query(Notice).all() for n in notices: notice = object_as_dict(n) notice_type_id = int(notice['notice_type_id']) notice_type = fetch_notice_type_by_id(notice_type_id, session) self.assertCountEqual(notice_type.notice_type, nnt)
def test_insert_model(self): results = {'c': 'd'} params = {'a': 'b'} score = .99 with session_scope(self.dal) as session: insert_model(session, results=results, params=params, score=score) result = [] with session_scope(self.dal) as session: models = session.query(Model).all() for m in models: model = object_as_dict(m) model.pop('create_date') result.append(model) expected = [{ 'id': 1, 'results': results, 'params': params, 'score': score }] self.assertCountEqual(result, expected)
def test_insert_updated_nightly_file_day_two(self): ''' Simulate a second batch entry with a repeating solnbr that now has attachments ''' with session_scope(self.dal) as session: insert_updated_nightly_file(session, self.predicted_nightly_data) with session_scope(self.dal) as session: insert_updated_nightly_file(session, self.predicted_nightly_data_day_two) result = [] with session_scope(self.dal) as session: notices = session.query(Notice).all() for n in notices: notice = object_as_dict(n) #pop the date and createdAt attributes since they're constructed programmatically notice.pop('date') notice.pop('createdAt') if notice['history']: notice['history'][0]['date'] = "test date" result.append(notice) expected = [{ 'id': 1, 'notice_type_id': 6, 'solicitation_number': 'rfp-e-bpm-djf-18-0800-pr-0000828', 'agency': 'department of justice', 'notice_data': { 'url': 'url', 'zip': '20535', 'date': '0506', 'desc': ' link to document', 'year': '18', 'naics': '511210', 'ntype': 'combine', 'offadd': '935 pennsylvania avenue, n.w. washington dc 20535', 'office': 'federal bureau of investigation', 'popzip': '20535', 'contact': 'clark kent, contracting officer, phone 5555555555, email [email protected]', 'subject': 'enterprise business process management software tool', 'classcod': '70', 'location': 'procurement section', 'setaside': 'n/a', 'popaddress': '935 pennsylvania ave. n.w. washington, dc ', 'popcountry': 'us' }, 'compliant': 0, 'feedback': None, 'history': None, 'action': None, 'updatedAt': None }, { 'id': 2, 'notice_type_id': 5, 'solicitation_number': 'spe4a618t934n', 'agency': 'defense logistics agency', 'notice_data': { 'url': 'test_url', 'zip': '23297', 'date': '0506', 'desc': 'test123', 'year': '18', 'naics': '334511', 'offadd': '334511', 'office': 'dla acquisition locations', 'contact': '*****@*****.**', 'subject': 'subject', 'archdate': '06132018', 'classcod': '66', 'location': 'dla aviation - bsm', 'respdate': '051418', 'setaside': 'n/a ' }, 'compliant': 0, 'feedback': None, 'history': None, 'action': None, 'updatedAt': None }, { 'id': 3, 'notice_type_id': 6, 'solicitation_number': 'spe4a618t934n', 'agency': 'defense logistics agency', 'notice_data': { 'url': 'test_url', 'zip': '23297', 'date': '0506', 'desc': 'test123', 'year': '17', 'naics': '334511', 'offadd': '334511', 'office': 'dla acquisition locations', 'contact': '*****@*****.**', 'subject': 'subject', 'archdate': '06132018', 'classcod': '66', 'location': 'dla aviation - bsm', 'respdate': '051418', 'setaside': 'n/a ' }, 'compliant': 0, 'feedback': None, 'history': [{ "date": "test date", "user": "", "action": "Solicitation Updated on FBO.gov", "status": "" }], 'action': None, 'updatedAt': None }] self.assertEqual(result, expected)