def test_batch_raises_exception(self): # Make the next call to sess.request raise a 403. exception = KintoException() exception.response = mock.MagicMock() exception.response.status_code = 403 exception.request = mock.sentinel.request self.session.request.side_effect = exception with self.assertRaises(KintoException): with self.client.batch(bucket='moz', collection='test') as batch: batch.create_record(id=1234, data={'foo': 'bar'})
def test_batch_raises_exception(self): # Make the next call to sess.request raise a 403. exception = KintoException() exception.response = mock.MagicMock() exception.response.status_code = 403 exception.request = mock.sentinel.request self.session.request.side_effect = exception with self.assertRaises(KintoException): with self.client.batch(bucket='moz', collection='test') as batch: batch.create_record(id=1234, data={'foo': 'bar'})
def test_unexisting_bucket_raises(self): # Make the next call to sess.request raise a 403. exception = KintoException() exception.response = mock.MagicMock() exception.response.status_code = 403 exception.request = mock.sentinel.request self.session.request.side_effect = exception with self.assertRaises(BucketNotFound) as cm: self.client.get_bucket('test') e = cm.exception self.assertEquals(e.response, exception.response) self.assertEquals(e.request, mock.sentinel.request) self.assertEquals(e.message, 'test')
def test_unexisting_bucket_raises(self): # Make the next call to sess.request raise a 403. exception = KintoException() exception.response = mock.MagicMock() exception.response.status_code = 403 exception.request = mock.sentinel.request self.session.request.side_effect = exception with self.assertRaises(BucketNotFound) as cm: self.client.get_bucket(id='test') e = cm.exception self.assertEqual(e.response, exception.response) self.assertEqual(e.request, mock.sentinel.request) self.assertEqual(e.message, 'test')
def test_http_500_raises_an_error(self): exception = KintoException() exception.response = mock.MagicMock() exception.response.status_code = 400 exception.request = mock.sentinel.request self.session.request.side_effect = exception try: self.client.get_bucket('test') except KintoException as e: self.assertEquals(e.response, exception.response) self.assertEquals(e.request, mock.sentinel.request) else: self.fail("Exception not raised")
def test_http_500_raises_an_error(self): exception = KintoException() exception.response = mock.MagicMock() exception.response.status_code = 400 exception.request = mock.sentinel.request self.session.request.side_effect = exception try: self.client.get_bucket(id='test') except KintoException as e: self.assertEqual(e.response, exception.response) self.assertEqual(e.request, mock.sentinel.request) else: self.fail("Exception not raised")
def test_unauthorized_raises_a_kinto_exception(self): # Make the next call to sess.request raise a 401. exception = KintoException() exception.response = mock.MagicMock() exception.response.status_code = 401 exception.request = mock.sentinel.request self.session.request.side_effect = exception with self.assertRaises(KintoException) as cm: self.client.get_bucket(id='test') e = cm.exception self.assertEqual(e.response, exception.response) self.assertEqual(e.request, mock.sentinel.request) self.assertEqual(e.message, "Unauthorized. Please authenticate or make sure the bucket " "can be read anonymously.")
def test_unauthorized_raises_a_kinto_exception(self): # Make the next call to sess.request raise a 401. exception = KintoException() exception.response = mock.MagicMock() exception.response.status_code = 401 exception.request = mock.sentinel.request self.session.request.side_effect = exception with self.assertRaises(KintoException) as cm: self.client.get_bucket(id='test') e = cm.exception self.assertEquals(e.response, exception.response) self.assertEquals(e.request, mock.sentinel.request) self.assertEquals(e.message, "Unauthorized. Please authenticate or make sure the bucket " "can be read anonymously.")
def test_collection_deletion_can_still_raise_errors(self): error = KintoException("An error occured") with mock.patch.object(self.client.session, "request", side_effect=error): with pytest.raises(KintoException): self.client.delete_collection(id="payments", bucket="mozilla", if_exists=True)
def test_group_deletion_can_still_raise_errors(self): error = KintoException("An error occured") with mock.patch.object(self.client.session, 'request', side_effect=error): with pytest.raises(KintoException): self.client.delete_group(id='payments', bucket='mozilla', if_exists=True)
def setUp(self): request = mock.MagicMock() request.method = "PUT" request.path_url = "/pim" response = mock.MagicMock() response.status_code = 400 self.exc = KintoException("Failure") self.exc.request = request self.exc.response = response
def test_assert_message_is_rendered_in_representation(self): exc = KintoException("Failure") self.assertIn("KintoException('Failure'", repr(exc))
def test_assert_message_is_rendered_in_message(self): exc = KintoException("Failure") self.assertIn("Failure", exc.message)
def test_assert_message_is_rendered_in_string(self): exc = KintoException("Failure") self.assertIn("Failure", str(exc))