def setUp(self):
        response = Mock()
        response.content = b'\xEF\xBB\xBF{"success":[true]}'
        response.text = str(response.content)

        self.email = '*****@*****.**'
        self.ip = '1.234.56.7'

        self.no_spaces_params = {
            'firstname': 'Johann',
            'lastname': 'Vandergrift',
            'phone': '+14805559163'
        }

        self.spaces_params_first_name = {
            'firstname': 'Johann Paulus',
            'lastname': 'Vandergrift',
            'phone': '+14805559163'
        }

        self.spaces_params_last_name = {
            'firstname': 'Johann',
            'lastname': 'van der Grift',
            'phone': '+14805559163'
        }

        if self._tls_version is not None:
            self.subj = EmailageClient('secret',
                                       'token',
                                       sandbox=True,
                                       tls_version=self._tls_version)
        else:
            self.subj = EmailageClient('secret', 'token', sandbox=True)

        self.g = self.subj.session.get = Mock(return_value=response)
class ClientTest(unittest.TestCase):

    _tls_version = None
    _http_method = None
    _timeout = None
    mocked_session = None

    def setUp(self):

        self.email = '*****@*****.**'
        self.ip = '1.234.56.7'

        self.no_spaces_params = {
            'firstname': 'Johann',
            'lastname': 'Vandergrift',
            'phone': '+14805559163'
        }

        self.spaces_params_first_name = {
            'firstname': 'Johann Paulus',
            'lastname': 'Vandergrift',
            'phone': '+14805559163'
        }

        self.spaces_params_last_name = {
            'firstname': 'Johann',
            'lastname': 'van der Grift',
            'phone': '+14805559163'
        }

        if self._tls_version is not None:
            self.subj = EmailageClient('secret',
                                       'token',
                                       sandbox=True,
                                       tls_version=self._tls_version,
                                       timeout=self._timeout)
        else:
            self.subj = EmailageClient('secret', 'token', sandbox=True, timeout=self._timeout)

        if self._http_method is not None:
            self.subj.set_http_method(self._http_method)

        session_mockup = RequestsSessionMockup()
        session_mockup.set_response_for_http_verb(self.subj.http_method, '{"success":[true]}')
        self.mocked_session = session_mockup.mock_object

        self.subj.session = self.mocked_session

    def test_is_initialized_with_properties(self):
        self.assertTrue(self.subj.sandbox)

    def test_generates_appropriate_key(self):
        self.assertEqual(self.subj.hmac_key, 'token&')
Exemple #3
0
    def setUp(self):
        response = Mock()
        response.text = '\xEF\xBB\xBF{"success":[true]}'

        self.email = '*****@*****.**'
        self.ip = '1.234.56.7'

        if self._tls_version is not None:
            self.subj = EmailageClient('secret',
                                       'token',
                                       sandbox=True,
                                       tls_version=self._tls_version)
        else:
            self.subj = EmailageClient('secret', 'token', sandbox=True)

        self.g = self.subj.session.get = Mock(return_value=response)
    def setUp(self):
        self.api_secret = os.getenv('ENV_SECRET') or 'TEST_SECRET'
        self.api_token = os.getenv('ENV_TOKEN') or 'TEST_TOKEN'

        if self.api_secret == 'TEST_SECRET' and self.api_token == 'TEST_TOKEN':
            raise AssertionError(
                "Ensure you have set valid login credentials in your environment"
            )

        self.api_domain = os.getenv('ENV_DOMAIN') or ApiDomains.sandbox
        self.api_user_email = os.getenv(
            'ENV_USER_EMAIL') or '*****@*****.**'

        self.client_instance = EmailageClient(self.api_secret, self.api_token)
        self.client_instance.set_api_domain(self.api_domain)

        self.test_query_email = '*****@*****.**'
        self.test_query_ip = '13.25.10.245'

        self.no_spaces_params = {
            'firstname': 'Johann',
            'lastname': 'Vandergrift',
            'phone': '+14805559163'
        }

        self.spaces_params_first_name = {
            'firstname': 'Johann Paulus',
            'lastname': 'Vandergrift',
            'phone': '+14805559163'
        }

        self.spaces_params_last_name = {
            'firstname': 'Johann',
            'lastname': 'van der Grift',
            'phone': '+14805559163'
        }

        self.responseStatusSuccess = {
            'status': 'success',
            'errorCode': '0',
            'description': ''
        }
    def setUp(self):

        self.email = '*****@*****.**'
        self.ip = '1.234.56.7'

        self.no_spaces_params = {
            'firstname': 'Johann',
            'lastname': 'Vandergrift',
            'phone': '+14805559163'
        }

        self.spaces_params_first_name = {
            'firstname': 'Johann Paulus',
            'lastname': 'Vandergrift',
            'phone': '+14805559163'
        }

        self.spaces_params_last_name = {
            'firstname': 'Johann',
            'lastname': 'van der Grift',
            'phone': '+14805559163'
        }

        if self._tls_version is not None:
            self.subj = EmailageClient('secret',
                                       'token',
                                       sandbox=True,
                                       tls_version=self._tls_version,
                                       timeout=self._timeout)
        else:
            self.subj = EmailageClient('secret', 'token', sandbox=True, timeout=self._timeout)

        if self._http_method is not None:
            self.subj.set_http_method(self._http_method)

        session_mockup = RequestsSessionMockup()
        session_mockup.set_response_for_http_verb(self.subj.http_method, '{"success":[true]}')
        self.mocked_session = session_mockup.mock_object

        self.subj.session = self.mocked_session
    def setUp(self):
        self.api_secret = os.getenv('ENV_SECRET') or 'TEST_SECRET'
        self.api_token = os.getenv('ENV_TOKEN') or 'TEST_TOKEN'

        if self.api_secret == 'TEST_SECRET' and self.api_token == 'TEST_TOKEN':
            raise AssertionError("Ensure you have set valid login credentials in your environment")

        self.api_domain = os.getenv('ENV_DOMAIN') or ApiDomains.sandbox
        self.api_user_email = os.getenv('ENV_USER_EMAIL') or '*****@*****.**'

        self.client_instance = EmailageClient(self.api_secret, self.api_token)
        self.client_instance.set_api_domain(self.api_domain)

        self.test_query_email = '*****@*****.**'
        self.test_query_ip = '13.25.10.245'

        self.no_spaces_params = {
            'first_name': 'Johann',
            'last_name': 'Vandergrift',
            'phone': '+14805559163'
        }

        self.spaces_params_first_name = {
            'first_name': 'Johann Paulus',
            'last_name': 'Vandergrift',
            'phone': '+14805559163'
        }

        self.spaces_params_last_name = {
            'first_name': 'Johann',
            'last_name': 'van der Grift',
            'phone': '+14805559163'
        }

        self.responseStatusSuccess = {
            'status': 'success',
            'errorCode': '0',
            'description': ''
        }
class IntegrationTest(unittest.TestCase):

    def setUp(self):
        self.api_secret = os.getenv('ENV_SECRET') or 'TEST_SECRET'
        self.api_token = os.getenv('ENV_TOKEN') or 'TEST_TOKEN'

        if self.api_secret == 'TEST_SECRET' and self.api_token == 'TEST_TOKEN':
            raise AssertionError("Ensure you have set valid login credentials in your environment")

        self.api_domain = os.getenv('ENV_DOMAIN') or ApiDomains.sandbox
        self.api_user_email = os.getenv('ENV_USER_EMAIL') or '*****@*****.**'

        self.client_instance = EmailageClient(self.api_secret, self.api_token)
        self.client_instance.set_api_domain(self.api_domain)

        self.test_query_email = '*****@*****.**'
        self.test_query_ip = '13.25.10.245'

        self.no_spaces_params = {
            'firstname': 'Johann',
            'lastname': 'Vandergrift',
            'phone': '+14805559163'
        }

        self.spaces_params_first_name = {
            'firstname': 'Johann Paulus',
            'lastname': 'Vandergrift',
            'phone': '+14805559163'
        }

        self.spaces_params_last_name = {
            'firstname': 'Johann',
            'lastname': 'van der Grift',
            'phone': '+14805559163'
        }

        self.responseStatusSuccess = {
            'status': 'success',
            'errorCode': '0',
            'description': ''
        }

    def test_trivial_client_query(self):

        test_query_email = '*****@*****.**'

        params = {
            'user_email': self.api_user_email,
        }

        response = self.client_instance.query(test_query_email, **params)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)

        self.assertEqual(response['query']['email'], test_query_email)

    def test_trivial_email_ip_client_query(self):

        test_query_tuple = (self.test_query_email, self.test_query_ip)

        params = {
            'user_email': self.api_user_email
        }

        response = self.client_instance.query(test_query_tuple, **params)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)
        self.assertEqual(response['query']['email'], self.test_query_email + '+' + self.test_query_ip)

    def test_email_optional_params_no_spaces_client_query(self):

        self.no_spaces_params['user_email'] = self.api_user_email

        response = self.client_instance.query(self.test_query_email, **self.no_spaces_params)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)
        self.assertEqual(response['query']['email'], self.test_query_email)

    def test_email_ip_optional_params_no_spaces_client_query(self):

        test_query_tuple = (self.test_query_email, self.test_query_ip)

        self.no_spaces_params['user_email'] = self.api_user_email

        response = self.client_instance.query(test_query_tuple, **self.no_spaces_params)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)
        self.assertEqual(response['query']['email'], self.test_query_email + '+' + self.test_query_ip)

    def test_email_optional_params_first_name_space_client_query(self):

        self.spaces_params_first_name['user_email'] = self.api_user_email

        response = self.client_instance.query(self.test_query_email, **self.spaces_params_first_name)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)
        self.assertEqual(response['query']['email'], self.test_query_email)

    def test_email_ip_optional_params_first_name_space_client_query(self):

        test_query_tuple = (self.test_query_email, self.test_query_ip)

        self.spaces_params_first_name['user_email'] = self.api_user_email

        response = self.client_instance.query(test_query_tuple, **self.spaces_params_first_name)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)
        self.assertEqual(response['query']['email'], self.test_query_email + '+' + self.test_query_ip)

    def test_email_optional_params_last_name_space_client_query(self):

        self.spaces_params_last_name['user_email'] = self.api_user_email

        response = self.client_instance.query(self.test_query_email, **self.spaces_params_last_name)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)
        self.assertEqual(response['query']['email'], self.test_query_email)

    def test_email_ip_optional_params_last_name_space_client_query(self):

        test_query_tuple = (self.test_query_email, self.test_query_ip)

        self.spaces_params_last_name['user_email'] = self.api_user_email

        response = self.client_instance.query(test_query_tuple, **self.spaces_params_last_name)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)
        self.assertEqual(response['query']['email'], self.test_query_email + '+' + self.test_query_ip)
class IntegrationTest(unittest.TestCase):

    def setUp(self):
        self.api_secret = os.getenv('ENV_SECRET') or 'TEST_SECRET'
        self.api_token = os.getenv('ENV_TOKEN') or 'TEST_TOKEN'

        if self.api_secret == 'TEST_SECRET' and self.api_token == 'TEST_TOKEN':
            raise AssertionError("Ensure you have set valid login credentials in your environment")

        self.api_domain = os.getenv('ENV_DOMAIN') or ApiDomains.sandbox
        self.api_user_email = os.getenv('ENV_USER_EMAIL') or '*****@*****.**'

        self.client_instance = EmailageClient(self.api_secret, self.api_token)
        self.client_instance.set_api_domain(self.api_domain)

        self.test_query_email = '*****@*****.**'
        self.test_query_ip = '13.25.10.245'

        self.no_spaces_params = {
            'first_name': 'Johann',
            'last_name': 'Vandergrift',
            'phone': '+14805559163'
        }

        self.spaces_params_first_name = {
            'first_name': 'Johann Paulus',
            'last_name': 'Vandergrift',
            'phone': '+14805559163'
        }

        self.spaces_params_last_name = {
            'first_name': 'Johann',
            'last_name': 'van der Grift',
            'phone': '+14805559163'
        }

        self.responseStatusSuccess = {
            'status': 'success',
            'errorCode': '0',
            'description': ''
        }

    def test_trivial_client_query(self):

        test_query_email = '*****@*****.**'

        params = {
            'user_email': self.api_user_email,
        }

        response = self.client_instance.query(test_query_email, **params)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)

        self.assertEqual(response['query']['email'], test_query_email)

    def test_trivial_email_ip_client_query(self):

        test_query_tuple = (self.test_query_email, self.test_query_ip)

        params = {
            'user_email': self.api_user_email
        }

        response = self.client_instance.query(test_query_tuple, **params)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)
        self.assertEqual(response['query']['email'], self.test_query_email + '+' + self.test_query_ip)

    def test_email_optional_params_no_spaces_client_query(self):

        self.no_spaces_params['user_email'] = self.api_user_email

        response = self.client_instance.query(self.test_query_email, **self.no_spaces_params)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)
        self.assertEqual(response['query']['email'], self.test_query_email)

    def test_email_ip_optional_params_no_spaces_client_query(self):

        test_query_tuple = (self.test_query_email, self.test_query_ip)

        self.no_spaces_params['user_email'] = self.api_user_email

        response = self.client_instance.query(test_query_tuple, **self.no_spaces_params)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)
        self.assertEqual(response['query']['email'], self.test_query_email + '+' + self.test_query_ip)

    def test_email_optional_params_first_name_space_client_query(self):

        self.spaces_params_first_name['user_email'] = self.api_user_email

        response = self.client_instance.query(self.test_query_email, **self.spaces_params_first_name)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)
        self.assertEqual(response['query']['email'], self.test_query_email)

    def test_email_ip_optional_params_first_name_space_client_query(self):

        test_query_tuple = (self.test_query_email, self.test_query_ip)

        self.spaces_params_first_name['user_email'] = self.api_user_email

        response = self.client_instance.query(test_query_tuple, **self.spaces_params_first_name)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)
        self.assertEqual(response['query']['email'], self.test_query_email + '+' + self.test_query_ip)

    def test_email_optional_params_last_name_space_client_query(self):

        self.spaces_params_last_name['user_email'] = self.api_user_email

        response = self.client_instance.query(self.test_query_email, **self.spaces_params_last_name)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)
        self.assertEqual(response['query']['email'], self.test_query_email)

    def test_email_ip_optional_params_last_name_space_client_query(self):

        test_query_tuple = (self.test_query_email, self.test_query_ip)

        self.spaces_params_last_name['user_email'] = self.api_user_email

        response = self.client_instance.query(test_query_tuple, **self.spaces_params_last_name)

        self.assertIsNotNone(response)
        self.assertDictEqual(response['responseStatus'], self.responseStatusSuccess)
        self.assertEqual(response['query']['email'], self.test_query_email + '+' + self.test_query_ip)