Ejemplo n.º 1
0
    def test_json_loads_dumps(self):
        resource = {"a": 1, "b": [1, 2]}

        result = json.dumps(json.loads("""{"a": 1, "b": [1, 2]}"""))
        assert_equal(json.dumps(resource), result)

        assert_equal(json.loads(result), resource)
Ejemplo n.º 2
0
    def test_json_loads_dumps(self):
        resource = {"a": 1, "b": [1, 2]}

        result = json.dumps(json.loads("""{"a": 1, "b": [1, 2]}"""))
        assert_equal(
            json.dumps(resource),
            result
        )

        assert_equal(
            json.loads(result),
            resource
        )
Ejemplo n.º 3
0
    def list_response_mock(self):
        self.list_ids = {
            "0": {
                "fields": [
                    "_id"
                ],
                "id": 0,
                "type": "primary"
            }
        }

        data = {
            "code": 200,
            "indexes": [
                {
                    "fields": ["_id"],
                    "id": 0,
                    "type": "primary"
                }
            ],
            "error": False,
            "identifiers": self.list_ids
        }

        return self.response_mock(
            status_code=200,
            text=json.dumps(data),
            method="get"
        )
Ejemplo n.º 4
0
    def test_rename(self):
        test_data = {"name": "test1"}
        test_args = {"data": json.dumps(test_data)}

        self.c.rename(name="test1")

        assert_equal(Client.post.call_args[1], test_args)
Ejemplo n.º 5
0
    def list_response_mock(self):
        self.list_ids = {
            "0": {
                "fields": [
                    "_id"
                ],
                "id": 0,
                "type": "primary"
            }
        }

        data = {
            "code": 200,
            "indexes": [
                {
                    "fields": ["_id"],
                    "id": 0,
                    "type": "primary"
                }
            ],
            "error": False,
            "identifiers": self.list_ids
        }

        return self.response_mock(
            status_code=200,
            text=json.dumps(data),
            method="get"
        )
Ejemplo n.º 6
0
    def test_save(self):
        doc = self.create_document({})

        patcher = self.response_mock(
            status_code=201,
            text=json.dumps(dict(
                _rev=30967599,
                _id=1,
                error=False,
                code=201
            )),
            method="put"
        )

        patcher.start()

        test_data = {
            "name": "sample"
        }
        updated = doc.update(test_data)

        assert_equal(updated.rev, 30967599)

        # call manuall save() method
        doc = self.create_document({})

        doc.update(test_data, save=False)
        doc.save()

        assert_equal(doc.rev, 30967599)
        patcher.stop()
Ejemplo n.º 7
0
    def test_rename(self):
        test_data = {"name": "test1"}
        test_args = {"data": json.dumps(test_data)}

        self.c.rename(name="test1")

        assert_equal(Client.post.call_args[1], test_args)
Ejemplo n.º 8
0
 def notfound_response_mock(self):
     return self.response_mock(
         status_code=404,
         text=json.dumps(dict(
             error=True,
             code=404
         )),
         method="get"
     )
Ejemplo n.º 9
0
    def test_create_edges(self):
        self.c_e.create_edges()

        test_data = {
            "name": "test_edges", "waitForSync": False,
            "type": Collections.COLLECTION_EDGES}
        test_args = {"data": json.dumps(test_data)}

        assert_true(Client.post.called)
        assert_equal(Client.post.call_args[1], test_args)
Ejemplo n.º 10
0
 def delete_edge_response_mock(self):
     return self.response_mock(status_code=204,
                               text=json.dumps(
                                   dict(_from="7848004/9289796",
                                        _to="7848004/9355332",
                                        _rev=30967598,
                                        _id=1,
                                        error=False,
                                        code=204)),
                               method="delete")
Ejemplo n.º 11
0
    def test_properties(self):
        self.c.properties(waitForSync=True)

        test_data = {"waitForSync": True}
        test_args = {"data": json.dumps(test_data)}

        self.c.properties(waitForSync=True)
        assert_equal(Client.put.call_args[1], test_args)

        self.c.properties()
        assert_equal(Client.get.call_args[1], {})
Ejemplo n.º 12
0
    def test_properties(self):
        self.c.properties(waitForSync=True)

        test_data = {"waitForSync": True}
        test_args = {"data": json.dumps(test_data)}

        self.c.properties(waitForSync=True)
        assert_equal(Client.put.call_args[1], test_args)

        self.c.properties()
        assert_equal(Client.get.call_args[1], {})
Ejemplo n.º 13
0
 def delete_response_mock(self):
     return self.response_mock(
         status_code=202,
         text=json.dumps(dict(
             _rev="30967598",
             _id="1/30967598",
             error=False,
             code=204
         )),
         method="delete"
     )
    def test_create(self):
        self.c.create()
        url = "{0}{1}".format(
            self.conn.url,
            self.c.CREATE_COLLECTION_PATH)

        test_data = {"name": "test", "waitForSync": False}
        test_args = {"data": json.dumps(test_data)}

        assert_true(Client.post.called)
        assert_equal(Client.post.call_args[0][0], url)
        assert_equal(Client.post.call_args[1], test_args)
    def test_rename(self):
        test_data = {"name": "test1"}
        test_args = {"data": json.dumps(test_data)}

        url = "{0}{1}".format(
            self.conn.url,
            self.c.RENAME_COLLECTION_PATH.format(self.c.name))

        self.c.rename(name="test1")

        assert_equal(Client.post.call_args[0][0], url)
        assert_equal(Client.post.call_args[1], test_args)
Ejemplo n.º 16
0
    def delete_response_mock(self):
        return self.response_mock(
            status_code=200,

            text=json.dumps(dict(
                _rev=30967598,
                _id=1,
                error=False,
                code=200
            )),
            method="delete"
        )
Ejemplo n.º 17
0
    def delete_response_mock(self):
        return self.response_mock(
            status_code=200,

            text=json.dumps(dict(
                _rev=30967598,
                _id=1,
                error=False,
                code=200
            )),
            method="delete"
        )
Ejemplo n.º 18
0
    def test_create_edges(self):
        self.c_e.create_edges()

        test_data = {
            "name": "test_edges",
            "waitForSync": False,
            "type": Collections.COLLECTION_EDGES
        }
        test_args = {"data": json.dumps(test_data)}

        assert_true(Client.post.called)
        assert_equal(Client.post.call_args[1], test_args)
Ejemplo n.º 19
0
 def delete_edge_response_mock(self):
     return self.response_mock(
         status_code=204,
         text=json.dumps(dict(
             _from="7848004/9289796",
             _to="7848004/9355332",
             _rev=30967598,
             _id=1,
             error=False,
             code=204
         )),
         method="delete"
     )
Ejemplo n.º 20
0
    def create_edge_response_mock(self, body=None):
        body = body if body is not None else {}
        defaults = dict(_from="7848004/9289796",
                        _to="7848004/9355332",
                        _rev=30967598,
                        _id="7848004/9683012",
                        error=False,
                        code=201)

        defaults.update(body)

        patcher = self.response_mock(status_code=201,
                                     text=json.dumps(defaults),
                                     method="post")

        return patcher
Ejemplo n.º 21
0
    def test_delete_notfound(self):
        doc = self.create_document({})

        patcher = self.response_mock(
            status_code=404,
            text=json.dumps(dict(
                error=True,
                code=404
            )),
            method="delete")

        patcher.start()
        assert_equal(
            doc.delete(),
            False
        )
        patcher.stop()
Ejemplo n.º 22
0
    def create_response_mock(self, _id=None, body=None):
        body = body if body is not None else {}
        defaults = dict(
            _rev="30967598",
            _id="1/30967598",
            error=False,
            code=201
        )

        defaults.update(body)

        patcher = self.response_mock(
            status_code=201,
            text=json.dumps(defaults),
            method="post"
        )

        return patcher
    def test_properties(self):
        self.c.properties(waitForSync=True)

        url = "{0}{1}".format(
            self.conn.url,
            self.c.PROPERTIES_COLLECTION_PATH.format(self.c.name)
        )

        assert_equal(Client.put.call_args[0][0], url)

        test_data = {"waitForSync": True}
        test_args = {"data": json.dumps(test_data)}

        self.c.properties(waitForSync=True)
        assert_equal(Client.put.call_args[0][0], url)
        assert_equal(Client.put.call_args[1], test_args)

        self.c.properties()
        assert_equal(Client.get.call_args[1], {})
Ejemplo n.º 24
0
    def create_edge_response_mock(self, body=None):
        body = body if body is not None else {}
        defaults = dict(
            _from="7848004/9289796",
            _to="7848004/9355332",
            _rev=30967598,
            _id="7848004/9683012",
            error=False,
            code=201
        )

        defaults.update(body)

        patcher = self.response_mock(
            status_code=201,
            text=json.dumps(defaults),
            method="post"
        )

        return patcher
Ejemplo n.º 25
0
    def create_response_mock(self, body=None):
        body = body if body is not None else {}
        defaults = {
            "code": 201,
            "geoJson": False,
            "fields": [
                "b"
            ],
            "id": 96609552,
            "type": "geo",
            "isNewlyCreated": True,
            "error": False
        }

        defaults.update(body)

        patcher = self.response_mock(
            status_code=201,
            text=json.dumps(defaults),
            method="post"
        )

        return patcher
Ejemplo n.º 26
0
    def create_response_mock(self, body=None):
        body = body if body is not None else {}
        defaults = {
            "code": 201,
            "geoJson": False,
            "fields": [
                "b"
            ],
            "id": 96609552,
            "type": "geo",
            "isNewlyCreated": True,
            "error": False
        }

        defaults.update(body)

        patcher = self.response_mock(
            status_code=201,
            text=json.dumps(defaults),
            method="post"
        )

        return patcher