def test_describe_blob(self):
        http_session = MagicMock()
        http_session.get = MagicMock()

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

        response.status_code = 200
        response.content = """
        {
            "meta": {
                "dummy1": {
                    "blobRef": "dummy1"
                },
                "dummy2": {
                    "blobRef": "dummy2"
                }
            }
        }
        """

        searcher = SearchClient(
            http_session=http_session,
            base_url="http://example.com/s/",
        )

        result = searcher.describe_blob("dummy1")

        http_session.get.assert_called_with(
            'http://example.com/s/camli/search/describe',
            params={
                'blobref': 'dummy1',
            }
        )

        self.assertEqual(
            type(result),
            BlobDescription,
        )

        self.assertEqual(
            result.raw_dict,
            {
                "blobRef": "dummy1",
            }
        )
        self.assertEqual(
            result.other_raw_dicts,
            {
                "dummy1": {
                    "blobRef": "dummy1",
                },
                "dummy2": {
                    "blobRef": "dummy2",
                },
            }
        )
Example #2
0
    def test_describe_blob(self):
        http_session = MagicMock()
        http_session.get = MagicMock()

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

        response.status_code = 200
        response.content = """
        {
            "meta": {
                "dummy1": {
                    "blobRef": "dummy1"
                },
                "dummy2": {
                    "blobRef": "dummy2"
                }
            }
        }
        """

        searcher = SearchClient(
            http_session=http_session,
            base_url="http://example.com/s/",
        )

        result = searcher.describe_blob("dummy1")

        http_session.get.assert_called_with(
            'http://example.com/s/camli/search/describe',
            params={
                'blobref': 'dummy1',
            })

        self.assertEqual(
            type(result),
            BlobDescription,
        )

        self.assertEqual(result.raw_dict, {
            "blobRef": "dummy1",
        })
        self.assertEqual(result.other_raw_dicts, {
            "dummy1": {
                "blobRef": "dummy1",
            },
            "dummy2": {
                "blobRef": "dummy2",
            },
        })
Example #3
0
    def test_get_claims_for_permanode(self):
        http_session = MagicMock()
        http_session.get = MagicMock()

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

        response.status_code = 200
        response.content = """
        {
            "claims": [
                {
                    "dummy": 1
                },
                {
                    "dummy": 2
                }
            ]
        }
        """

        searcher = SearchClient(
            http_session=http_session,
            base_url="http://example.com/s/",
        )

        claims = searcher.get_claims_for_permanode('dummy1')

        http_session.get.assert_called_with(
            'http://example.com/s/camli/search/claims',
            params={
                "permanode": "dummy1",
            },
        )

        self.assertEqual(
            [type(claim) for claim in claims],
            [ClaimMeta, ClaimMeta],
        )
        self.assertEqual(
            [claim.raw_dict["dummy"] for claim in claims],
            [1, 2],
        )
    def test_get_claims_for_permanode(self):
        http_session = MagicMock()
        http_session.get = MagicMock()

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

        response.status_code = 200
        response.content = """
        {
            "claims": [
                {
                    "dummy": 1
                },
                {
                    "dummy": 2
                }
            ]
        }
        """

        searcher = SearchClient(
            http_session=http_session,
            base_url="http://example.com/s/",
        )

        claims = searcher.get_claims_for_permanode('dummy1')

        http_session.get.assert_called_with(
            'http://example.com/s/camli/search/claims',
            params={
                "permanode": "dummy1",
            },
        )

        self.assertEqual(
            [type(claim) for claim in claims],
            [ClaimMeta, ClaimMeta],
        )
        self.assertEqual(
            [claim.raw_dict["dummy"] for claim in claims],
            [1, 2],
        )
Example #5
0
    def test_query(self):
        http_session = MagicMock()
        http_session.post = MagicMock()

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

        response.status_code = 200
        response.content = """
        {
            "blobs": [
                {
                    "blob": "dummy-1"
                },
                {
                    "blob": "dummy-2"
                }
            ]
        }
        """

        searcher = SearchClient(
            http_session=http_session,
            base_url="http://example.com/s/",
        )

        results = searcher.query('dummyquery')

        http_session.post.assert_called_with(
            'http://example.com/s/camli/search/query',
            data='{"expression": "dummyquery"}',
        )

        self.assertEqual(
            [type(result) for result in results],
            [SearchResult, SearchResult],
        )
        self.assertEqual(
            [result.blobref for result in results],
            ["dummy-1", "dummy-2"],
        )
    def test_query(self):
        http_session = MagicMock()
        http_session.post = MagicMock()

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

        response.status_code = 200
        response.content = """
        {
            "blobs": [
                {
                    "blob": "dummy-1"
                },
                {
                    "blob": "dummy-2"
                }
            ]
        }
        """

        searcher = SearchClient(
            http_session=http_session,
            base_url="http://example.com/s/",
        )

        results = searcher.query('dummyquery')

        http_session.post.assert_called_with(
            'http://example.com/s/camli/search/query',
            data='{"expression": "dummyquery"}',
        )

        self.assertEqual(
            [type(result) for result in results],
            [SearchResult, SearchResult],
        )
        self.assertEqual(
            [result.blobref for result in results],
            ["dummy-1", "dummy-2"],
        )
Example #7
0
    def __init__(
        self,
        http_session=None,
        blob_root=None,
        search_root=None,
        sign_root=None,
    ):
        self.http_session = http_session
        self.blob_root = blob_root
        self.search_root = search_root
        self.sign_root = sign_root

        from camlistore.blobclient import BlobClient
        self.blobs = BlobClient(
            http_session=http_session,
            base_url=blob_root,
        )

        from camlistore.searchclient import SearchClient
        self.searcher = SearchClient(
            http_session=http_session,
            base_url=search_root,
        )
Example #8
0
    def __init__(self,
                 http_session=None,
                 blob_root=None,
                 search_root=None,
                 sign_root=None,
                 uploadhelper_root=None):

        self.http_session = http_session
        self.blob_root = blob_root
        self.search_root = search_root
        self.sign_root = sign_root
        self.uploadhelper_root = uploadhelper_root

        from camlistore.blobclient import BlobClient
        self.blobs = BlobClient(
            http_session=http_session,
            base_url=blob_root,
        )

        from camlistore.searchclient import SearchClient
        self.searcher = SearchClient(
            http_session=http_session,
            base_url=search_root,
        )

        if sign_root:
            from camlistore.signing import Signer
            self.signer = Signer(http_session=http_session, base_url=sign_root)
        else:
            self.signer = None

        if uploadhelper_root:
            from camlistore.uploadhelper import UploadHelper
            self.uploadhelper = UploadHelper(http_session=http_session,
                                             base_url=uploadhelper_root)
        else:
            self.uploadhelper_root = None