Exemplo n.º 1
0
 def test_delete_user_should_fail_if_user_id_too_long(self):
     pn_client = PushNotifications(
         'INSTANCE_ID',
         'SECRET_KEY'
     )
     with self.assertRaises(ValueError) as e:
         pn_client.delete_user('A'*165)
     self.assertIn('longer than the maximum of 164 chars', str(e.exception))
Exemplo n.º 2
0
 def test_delete_user_should_fail_if_user_id_not_a_string(self):
     pn_client = PushNotifications(
         'INSTANCE_ID',
         'SECRET_KEY'
     )
     with self.assertRaises(TypeError) as e:
         pn_client.delete_user(False)
     self.assertIn('user_id must be a string', str(e.exception))
Exemplo n.º 3
0
 def test_delete_user_should_not_error_on_not_json_success(self):
     pn_client = PushNotifications(
         'INSTANCE_ID',
         'SECRET_KEY'
     )
     with requests_mock.Mocker() as http_mock:
         http_mock.register_uri(
             requests_mock.ANY,
             requests_mock.ANY,
             status_code=200,
             text='<notjson></notjson>',
         )
         pn_client.delete_user('alice')
Exemplo n.º 4
0
 def test_delete_user_should_error_correctly_if_error_not_json(self):
     pn_client = PushNotifications(
         'INSTANCE_ID',
         'SECRET_KEY'
     )
     with requests_mock.Mocker() as http_mock:
         http_mock.register_uri(
             requests_mock.ANY,
             requests_mock.ANY,
             status_code=500,
             text='<notjson></notjson>',
         )
         with self.assertRaises(PusherServerError) as e:
             pn_client.delete_user('user-0001')
         self.assertIn('Unknown error: no description', str(e.exception))
Exemplo n.º 5
0
 def test_delete_user_should_raise_on_http_404_error(self):
     pn_client = PushNotifications(
         'INSTANCE_ID',
         'SECRET_KEY'
     )
     with requests_mock.Mocker() as http_mock:
         http_mock.register_uri(
             requests_mock.ANY,
             requests_mock.ANY,
             status_code=404,
             json={'error': 'Instance not found', 'description': 'blah'},
         )
         with self.assertRaises(PusherMissingInstanceError) as e:
             pn_client.delete_user('user-0001')
         self.assertIn('Instance not found: blah', str(e.exception))
Exemplo n.º 6
0
 def test_delete_user_should_raise_on_http_5xx_error(self):
     pn_client = PushNotifications(
         'INSTANCE_ID',
         'SECRET_KEY'
     )
     with requests_mock.Mocker() as http_mock:
         http_mock.register_uri(
             requests_mock.ANY,
             requests_mock.ANY,
             status_code=500,
             json={'error': 'Server error', 'description': 'blah'},
         )
         with self.assertRaises(PusherServerError) as e:
             pn_client.delete_user('user-0001')
         self.assertIn('Server error: blah', str(e.exception))
Exemplo n.º 7
0
    def test_delete_user_should_make_correct_http_request(self):
        pn_client = PushNotifications(
            'INSTANCE_ID',
            'SECRET_KEY'
        )
        with requests_mock.Mocker() as http_mock:
            http_mock.register_uri(
                requests_mock.ANY,
                requests_mock.ANY,
                status_code=200,
                json='',
            )
            pn_client.delete_user('alice')
            req = http_mock.request_history[0]

        method = req.method
        path = req.path
        headers = dict(req._request.headers.lower_items())

        self.assertEqual(
            method,
            'DELETE',
        )
        self.assertEqual(
            path,
            '/customer_api/v1/instances/instance_id/users/alice',
        )
        self.assertDictEqual(
            headers,
            {
                'content-length': '0',
                'authorization': 'Bearer SECRET_KEY',
                'x-pusher-library': 'pusher-push-notifications-python 2.0.0',
                'host': 'instance_id.pushnotifications.pusher.com',
            },
        )