def test_is_whitelisted_returns_true_request_with_many_whitelist(self): path_match = '/match/me/' method_match = 'MATCH' self.whitelist.append({'path': '/path/2', 'method': 'method2'}) self.whitelist.append({'path': '/path/3', 'method': 'method3'}) self.whitelist.append({'path': path_match, 'method': method_match}) self.whitelist.append({'path': '/path/4', 'method': 'method4'}) setattr(self.request, 'path', path_match) setattr(self.request, 'method', method_match) self.assertTrue(is_whitelisted(self.request, self.whitelist))
def test_when_regex_is_greedy(self): whitelist = [{'path': '/some/path/long'}] setattr(self.request, 'path', '/some/path/longer') self.assertTrue(is_whitelisted(self.request, whitelist))
def test_is_whitelisted_returns_false_request_no_match_method(self): setattr(self.request, 'method', 'INVALID_METHOD') self.whitelist[0]['method'] = self.dummy_method self.assertFalse(is_whitelisted(self.request, self.whitelist))
def test_is_whitelisted_returns_true_request_match_method(self): self.whitelist[0]['method'] = self.dummy_method self.assertTrue(is_whitelisted(self.request, self.whitelist))
def test_is_whitelisted_true_response_path_matched(self): self.assertTrue(is_whitelisted(self.request, self.whitelist))
def test_is_whitelisted_returns_false_no_match_code(self): self.whitelist[0]['method'] = self.dummy_method self.whitelist[0]['code'] = 'WONT_MATCH' self.assertFalse(is_whitelisted(self.request, self.whitelist))
def test_is_whitelisted_returns_true_request_matching_path(self): self.assertTrue(is_whitelisted(self.request, self.whitelist))
def test_is_whitelisted_returns_false_request_path_not_found(self): setattr(self.request, 'path', '/some/unfound/path/') self.assertFalse(is_whitelisted(self.request, self.whitelist))