Пример #1
0
class RefererRequestTest(BaseTestCase):

    def setUp(self):
        """
        Create some referer tests.
        """
        super(RefererRequestTest, self).setUp()
        self.referer_test1 = RefererTestModel.objects.create(domain="www.google.com")
        self.referer_test2 = RefererTestModel.objects.create(domain="google.com")
        self.test = RefererTest()

    def test_simple_lookup(self):
        referer_url = "http://www.google.com/search?sclient=psy&hl=en&site=&source=hp&q=test&aq=f&aqi=&aql=&oq=&pbx=1&cad=cbv"
        request = self.req_factory.request(HTTP_REFERER=referer_url)
        match = self.test.test(request)
        assert match == self.referer_test1

    def test_lookup_fail(self):
        referer_url = "http://www.google.fr/search?sclient=psy&hl=en&site=&source=hp&q=test&aq=f&aqi=&aql=&oq=&pbx=1&cad=cbv"
        request = self.req_factory.request(HTTP_REFERER=referer_url)
        match = self.test.test(request)
        assert match is None

    def test_non_subdomain_match(self):
        referer_url = "http://google.com/search?sclient=psy&hl=en&site=&source=hp&q=test&aq=f&aqi=&aql=&oq=&pbx=1&cad=cbv"
        request = self.req_factory.request(HTTP_REFERER=referer_url)
        match = self.test.test(request)
        assert match == self.referer_test2
Пример #2
0
 def setUp(self):
     """
     Create some referer tests.
     """
     super(RefererRequestTest, self).setUp()
     self.referer_test1 = RefererTestModel.objects.create(domain="www.google.com")
     self.referer_test2 = RefererTestModel.objects.create(domain="google.com")
     self.test = RefererTest()