コード例 #1
0
    def test_get_success(self):
        http_session = MagicMock()
        http_session.get = MagicMock()
        response = MagicMock()
        http_session.get.return_value = response

        response.status_code = 200
        response.content = b'dummy blob'

        blobs = BlobClient(
            http_session,
            'http://example.com/blerbs/',
        )
        result = blobs.get('sha1-7928f34bd3263b86e67d11efff30d67fe7f3d176')

        http_session.get.assert_called_with(
            "http://example.com/blerbs/camli/"
            "sha1-7928f34bd3263b86e67d11efff30d67fe7f3d176")
        self.assertEqual(
            type(result),
            Blob,
        )
        self.assertEqual(
            result.data,
            b'dummy blob',
        )
コード例 #2
0
    def test_get_not_found(self):
        http_session = MagicMock()
        http_session.get = MagicMock()
        response = MagicMock()
        http_session.get.return_value = response

        response.status_code = 404
        response.content = 'not found'

        blobs = BlobClient(
            http_session,
            'http://example.com/blerbs/',
        )
        from camlistore.exceptions import NotFoundError
        self.assertRaises(
            NotFoundError,
            lambda: blobs.get('dummy-blobref'),
        )
        http_session.get.assert_called_with(
            "http://example.com/blerbs/camli/dummy-blobref")
コード例 #3
0
    def test_get_hash_mismatch(self):
        from camlistore.exceptions import HashMismatchError

        http_session = MagicMock()
        http_session.get = MagicMock()
        response = MagicMock()
        http_session.get.return_value = response

        response.status_code = 200
        response.content = b'dummy blob'

        blobs = BlobClient(
            http_session,
            'http://example.com/blerbs/',
        )
        self.assertRaises(
            HashMismatchError,
            lambda: blobs.get('sha1-dummyblobref'),
        )
        http_session.get.assert_called_with(
            "http://example.com/blerbs/camli/sha1-dummyblobref")