def test_postiive_decorator_coherence(self): self.pass_flag = False def run_me_to_pass(): self.pass_flag = True class FakeResponse(object): crosstown_tasks = [] status = "200 OK" through_to_you = crosstown_traffic.follow_response(same_thread=True) threading.current_thread().response_object = FakeResponse() through_to_you(run_me_to_pass) through_to_you.run(reactor.threadpool) # threadpool doesn't matter because same_thread is True. self.assertFalse(through_to_you.no_go) # If the no_go is False... self.assertTrue(self.pass_flag) # Then run_me_to_pass will have run.
def test_negative_decorator_coherence(self): def append_me_to_pass(): pass class FakeResponse(object): crosstown_tasks = [] status = "418 I'm a teapot. Seriously." through_to_you = crosstown_traffic.follow_response(same_thread=True) threading.current_thread().response_object = FakeResponse() through_to_you.no_go = True # If no_go is True... through_to_you(append_me_to_pass) # and we call it... self.assertFalse(through_to_you.response.crosstown_tasks) # We won't have added any tasks. through_to_you.no_go = False # However if no_go is False... through_to_you(append_me_to_pass) # and we call it... self.assertEqual(through_to_you.response.crosstown_tasks[0].crosstown_task, append_me_to_pass ) # We will have added the function.
def test_no_bad_status_codes_are_cool(self): through_to_you = crosstown_traffic.follow_response(no_go_status_codes=[418]) through_to_you.status_code = 404 through_to_you.check_status_code_against_no_go_list() self.assertFalse(through_to_you.no_go)
def test_bad_status_codes_cause_no_go_flag(self): through_to_you = crosstown_traffic.follow_response(no_go_status_codes=[418]) through_to_you.status_code = 418 through_to_you.check_status_code_against_no_go_list() self.assertTrue(through_to_you.no_go)