Exemplo n.º 1
0
    def test_process_query(self):
        mixin = LearningSiteSearchMixin()

        all = LearningSite.objects.all()
        qs = mixin._process_query(qs=all, q='site')
        self.assertEquals(qs.count(), 3)

        qs = mixin._process_query(qs=all, q='Alpha')
        self.assertEquals(qs.count(), 1)
        self.assertEquals(qs.first(), self.site1)

        qs = mixin._process_query(
            qs=all, q='category:{}'.format(self.site2.category.first().name))
        self.assertEquals(qs.count(), 1)
        self.assertEquals(qs.first(), self.site2)

        qs = mixin._process_query(qs=all, q='tag:red')
        self.assertEquals(qs.count(), 1)
        self.assertEquals(qs.first(), self.site3)

        all = LearningSite.objects.all()
        qs = mixin._process_query(
            qs=all, q='the first', full_search=True)
        self.assertEquals(qs.count(), 1)
        self.assertEquals(qs.first(), self.site1)
Exemplo n.º 2
0
    def test_process_years(self):
        mixin = LearningSiteSearchMixin()

        all = LearningSite.objects.all()

        qs = mixin._process_years(all, 1776, 2018)
        self.assertEquals(qs.count(), 2)
        self.assertTrue(self.site1 in qs)
        self.assertTrue(self.site3 in qs)

        qs = mixin._process_years(all, 1900, 1918)
        self.assertEquals(qs.count(), 1)
        self.assertTrue(self.site3 in qs)

        qs = mixin._process_years(all, 1980, 2018)
        self.assertEquals(qs.count(), 1)
        self.assertTrue(self.site1 in qs)

        qs = mixin._process_years(all, 1800, 1812)
        self.assertEquals(qs.count(), 0)
Exemplo n.º 3
0
 def test_filter_empty(self):
     mixin = LearningSiteSearchMixin()
     mixin.request = RequestFactory().get('/', {})
     mixin.request.user = AnonymousUser()
     qs = mixin.filter(LearningSite.objects.all())
     self.assertEquals(qs.count(), 3)