コード例 #1
0
 def test_request_doing_with_right_params(self, logger_exception, get,
                                          settings):
     settings.BRITEVERIFY_API_KEY = BRITEVERIFY_API_KEY
     check_email(self.example_email)
     get.assert_called_with(
         ENTRY_POINT,
         data={'address': self.example_email,
               'apikey': BRITEVERIFY_API_KEY},
         timeout=TIMEOUT)
コード例 #2
0
 def test_checking_network_error(self, logger_exception, get, settings):
     get.side_effect = HTTPError
     settings.BRITEVERIFY_API_KEY = BRITEVERIFY_API_KEY
     self.assertDictEqual(DEFAULT_RESULT,
                          check_email(self.example_email))
     self.assertTrue(get.called)
     logger_exception.assert_called_with('Briteverify service error.')
コード例 #3
0
    def test_email_not_valid(self, logger_exception, get, settings):
        json_method = mock.MagicMock()
        json_method.return_value = dict(EXAMPLE_API_RESPONSE)
        get.return_value.json = json_method
        settings.BRITEVERIFY_API_KEY = BRITEVERIFY_API_KEY

        self.assertDictEqual(dict(DEFAULT_RESULT, valid=False),
                             check_email(self.example_email))
        self.assertTrue(get.called)
        self.assertTrue(json_method.called)
        self.assertFalse(logger_exception.called)
コード例 #4
0
    def test_invalid_json_data(self, logger_exception, get, settings):
        json_method = mock.MagicMock()
        json_method.side_effect = ValueError
        get.return_value.json = json_method
        settings.BRITEVERIFY_API_KEY = BRITEVERIFY_API_KEY

        self.assertDictEqual(DEFAULT_RESULT,
                             check_email(self.example_email))
        self.assertTrue(get.called)
        self.assertTrue(json_method.called)
        logger_exception.assert_called_with(
            'Briteverify service error. No json received.')
コード例 #5
0
    def test_bad_json_structure(self, logger_exception, get, settings):
        json_method = mock.MagicMock()
        json_method.return_value = dict()
        get.return_value.json = json_method
        settings.BRITEVERIFY_API_KEY = BRITEVERIFY_API_KEY

        self.assertDictEqual(DEFAULT_RESULT,
                             check_email(self.example_email))
        self.assertTrue(get.called)
        self.assertTrue(json_method.called)

        logger_exception.assert_called_with(
            'Briteverify service error. Bad json data: %r',
            json_method.return_value)
コード例 #6
0
    def clean(self):
        super(BriteverifyFormMixin, self).clean()

        email = self.cleaned_data.get(self.EMAIL_FIELD_NAME)

        # If we already have errors - not making request to service
        if not email or self.errors:
            return

        email_status = check_email(email)

        if not email_status['valid']:
            self.add_error(self.EMAIL_FIELD_NAME,
                           self.error_messages['invalid_email'])
            return

        if email_status['disposable']:
            self.add_error(self.EMAIL_FIELD_NAME,
                           self.error_messages['disposable_email'])
            return
コード例 #7
0
 def test_checking_disable(self, logger_exception, get, settings):
     settings.BRITEVERIFY_API_KEY = None
     self.assertDictEqual(DEFAULT_RESULT,
                          check_email(self.example_email))
     self.assertFalse(get.called)