示例#1
0
 def test_agent_repr(self):
     testAgent = Agent('session')
     testAgent.name = 'Tester, Test'
     testAgent.viaf = 1
     self.assertEqual(
         str(testAgent),
         '<Agent(name=Tester, Test, sort_name=None, lcnaf=None, viaf=1)>')
示例#2
0
 def test_jw_query_single_error(self):
     mock_session = MagicMock()
     mock_session.query().filter().one.side_effect = NoResultFound
     testAgent = Agent(mock_session)
     testAgent.name = 'Tester, Test'
     noMatches = testAgent.findJaroWinklerQuery()
     self.assertEqual(noMatches, None)
示例#3
0
 def test_jw_query_success(self):
     mock_session = MagicMock()
     mock_session.query().filter().one.return_value = 'mockAgent'
     testAgent = Agent(mock_session)
     testAgent.name = 'O\'Tester, Test'
     matchAgent = testAgent.findJaroWinklerQuery()
     self.assertEqual(matchAgent, 'mockAgent')
示例#4
0
 def test_viaf_query_miss(self, mock_req):
     mock_resp = MagicMock()
     mock_resp.json.return_value = {'message': 'Missing'}
     mock_req.get.return_value = mock_resp
     testAgent = Agent()
     testAgent.name = 'Old'
     outAgent = testAgent.findViafQuery()
     self.assertEqual(outAgent, None)
示例#5
0
 def test_authority_query_success(self):
     mock_session = MagicMock()
     mock_session.query().filter().one_or_none.return_value = 'mockAgent'
     testAgent = Agent(mock_session)
     testAgent.viaf = 999999999
     testAgent.lcnaf = 999999999
     foundAgent = testAgent.authorityQuery()
     self.assertEqual(foundAgent, 'mockAgent')
示例#6
0
 def test_authority_query_single_error(self):
     mock_session = MagicMock()
     mock_session.query().filter().one_or_none.return_value = None
     testAgent = Agent(mock_session)
     testAgent.viaf = 999999999
     testAgent.lcnaf = 999999999
     noAgent = testAgent.authorityQuery()
     self.assertEqual(noAgent, None)
示例#7
0
 def test_trgm_query_multiple_response(self):
     mock_session = MagicMock()
     mock_resp = MagicMock()
     mock_resp.rowcount = 2
     mock_session.execute.return_value = mock_resp
     testAgent = Agent(mock_session)
     testAgent.name = 'Tester, Test'
     manyMatches = testAgent.findTrgmQuery()
     self.assertEqual(manyMatches, None)
示例#8
0
 def test_authority_query_multiple_error(self):
     mock_session = MagicMock()
     mock_session.query()\
         .filter().one_or_none.side_effect = MultipleResultsFound
     mock_session.query().filter().first.return_value = 'firstMatch'
     testAgent = Agent(mock_session)
     testAgent.viaf = 999999999
     testAgent.lcnaf = 999999999
     firstAgent = testAgent.authorityQuery()
     self.assertEqual(firstAgent, 'firstMatch')
示例#9
0
 def test_trgm_query_no_matches(self):
     mock_session = MagicMock()
     mock_response = MagicMock()
     mock_response.rowcount = 0
     mock_response.first.return_value = None
     mock_session.execute.return_value = mock_response
     testAgent = Agent(mock_session)
     testAgent.name = 'Tester, Test'
     noMatches = testAgent.findTrgmQuery()
     self.assertEqual(noMatches, None)
示例#10
0
 def test_trgm_query_success(self):
     mock_session = MagicMock()
     mock_resp = MagicMock()
     mock_resp.rowcount = 1
     mock_resp.first.return_value = 'mockAgent'
     mock_session.execute.return_value = mock_resp
     testAgent = Agent(mock_session)
     testAgent.name = 'O\'Tester, Test'
     matchAgent = testAgent.findTrgmQuery()
     self.assertEqual(matchAgent, 'mockAgent')
示例#11
0
 def test_viaf_query_success(self, mock_clean, mock_auth, mock_req):
     mock_resp = MagicMock()
     mock_resp.json.return_value = {
         'name': 'Test',
         'viaf': 000,
         'lcnaf': 000
     }
     mock_req.get.return_value = mock_resp
     testAgent = Agent()
     testAgent.name = 'Old'
     outAgent = testAgent.findViafQuery()
     self.assertEqual(outAgent, 'matchedAgent')
示例#12
0
 def test_agent_insert_sort_none(self):
     testAgent = Agent()
     testData = {'name': 'New, Name', 'sort_name': None}
     testAgent.createTmpRelations(testData)
     testAgent.insertData(testData)
     testAgent.removeTmpRelations()
     self.assertEqual(testAgent.name, 'New, Name')
     self.assertEqual(testAgent.sort_name, 'new, name')
示例#13
0
 def test_new_agent_creation(self):
     mockSession = MagicMock()
     newAgent, roles = Agent.createAgent(mockSession, {
         'name': 'Murry, Kathleen Beauchamp',
         'roles': ['author']
     })
     self.assertEqual(newAgent.name, 'Murry, Kathleen Beauchamp')
     self.assertEqual(roles[0], 'author')
示例#14
0
 def test_updateInsert_insert(self):
     with patch('sfrCore.model.Agent.createAgent') as mock_create:
         mock_agent = MagicMock()
         mock_agent.lookup.return_value = None
         mock_create.return_value = (mock_agent, ['test'])
         testAgent, roles = Agent.updateOrInsert('session', 'fakeAgent')
         self.assertEqual(testAgent, mock_agent)
         self.assertEqual(roles, ['test'])
示例#15
0
 def test_clean_role(self):
     testAgent = Agent()
     testAgent.name = 'Test, Tester [tester]'
     testAgent.tmp_dates = []
     testAgent.tmp_roles = []
     testAgent.cleanName()
     self.assertEqual(testAgent.name, 'Test, Tester')
     self.assertEqual(testAgent.tmp_roles, ['tester'])
示例#16
0
 def test_clean_name_birth_only(self):
     testAgent = Agent()
     testAgent.name = 'Test, Tester 1950-'
     testAgent.tmp_dates = []
     testAgent.tmp_roles = []
     testAgent.cleanName()
     self.assertEqual(testAgent.tmp_roles, [])
     self.assertEqual(testAgent.name, 'Test, Tester')
     self.assertEqual(testAgent.tmp_dates[0]['display_date'], '1950')
示例#17
0
    def test_agent_update(self, mock_date, mock_link, mock_alias, mock_rm,
                          mock_clean, mock_tmp):
        testAgent = Agent()
        for tmp in [('tmp_aliases', ['Alias, Name']),
                    ('tmp_link', [{
                        'link': 'test_link'
                    }]), ('tmp_dates', ['test_date']),
                    ('tmp_roles', ['test'])]:
            setattr(testAgent, tmp[0], tmp[1])

        testAgent.name = 'Old, Name'

        newData = {'name': 'New, Name'}

        mock_alias.insertOrSkip.return_value = MagicMock()
        mock_link.updateOrInsert.side_effect = [MagicMock()]
        mock_date.updateOrInsert.side_effect = [MagicMock()]

        testAgent.update('session', newData)
        self.assertEqual(testAgent.name, 'New, Name')
示例#18
0
    def test_agent_insertData(self, mock_date, mock_link, mock_alias):
        testAgent = Agent()
        for tmp in [('tmp_aliases', ['Alias, Name']),
                    ('tmp_link', {
                        'link': 'test_link'
                    }), ('tmp_dates', [{
                        'date_type': 'test'
                    }]), ('tmp_roles', ['test'])]:
            setattr(testAgent, tmp[0], tmp[1])

        testAgent.name = 'Old, Name'

        newData = {'name': 'New, Name'}

        mock_alias.return_value = MagicMock()
        mock_link.side_effect = [MagicMock()]
        mock_date.insert.side_effect = [MagicMock()]

        testAgent.insertData(newData)
        self.assertEqual(testAgent.name, 'New, Name')
        self.assertEqual(testAgent.sort_name, 'new, name')
示例#19
0
 def test_combined(self):
     testAgent = Agent()
     testAgent.name = 'Test, Tester 1950-2000 [tester]'
     testAgent.tmp_dates = []
     testAgent.tmp_roles = []
     testAgent.cleanName()
     self.assertEqual(testAgent.name, 'Test, Tester')
     self.assertEqual(testAgent.tmp_roles, ['tester'])
     self.assertEqual(testAgent.tmp_dates[0]['display_date'], '1950')
     self.assertEqual(testAgent.tmp_dates[1]['display_date'], '2000')
示例#20
0
 def test_updateInsert_update(self):
     with patch('sfrCore.model.Agent.createAgent') as mock_create:
         mock_agent = MagicMock()
         mock_agent.lookup.return_value = 1
         mock_create.return_value = (mock_agent, ['test'])
         mock_existing = MagicMock()
         mock_existing.update.return_value = ['existing', 'test']
         mock_session = MagicMock()
         mock_session.query.return_value.get.return_value = mock_existing
         testAgent, roles = Agent.updateOrInsert(mock_session, 'fakeAgent')
         self.assertEqual(testAgent, mock_existing)
         self.assertTrue('existing' in roles and 'test' in roles)
示例#21
0
 def test_agent_remove_tmp_rels(self):
     testAgent = Agent('session')
     testAgent.createTmpRelations({})
     self.assertEqual(testAgent.tmp_roles, [])
     testAgent.removeTmpRelations()
     with self.assertRaises(AttributeError):
         testAgent.tmp_roles
示例#22
0
    def test_agent_lookup_authority(self, mock_auth):
        testAgent = Agent()
        testAgent.viaf = 999999999
        testAgent.lcnaf = 999999999
        testAgent.name = 'Tester, Test'

        res = testAgent.lookup()
        self.assertEqual(res, 'mockAgent')
示例#23
0
 def test_agent_create_err(self, mock_rm, mock_clean, mock_inst, mock_add):
     with patch.object(Agent, 'name', '    '):
         with self.assertRaises(DataError):
             testData = {'name': 'Name, New'}
             newAgent, newRoles = Agent.createAgent('session', testData)
示例#24
0
 def test_agent_create(self, mock_rm, mock_clean, mock_inst, mock_add):
     with patch.object(Agent, 'name', 'Name, New'):
         testData = {'name': 'Name, New'}
         newAgent, newRoles = Agent.createAgent('session', testData)
         self.assertEqual(newAgent.name, 'Name, New')
         self.assertEqual(newRoles, [])
示例#25
0
 def test_agent_init(self):
     testAgent = Agent('session')
     self.assertEqual(testAgent.session, 'session')
示例#26
0
    def test_agent_lookup_name(self, mock_auth):
        testAgent = Agent()
        testAgent.name = 'Tester, Test'

        res = testAgent.lookup()
        self.assertEqual(res, 'mockAgent')
示例#27
0
 def test_agent_tmp_rels(self):
     testAgent = Agent('session')
     testAgent.createTmpRelations({'roles': None, 'dates': ['date']})
     self.assertEqual(testAgent.tmp_aliases, [])
     self.assertEqual(testAgent.tmp_roles, [])
     self.assertEqual(testAgent.tmp_dates, ['date'])
示例#28
0
 def test_add_lifespan_date(self):
     testAgent = Agent()
     testAgent.tmp_dates = []
     testAgent.addLifespan('testdate', '1066')
     self.assertEqual(testAgent.tmp_dates[0]['display_date'], '1066')
示例#29
0
 def test_agent_dir(self):
     testAgent = Agent('session')
     self.assertEqual(dir(testAgent),
                      ['biography', 'lcnaf', 'name', 'sort_name', 'viaf'])