Exemple #1
0
    def test_resource_list_request_error(self, requests_patched):
        requests_patched.get.side_effect = RequestException(
            'API is acting up!')
        client = DlogrClient('http://api.dlogr.com')

        with self.assertRaises(DlogrAPIError) as context:
            client.Event.list()
        self.assertEquals('{}'.format(context.exception), 'API is acting up!')
Exemple #2
0
def create_event(base_api_url, auth_token, message, timestamp, object_id,
                 object_type, human_identifier):
    client = DlogrClient(base_api_url=base_api_url, auth_token=auth_token)
    return client.Event.create(message=message,
                               timestamp=timestamp,
                               object_id=object_id,
                               object_type=object_type,
                               human_identifier=human_identifier)
Exemple #3
0
    def test_resource_update_request_error(self, requests_patched):
        requests_patched.patch.side_effect = RequestException(
            'API is acting up!')
        client = DlogrClient('http://api.dlogr.com')

        with self.assertRaises(DlogrAPIError) as context:
            client.Event.update('object_id',
                                email='*****@*****.**',
                                name='New Hamster')
        self.assertEquals('{}'.format(context.exception), 'API is acting up!')
Exemple #4
0
    def test_resource_create_request_error(self, requests_patched):
        requests_patched.post.side_effect = RequestException(
            'API is acting up!')
        client = DlogrClient('http://api.dlogr.com')

        with self.assertRaises(DlogrAPIError) as context:
            client.Event.create(email='*****@*****.**',
                                password='******',
                                name='Hamster')
        self.assertEquals('{}'.format(context.exception), 'API is acting up!')
Exemple #5
0
    def test_resource_retrieve_events(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com')
        client.Event.retrieve('object_id')

        requests_patched.get.assert_called_once_with(
            'http://api.dlogr.com/api/events/object_id',
            auth=None,
            headers={'user-agent': mock.ANY},
            data=None,
            params=None,
            verify=mock.ANY,
        )
Exemple #6
0
    def test_resource_delete_customers(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com')
        client.Customer.delete('object_id')

        requests_patched.delete.assert_called_once_with(
            'http://api.dlogr.com/api/customers/object_id',
            auth=None,
            headers={'user-agent': mock.ANY},
            data=None,
            params=None,
            verify=mock.ANY,
        )
Exemple #7
0
    def test_resource_delete_auth_credentials(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com',
                             auth_credentials=('*****@*****.**', 'sikret'))
        client.Event.delete('object_id')

        requests_patched.delete.assert_called_once_with(
            'http://api.dlogr.com/api/events/object_id',
            auth=('*****@*****.**', 'sikret'),
            headers={'user-agent': mock.ANY},
            data=None,
            params=None,
            verify=mock.ANY,
        )
Exemple #8
0
    def test_verify_account(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com')

        client.Auth.verify_account(token='wildhash')

        requests_patched.post.assert_called_once_with(
            'http://api.dlogr.com/api/auth/verify-account',
            auth=None,
            headers={'user-agent': mock.ANY},
            data={'token': 'wildhash'},
            params=None,
            verify=mock.ANY,
        )
Exemple #9
0
    def test_reset_password(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com')

        client.Auth.reset_password(email='*****@*****.**')

        requests_patched.post.assert_called_once_with(
            'http://api.dlogr.com/api/auth/reset-password',
            auth=None,
            headers={'user-agent': mock.ANY},
            data={'email': '*****@*****.**'},
            params=None,
            verify=mock.ANY,
        )
Exemple #10
0
    def test_resource_list_customers(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com')
        client.Customer.list()

        requests_patched.get.assert_called_once_with(
            'http://api.dlogr.com/api/customers',
            auth=None,
            headers={'user-agent': mock.ANY},
            data=None,
            params={
                'limit': 30,
                'offset': 0
            },
            verify=mock.ANY,
        )
Exemple #11
0
    def test_resource_list_limit_offset(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com')
        client.Event.list(limit=100, offset=50)

        requests_patched.get.assert_called_once_with(
            'http://api.dlogr.com/api/events',
            auth=None,
            headers={'user-agent': mock.ANY},
            data=None,
            params={
                'limit': 100,
                'offset': 50
            },
            verify=mock.ANY,
        )
Exemple #12
0
    def test_resource_list_auth_credentials(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com',
                             auth_credentials=('*****@*****.**', 'sikret'))
        client.Event.list()

        requests_patched.get.assert_called_once_with(
            'http://api.dlogr.com/api/events',
            auth=('*****@*****.**', 'sikret'),
            headers={'user-agent': mock.ANY},
            data=None,
            params={
                'limit': 30,
                'offset': 0
            },
            verify=mock.ANY,
        )
Exemple #13
0
    def test_resource_delete_auth_token(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com',
                             auth_token='weirdhashhere')
        client.Event.delete('object_id')

        requests_patched.delete.assert_called_once_with(
            'http://api.dlogr.com/api/events/object_id',
            auth=None,
            headers={
                'user-agent': mock.ANY,
                'Authorization': 'Token weirdhashhere'
            },
            data=None,
            params=None,
            verify=mock.ANY,
        )
Exemple #14
0
    def test_resource_list_additional_parameters(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com')
        client.Event.list(fields='unicorn', answer=42)

        requests_patched.get.assert_called_once_with(
            'http://api.dlogr.com/api/events',
            auth=None,
            headers={'user-agent': mock.ANY},
            data=None,
            params={
                'limit': 30,
                'offset': 0,
                'fields': 'unicorn',
                'answer': 42
            },
            verify=mock.ANY,
        )
Exemple #15
0
    def test_resource_update_customers(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com')
        client.Customer.update('object_id',
                               email='*****@*****.**',
                               name='New Hamster')

        requests_patched.patch.assert_called_once_with(
            'http://api.dlogr.com/api/customers/object_id',
            auth=None,
            headers={'user-agent': mock.ANY},
            data={
                'email': '*****@*****.**',
                'name': 'New Hamster'
            },
            params=None,
            verify=mock.ANY,
        )
Exemple #16
0
    def test_resource_update_auth_credentials(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com',
                             auth_credentials=('*****@*****.**', 'sikret'))
        client.Event.update('object_id',
                            email='*****@*****.**',
                            name='New Hamster')

        requests_patched.patch.assert_called_once_with(
            'http://api.dlogr.com/api/events/object_id',
            auth=('*****@*****.**', 'sikret'),
            headers={'user-agent': mock.ANY},
            data={
                'email': '*****@*****.**',
                'name': 'New Hamster'
            },
            params=None,
            verify=mock.ANY,
        )
Exemple #17
0
    def test_resource_create_customers(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com')
        client.Customer.create(email='*****@*****.**',
                               password='******',
                               name='Hamster')

        requests_patched.post.assert_called_once_with(
            'http://api.dlogr.com/api/customers',
            auth=None,
            headers={'user-agent': mock.ANY},
            data={
                'email': '*****@*****.**',
                'password': '******',
                'name': 'Hamster'
            },
            params=None,
            verify=mock.ANY,
        )
Exemple #18
0
    def test_resource_list_auth_token(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com',
                             auth_token='weirdhashhere')
        client.Event.list()

        requests_patched.get.assert_called_once_with(
            'http://api.dlogr.com/api/events',
            auth=None,
            headers={
                'user-agent': mock.ANY,
                'Authorization': 'Token weirdhashhere'
            },
            data=None,
            params={
                'limit': 30,
                'offset': 0
            },
            verify=mock.ANY,
        )
Exemple #19
0
    def test_change_password(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com')

        client.Auth.change_password(email='*****@*****.**',
                                    password='******',
                                    new_password='******',
                                    reset_token='hashhh')

        requests_patched.post.assert_called_once_with(
            'http://api.dlogr.com/api/auth/change-password',
            auth=None,
            headers={'user-agent': mock.ANY},
            data={
                'email': '*****@*****.**',
                'password': '******',
                'new_password': '******',
                'reset_token': 'hashhh'
            },
            params=None,
            verify=mock.ANY,
        )
Exemple #20
0
    def test_resource_update_auth_token(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com',
                             auth_token='weirdhashhere')
        client.Event.update('object_id',
                            email='*****@*****.**',
                            name='New Hamster')

        requests_patched.patch.assert_called_once_with(
            'http://api.dlogr.com/api/events/object_id',
            auth=None,
            headers={
                'user-agent': mock.ANY,
                'Authorization': 'Token weirdhashhere'
            },
            data={
                'email': '*****@*****.**',
                'name': 'New Hamster'
            },
            params=None,
            verify=mock.ANY,
        )
Exemple #21
0
    def test_resource_create_auth_token(self, requests_patched):
        client = DlogrClient('http://api.dlogr.com',
                             auth_token='weirdhashhere')
        client.Event.create(email='*****@*****.**',
                            password='******',
                            name='Hamster')

        requests_patched.post.assert_called_once_with(
            'http://api.dlogr.com/api/events',
            auth=None,
            headers={
                'user-agent': mock.ANY,
                'Authorization': 'Token weirdhashhere'
            },
            data={
                'email': '*****@*****.**',
                'password': '******',
                'name': 'Hamster'
            },
            params=None,
            verify=mock.ANY,
        )
Exemple #22
0
def get_dlogr_client(*args, **kwargs):
    ''' Centralized for testing/mocking purposes. '''
    return DlogrClient(settings.DLOGR_BASE_API_URL, *args, **kwargs)