Ejemplo n.º 1
0
 def test_retrain_check(self):
     with session_scope(self.dal) as session:
         insert_data(session, self.data)
     with session_scope(self.dal) as session:
         result = retrain_check(session)
     expected = False
     self.assertEqual(result, expected)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 def test_get_validated_untrained_count(self):
     with session_scope(self.dal) as session:
         insert_data(session, self.data)
     with session_scope(self.dal) as session:
         result = get_validated_untrained_count(session)
     expected = 0
     self.assertEqual(result, expected)
Ejemplo n.º 4
0
 def test_fetch_notices_by_solnbr_bogus_solnbr(self):
     with session_scope(self.dal) as session:
         insert_data(session, self.data)
     with session_scope(self.dal) as session:
         notices = fetch_notices_by_solnbr('notexist', session)
     result = len(notices)
     expected = 0
     self.assertEqual(result, expected)
Ejemplo n.º 5
0
 def test_fetch_validated_attachments(self):
     with session_scope(self.dal) as session:
         insert_data(session, self.data)
     with session_scope(self.dal) as session:
         attachments = fetch_validated_attachments(session)
     result = len(attachments)
     # 993 since that's how many docs were initially labeled
     expected = 993
     self.assertEqual(result, expected)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
    def test_insert_bad_notice(self):

        call_count = 0
        with session_scope(self.dal) as session:
            # intentionally bad notice type
            data = mock_data_for_db.copy()
            data['notice type'] = "not to be found"
            self.assertNotEqual(mock_data_for_db['notice type'],
                                data['notice type'])

            logger = logging.getLogger("utils.db.db_utils")
            print(logger)

            with mock.patch.object(logger, 'warning', wraps=logger.warning):
                insert_data(session, [data])
                call_count = logger.warning.call_count
        self.assertEqual(
            1, call_count,
            "We should get one warning when adding a notice with a new notice type."
        )