예제 #1
0
    def test_search__finds_matches_multiple_models__ignores_misses(self):
        expected_1 = mommy.make(FirstSearchModel, email='*****@*****.**')
        expected_2 = mommy.make(FirstSearchModel, email='*****@*****.**')
        expected_3 = mommy.make(SecondSearchModel, email='*****@*****.**')
        expected_4 = mommy.make(SecondSearchModel, email='*****@*****.**')
        mommy.make(FirstSearchModel, email='*****@*****.**')
        mommy.make(SecondSearchModel, email='*****@*****.**')

        full_results = registry.search('*****@*****.**')
        self.assertEqual(len(full_results), 2)

        # Sort full results into testable order
        model_0, results_0 = full_results[0]
        model_1, results_1 = full_results[1]

        if model_0 is SecondSearchModel:
            model_0, results_0, model_1, results_1 = (
                model_1, results_1, model_0, results_0,
            )

        self.assertEqual(model_0, FirstSearchModel)
        self.assertEqual(results_0.count(), 2)
        self.assertEqual(results_0[0].pk, expected_1.pk)
        self.assertEqual(results_0[1].pk, expected_2.pk)

        self.assertEqual(model_1, SecondSearchModel)
        self.assertEqual(results_1.count(), 2)
        self.assertEqual(results_1[0].pk, expected_3.pk)
        self.assertEqual(results_1[1].pk, expected_4.pk)
예제 #2
0
    def test_search__finds_match_first_model__ignores_misses(self):
        expected = FirstSearchModelFactory.create(email='*****@*****.**')
        FirstSearchModelFactory.create(email='*****@*****.**')
        SecondSearchModelFactory.create(email='*****@*****.**')

        full_results = registry.search('*****@*****.**')
        self.assertEqual(len(full_results), 1)

        model, results = full_results[0]
        self.assertEqual(model, FirstSearchModel)
        self.assertEqual(results.count(), 1)
        self.assertEqual(results[0].pk, expected.pk)
예제 #3
0
    def test_search__finds_match_second_model__ignores_misses(self):
        expected = mommy.make(SecondSearchModel, email='*****@*****.**')
        mommy.make(FirstSearchModel, email='*****@*****.**')
        mommy.make(SecondSearchModel, email='*****@*****.**')

        full_results = registry.search('*****@*****.**')
        self.assertEqual(len(full_results), 1)

        model, results = full_results[0]
        self.assertEqual(model, SecondSearchModel)
        self.assertEqual(results.count(), 1)
        self.assertEqual(results[0].pk, expected.pk)
예제 #4
0
    def test_search__finds_match_first_model__ignores_misses(self):
        expected = baker.make(FirstSearchModel, email="*****@*****.**")
        baker.make(FirstSearchModel, email="*****@*****.**")
        baker.make(SecondSearchModel, email="*****@*****.**")

        full_results = registry.search("*****@*****.**")
        self.assertEqual(len(full_results), 1)

        model, results = full_results[0]
        self.assertEqual(model, FirstSearchModel)
        self.assertEqual(results.count(), 1)
        self.assertEqual(results[0].pk, expected.pk)