Exemplo n.º 1
0
    def test_find_users_api_no_match(self):
        '''It should not find user if no match'''
        UserFactory.create_batch(3)

        response = self.get(url_for('api.users', q='xxxxxx'))
        self.assert200(response)
        self.assertEqual(len(response.json['data']), 0)
Exemplo n.º 2
0
    def test_suggest_users_api_no_match(self):
        '''It should not provide user suggestion if no match'''
        with self.autoindex():
            UserFactory.create_batch(3)

        response = self.get(url_for('api.suggest_users'),
                            qs={'q': 'xxxxxx', 'size': '5'})
        self.assert200(response)
        self.assertEqual(len(response.json), 0)
Exemplo n.º 3
0
    def test_suggest_users_api_no_match(self):
        '''It should not provide user suggestion if no match'''
        with self.autoindex():
            UserFactory.create_batch(3)

        response = self.get(url_for('api.suggest_users'),
                            qs={'q': 'xxxxxx', 'size': '5'})
        self.assert200(response)
        self.assertEqual(len(response.json), 0)
Exemplo n.º 4
0
    def test_suggest_users_api_no_dedup(self):
        '''It should suggest users without deduplicating homonyms'''
        with self.autoindex():
            UserFactory.create_batch(2, first_name='test', last_name='homonym')

        response = self.get(url_for('api.suggest_users'),
                            qs={'q': 'homonym', 'size': '5'})
        self.assert200(response)

        self.assertEqual(len(response.json), 2)

        for suggestion in response.json:
            self.assertEqual(suggestion['first_name'], 'test')
            self.assertEqual(suggestion['last_name'], 'homonym')
Exemplo n.º 5
0
    def test_suggest_users_api_no_dedup(self):
        '''It should suggest users without deduplicating homonyms'''
        with self.autoindex():
            UserFactory.create_batch(2, first_name='test', last_name='homonym')

        response = self.get(url_for('api.suggest_users'),
                            qs={'q': 'homonym', 'size': '5'})
        self.assert200(response)

        self.assertEqual(len(response.json), 2)

        for suggestion in response.json:
            self.assertEqual(suggestion['first_name'], 'test')
            self.assertEqual(suggestion['last_name'], 'homonym')
Exemplo n.º 6
0
    def test_suggest_users_api_by_id(self):
        '''It should suggest an user based on its ID'''
        with self.autoindex():
            users = UserFactory.create_batch(4)

        first_user = users[0]
        response = self.get(url_for('api.suggest_users'),
                            qs={'q': str(first_user.id), 'size': '5'})
        self.assert200(response)

        # The batch factory generates ids that might be too close
        # which then are found with the fuzzy search.
        suggested_ids = [u['id'] for u in response.json]
        self.assertGreaterEqual(len(suggested_ids), 1)
        self.assertIn(str(first_user.id), suggested_ids)
Exemplo n.º 7
0
    def test_suggest_users_api_by_id(self):
        '''It should suggest an user based on its ID'''
        with self.autoindex():
            users = UserFactory.create_batch(4)

        first_user = users[0]
        response = self.get(url_for('api.suggest_users'),
                            qs={'q': str(first_user.id), 'size': '5'})
        self.assert200(response)

        # The batch factory generates ids that might be too close
        # which then are found with the fuzzy search.
        suggested_ids = [u['id'] for u in response.json]
        self.assertGreaterEqual(len(suggested_ids), 1)
        self.assertIn(str(first_user.id), suggested_ids)