def test_unicode_token(self): mw = SecretBallotIpUseragentMiddleware() r = HttpRequest() r.META['REMOTE_ADDR'] = '1.2.3.4' r.META['HTTP_USER_AGENT'] = u"Orange España" mw.process_request(r) token = r.secretballot_token assert token == 'fdb9f3e35ac8355e1e97f338f0ede097'
def test_unicode_token(self): mw = SecretBallotIpUseragentMiddleware() r = HttpRequest() r.META['REMOTE_ADDR'] = '1.2.3.4' r.META['HTTP_USER_AGENT'] = u"Orange España" mw.process_request(r) token = r.secretballot_token assert token == 'fdb9f3e35ac8355e1e97f338f0ede097'
def test_ip_ua_middleware(self): mw = SecretBallotIpUseragentMiddleware() # basic token r = HttpRequest() r.META['REMOTE_ADDR'] = '1.2.3.4' r.META['HTTP_USER_AGENT'] = 'Firefox' mw.process_request(r) ff_token = r.secretballot_token # same one r = HttpRequest() r.META['REMOTE_ADDR'] = '1.2.3.4' r.META['HTTP_USER_AGENT'] = 'Firefox' mw.process_request(r) ff_token2 = r.secretballot_token assert ff_token == ff_token2 # different one r = HttpRequest() r.META['REMOTE_ADDR'] = '1.2.3.4' r.META['HTTP_USER_AGENT'] = 'Chrome' mw.process_request(r) chrome_token = r.secretballot_token assert ff_token != chrome_token # blank one r = HttpRequest() r.META['REMOTE_ADDR'] = '1.2.3.4' r.META['HTTP_USER_AGENT'] = '' mw.process_request(r) blank_token = r.secretballot_token assert ff_token != blank_token
def test_ip_ua_middleware(self): mw = SecretBallotIpUseragentMiddleware() # basic token r = HttpRequest() r.META['REMOTE_ADDR'] = '1.2.3.4' r.META['HTTP_USER_AGENT'] = 'Firefox' mw.process_request(r) ff_token = r.secretballot_token # same one r = HttpRequest() r.META['REMOTE_ADDR'] = '1.2.3.4' r.META['HTTP_USER_AGENT'] = 'Firefox' mw.process_request(r) ff_token2 = r.secretballot_token assert ff_token == ff_token2 # different one r = HttpRequest() r.META['REMOTE_ADDR'] = '1.2.3.4' r.META['HTTP_USER_AGENT'] = 'Chrome' mw.process_request(r) chrome_token = r.secretballot_token assert ff_token != chrome_token # blank one r = HttpRequest() r.META['REMOTE_ADDR'] = '1.2.3.4' r.META['HTTP_USER_AGENT'] = '' mw.process_request(r) blank_token = r.secretballot_token assert ff_token != blank_token