Esempio n. 1
0
    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'})
Esempio n. 2
0
    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'})
Esempio n. 3
0
    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')
Esempio n. 4
0
    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')
Esempio n. 5
0
    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")
Esempio n. 6
0
    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")
Esempio n. 7
0
    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.")
Esempio n. 8
0
    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.")
Esempio n. 9
0
 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)
Esempio n. 10
0
 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)
Esempio n. 11
0
    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
Esempio n. 12
0
 def test_assert_message_is_rendered_in_representation(self):
     exc = KintoException("Failure")
     self.assertIn("KintoException('Failure'", repr(exc))
Esempio n. 13
0
 def test_assert_message_is_rendered_in_message(self):
     exc = KintoException("Failure")
     self.assertIn("Failure", exc.message)
Esempio n. 14
0
 def test_assert_message_is_rendered_in_string(self):
     exc = KintoException("Failure")
     self.assertIn("Failure", str(exc))