def test_requires_petpoint_login_parser_should_exit_without_calling_underlying_parser_for_authentication_failure(self):
        please_sign_in_response = fake_response_from_file('signinout/please_sign_in.html')
        login_request = FakeSpider().fake_parse_requiring_login(please_sign_in_response)
        second_please_sign_in_response = fake_response_from_file('signinout/please_sign_in.html')
        auth_failure_parse_result = login_request.callback(second_please_sign_in_response)

        self.assertIsNone(auth_failure_parse_result)
    def test_requires_petpoint_login_parser_should_log_an_error_for_authentication_failure(self):
        spider = FakeSpider()
        please_sign_in_response = fake_response_from_file('signinout/please_sign_in.html')
        login_request = spider.fake_parse_requiring_login(please_sign_in_response)
        second_please_sign_in_response = fake_response_from_file('signinout/please_sign_in.html')
        login_request.callback(second_please_sign_in_response)

        self.assertEqual(1, len(spider.logger.errors))
    def test_requires_petpoint_login_parser_should_log_on_login(self):
        please_sign_in_response = fake_response_from_file('signinout/please_sign_in.html')
        spider = FakeSpider()
        spider.fake_parse_requiring_login(please_sign_in_response)

        self.assertListEqual([], spider.logger.errors)
        self.assertEqual(1, len(spider.logger.infos))
    def test_requires_petpoint_login_parser_should_not_spam_log_for_successful_authentication(self):
        authenticated_response = fake_response_from_file('AnimalTab/blank.html')
        spider = FakeSpider()
        spider.fake_parse_requiring_login(authenticated_response)

        self.assertListEqual([], spider.logger.errors)
        self.assertListEqual([], spider.logger.infos)
    def test_parse_animal_search_criteria(self):
        response = fake_response_from_file('AnimalTab/blank.html')
        parsed_criteria = self.spider.parse_animal_search_criteria(response)

        self.assertEqual(
            parsed_criteria,
            {
                u'Animal Number': 0,
                u'Case Number': 6,
                u'Case Reference #': 11,
                u'Group #': 12,
                u'Last 10': 9,
                u'Location': 3,
                u'Microchip ID': 1,
                u'Name': 5,
                u'Owner Address': 10,
                u'Owner Name': 7,
                u'Pet ID': 2,
                u'Reference # (ARN)': 8,
                u'Stage': 4
            }
        )
    def test_requires_petpoint_login_parser_should_perform_login_if_necessary(self):
        please_sign_in_response = fake_response_from_file('signinout/please_sign_in.html')
        result = FakeSpider().fake_parse_requiring_login(please_sign_in_response)

        # Verifying the format is too picky, do it in integration testing
        self.assertIsInstance(result, FormRequest)
    def test_requires_petpoint_login_parser_should_pass_through_to_underlying_parser_if_logged_in(self):
        authenticated_response = fake_response_from_file('AnimalTab/blank.html')
        result = FakeSpider().fake_parse_requiring_login(authenticated_response)

        self.assertEqual(result, "parse output")