Ejemplo n.º 1
0
    def test_point_serialization(self):
        latitude = 80
        longitude = 100

        point = Point(latitude, longitude)

        writer = JanusGraphSONWriter().build()

        graphSON = writer.writeObject(point)

        expectedJSON = dict()
        expectedJSON["@type"] = "janusgraph:Geoshape"
        expectedJSON["@value"] = dict()
        expectedJSON["@value"]["type"] = "Point"
        expectedJSON["@value"]["coordinates"] = list()
        expectedJSON["@value"]["coordinates"].append({
            "@type": "g:Double",
            "@value": float(longitude)
        })
        expectedJSON["@value"]["coordinates"].append({
            "@type": "g:Double",
            "@value": float(latitude)
        })

        actualGson = json.loads(graphSON)

        self.assertEqual(actualGson, expectedJSON)
class TestCircleSerialization(unittest.TestCase):
    def setUp(self):
        self.latitude = 80
        self.longitude = 100
        self.radius = 5

        self.circle = Circle(self.longitude, self.latitude, self.radius)

        self.writer = JanusGraphSONWriter().build()
        pass

    def test_circle_serialization(self):
        graphSON = self.writer.writeObject(self.circle)

        expectedJSONStr = "{\"@type\":\"janusgraph:Geoshape\",\"@value\":{\"geometry\":{\"type\":\"Circle\", \
                            \"coordinates\":[{\"@type\":\"g:Double\",\"@value\":" + str(
            self.latitude) + "},\
                            {\"@type\":\"g:Double\",\"@value\":" + str(
                self.longitude) + "}], \"radius\":{\"@type\":\"g:Double\",\
                            \"@value\":" + str(
                    self.radius
                ) + "},\"properties\":{\"radius_units\":\"km\"}}}}"

        actualGson = json.loads(graphSON)
        expectedGson = json.loads(expectedJSONStr)

        self.assertEqual(actualGson, expectedGson)

        pass
Ejemplo n.º 3
0
class TestCircleSerialization(unittest.TestCase):
    def setUp(self):
        self.latitude = 80
        self.longitude = 100

        self.point = Point(self.longitude, self.latitude)

        self.writer = JanusGraphSONWriter().build()
        pass

    def test_point_serialization(self):
        graphSON = self.writer.writeObject(self.point)

        expectedJSONStr = "{\"@type\":\"janusgraph:Geoshape\",\"@value\":{\"type\":\"Point\", \
                            \"coordinates\":[{\"@type\":\"g:Double\",\"@value\":" + str(
            self.latitude) + "},\
                            {\"@type\":\"g:Double\",\"@value\":" + str(
                self.longitude) + "}]}}"

        actualGson = json.loads(graphSON)

        expectedGson = json.loads(expectedJSONStr)

        self.assertEqual(actualGson, expectedGson)

        pass
Ejemplo n.º 4
0
    def test_relationID_serialization(self):
        relationID = "74q-9n4-b2t-cr4"

        edge = RelationIdentifier(relationID)
        writer = JanusGraphSONWriter().build()

        graphSON = writer.writeObject(edge)

        expectedJSON = dict()
        expectedJSON["@type"] = "janusgraph:RelationIdentifier"
        expectedJSON["@value"] = {"relationId": relationID}

        actualJSON = json.loads(graphSON)

        self.assertEqual(expectedJSON, actualJSON)
class TestRelationIdentifierSerializer(unittest.TestCase):
    def setUp(self):
        self.relationID = "74q-9n4-b2t-cr4"
        self.edge = RelationIdentifier(self.relationID)
        self.writer = JanusGraphSONWriter().build()
        pass

    def test_relationID_serialization(self):
        graphSON = self.writer.writeObject(self.edge)

        expectedJSONStr = "{\"@type\":\"janusgraph:RelationIdentifier\",\"@value\": {\"relationId\": \"" + self.relationID + "\"}}"

        expectedJSON = json.loads(expectedJSONStr)
        actualJSON = json.loads(graphSON)

        self.assertEqual(expectedJSON, actualJSON)
        pass
Ejemplo n.º 6
0
    def test_circle_serialization(self):
        latitude = 80
        longitude = 100
        radius = 5

        circle = Circle(latitude, longitude, radius)

        writer = JanusGraphSONWriter().build()

        graphSON = writer.writeObject(circle)

        expectedJSON = dict()
        expectedJSON["@type"] = "janusgraph:Geoshape"
        expectedJSON["@value"] = dict()
        expectedJSON["@value"]["geometry"] = dict()
        expectedJSON["@value"]["geometry"]["type"] = "Circle"
        expectedJSON["@value"]["geometry"]["coordinates"] = list()
        expectedJSON["@value"]["geometry"]["coordinates"].append({
            "@type":
            "g:Double",
            "@value":
            float(longitude)
        })
        expectedJSON["@value"]["geometry"]["coordinates"].append({
            "@type":
            "g:Double",
            "@value":
            float(latitude)
        })
        expectedJSON["@value"]["geometry"]["radius"] = dict()
        expectedJSON["@value"]["geometry"]["radius"]["@type"] = "g:Double"
        expectedJSON["@value"]["geometry"]["radius"]["@value"] = radius
        expectedJSON["@value"]["geometry"]["properties"] = {
            "radius_units": "km"
        }

        actualGson = json.loads(graphSON)

        self.assertEqual(actualGson, expectedJSON)