Beispiel #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'})
Beispiel #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'})
Beispiel #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')
Beispiel #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')
Beispiel #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")
Beispiel #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")
Beispiel #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.")
Beispiel #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.")