Ejemplo n.º 1
0
    def test_can_update_existing_vertex(self):
        vid = '1111'
        d = {
            GIZMO_ID: vid,
            'some_field': 'mark',
        }
        v = self.mapper.create(d, TestVertex)
        v['some_field'] = 'xxxx'

        self.mapper.save(v)._build_queries()

        sent_params = copy.deepcopy(self.mapper.params)
        values = ['some_field', 'xxxx', 'vertex', entity_name(v), GIZMO_ENTITY,
            GIZMO_TYPE]
        queries = self.mapper.queries

        self.assertEqual(2, len(queries))

        params = self.mapper.params
        return_var = self.mapper.get_entity_variable(v)
        expected = build_update_query(entity=v, values=values,
            params=params, mapper=self.mapper, return_var=return_var)

        self.assertEqual(expected, queries[0])

        # +2 for id and alias
        self.assertEqual(len(values) + 2, len(params))
Ejemplo n.º 2
0
    def test_can_save_vertex_with_two_fields_value_two_props_on_one_field(self):
        v = TestVertex()
        ik = 'some_field' + str(random())
        iv = 'some_value' + str(random())
        ik2 = '2__some_field' + str(random())
        iv2 = '2some_value' + str(random())
        pk = 'prop_key' + str(random())
        pv = 'prop_value' + str(random())
        pk2 = '2prop_key' + str(random())
        pv2 = '2prop_value' + str(random())
        v[ik] = iv
        v[ik][iv].properties[pk] = pv
        v[ik][iv].properties[pk2] = pv2
        v[ik2] = iv2

        self.query.save(v)

        values = [ik, iv, iv2, ik2, 'vertex', entity_name(v), str(v),
            GIZMO_ENTITY, GIZMO_TYPE, pk2, pv2, pk, pv]
        value_properties = {
            iv: {
                pk: pv,
                pk2: pv2,
            },
        }
        queries = self.query.queries

        self.assertEqual(1, len(queries))

        entry = queries[0]
        params = entry['params']
        expected = build_vertex_create_query(entity=v, values=values, params=params,
            value_properties=value_properties, mapper=self.mapper)
        self.assertEqual(expected, entry['script'])
        self.assertEqual(len(values), len(params))
Ejemplo n.º 3
0
    def test_can_save_vertex_with_one_field_value_two_properties(self):
        v = TestVertex()
        ik = 'some_field' + str(random())
        iv = 'some_value' + str(random())
        pk = 'prop_key' + str(random())
        pv = 'prop_value' + str(random())
        pk2 = 'prop2_key' + str(random())
        pv2 = 'prop2_value' + str(random())
        v[ik] = iv
        v[ik][iv].properties[pk] = pv
        v[ik][iv].properties[pk2] = pv2

        self.query.save(v)

        values = [ik, iv, 'vertex', entity_name(v), str(v), GIZMO_ENTITY, GIZMO_TYPE]
        value_properties = {
            iv: {
                pk: pv,
                pk2: pv2,
            }
        }
        queries = self.query.queries

        self.assertEqual(1, len(queries))

        entry = queries[0]
        params = entry['params']
        expected = build_vertex_create_query(entity=v, values=values, params=params,
            value_properties=value_properties, mapper=self.mapper)

        self.assertEqual(expected, entry['script'])

        # 4 is the number of params added because of the two props defined
        self.assertEqual(len(values) + 4, len(params))
Ejemplo n.º 4
0
    def test_can_assure_saving_vertex_mulitple_times_only_crud_once(self):
        d = {'some_field': str(random())}
        v = self.mapper.create(d, TestVertex)

        self.mapper.save(v).save(v)._build_queries()
        params = copy.deepcopy(self.mapper.params)
        return_var = self.mapper.get_entity_variable(v)
        values = ['some_field', d['some_field'], 'vertex', entity_name(v),
            GIZMO_ENTITY, GIZMO_TYPE, str(v)]
        expected = build_vertex_create_query(entity=v, values=values,
            params=params, mapper=self.mapper, return_var=return_var)
        self.assertEqual(3, len(self.mapper.queries))
        self.assertIn(expected, self.mapper.queries)
Ejemplo n.º 5
0
    def test_can_queue_save_vertex_with_two_params_query(self):
        d = {
            'some_field': 'mark',
        }
        v = self.mapper.create(d, TestVertex)

        self.mapper.save(v)._build_queries()

        params = copy.deepcopy(self.mapper.params)
        values = ['some_field', 'mark', 'vertex', entity_name(v), GIZMO_ENTITY,
            GIZMO_TYPE, str(v)]
        return_var = self.mapper.get_entity_variable(v)
        expected = build_vertex_create_query(entity=v, values=values,
            params=params, mapper=self.mapper, return_var=return_var)

        self.assertEqual(expected, self.mapper.queries[0])
        self.assertEqual(len(values), len(params))
Ejemplo n.º 6
0
    def test_can_save_vertex_with_no_field_values(self):
        v = TestVertex()

        self.query.save(v)

        queries = self.query.queries
        values = ['vertex', entity_name(v), str(v), GIZMO_ENTITY, GIZMO_TYPE]

        self.assertEqual(1, len(queries))

        entry = queries[0]
        params = entry['params']
        expected = build_vertex_create_query(entity=v, values=values,
            params=params, mapper=self.mapper)

        self.assertEqual(expected, entry['script'])
        self.assertEqual(len(values), len(params))
Ejemplo n.º 7
0
    def test_can_save_edge_with_ends_being_ids(self):
        d = {
            'outV': 10,
            'inV': 99,
        }
        e = TestEdge(data=d)

        self.query.save(e)

        values = [str(e), e.outV, e.inV,
            entity_name(e)]
        entry = self.query.queries[0]
        expected = build_edge_create_query(entity=e, out_v=e.outV,
            in_v=e.inV, values=values, mapper=self.mapper,
            params=entry['params'])

        self.assertEqual(expected, entry['script'])
        self.assertEqual(len(values) + 1, len(entry['params']))
Ejemplo n.º 8
0
    def test_can_save_edge_one_end_being_new_entity_other_being_id(self):
        v = TestVertex()
        d = {
            'outV': 15,
            'inV': v,
        }
        e = TestEdge(data=d)

        self.query.save(e)

        in_v = 'var:{}'.format(self.mapper.get_entity_variable(v))
        values = [GIZMO_LABEL[0], str(e), e.outV,
            entity_name(e)]
        entry = self.query.queries[0]
        expected = build_edge_create_query(entity=e, out_v=e.outV,
            in_v=in_v, values=values, mapper=self.mapper,
            params=entry['params'])

        self.assertEqual(expected, entry['script'])
        self.assertEqual(len(values), len(entry['params']))
Ejemplo n.º 9
0
    def test_can_save_vertex_with_one_field_value(self):
        v = TestVertex()
        ik = '__some_field' + str(random())
        iv = 'some_value' + str(random())
        v[ik] = iv

        self.query.save(v)

        values = [ik, iv, 'vertex', entity_name(v), str(v), GIZMO_ENTITY,
            GIZMO_TYPE]
        queries = self.query.queries

        self.assertEqual(1, len(queries))

        entry = queries[0]
        params = entry['params']
        expected = build_vertex_create_query(entity=v, values=values,
            params=params, mapper=self.mapper)
        self.assertEqual(expected, entry['script'])
        self.assertEqual(len(values), len(params))
Ejemplo n.º 10
0
    def test_can_update_vertex_with_no_field_values(self):
        _id = str(random())
        data = {GIZMO_ID: _id}
        v = TestVertex(data)

        self.query.save(v)

        queries = self.query.queries
        values = ['vertex', entity_name(v), GIZMO_ENTITY, GIZMO_ID]

        self.assertEqual(1, len(queries))

        entry = queries[0]
        params = entry['params']
        expected = build_update_query(entity=v, values=values, mapper=self.mapper,
            params=params)

        self.assertEqual(expected, entry['script'])

        # +1 because we cannot add the _id var to the values list and alias
        self.assertEqual(len(values) + 2, len(params))
Ejemplo n.º 11
0
    def test_can_update_vertex_with_two_fields_after_deleting_one(self):
        _id = str(random())
        ik = 'key' + str(random())
        iv = 'val' + str(random())
        ik2 = '2key' + str(random())
        iv2 = '2val' + str(random())
        data = {GIZMO_ID: _id, ik: iv, ik2: iv2}
        v = TestVertex(data)

        del v[ik2]

        values = [ik, iv, ik2, iv2, GIZMO_ENTITY, entity_name(v), GIZMO_TYPE, 'vertex']
        deleted = [ik2, ]

        self.query.save(v)
        queries = self.query.queries
        entry = queries[0]
        params = entry['params']
        expected = build_update_query(entity=v, values=values, mapper=self.mapper,
            params=params, deleted=deleted)

        self.assertEqual(expected, entry['script'])
Ejemplo n.º 12
0
    def test_can_update_vertext_with_one_field_and_two_properties(self):
        # we only need one test bc properties are tested for adding vertex
        _id = str(random())
        data = {GIZMO_ID: _id}
        v = TestVertex(data)
        ik = 'some_field' + str(random())
        iv = 'some_value' + str(random())
        pk = 'prop_key' + str(random())
        pv = 'prop_value' + str(random())
        pk2 = '2prop_key' + str(random())
        pv2 = '2prop_value' + str(random())
        v[ik] = iv
        v[ik][iv].properties[pk] = pv
        v[ik][iv].properties[pk2] = pv2

        self.query.save(v)

        values = [ik, iv, 'vertex', entity_name(v), GIZMO_ENTITY, GIZMO_ID,
            pk2, pv2, pk, pv]
        value_properties = {
            iv: {
                pk: pv,
                pk2: pv2,
            },
        }

        queries = self.query.queries

        self.assertEqual(1, len(queries))

        entry = queries[0]
        params = entry['params']
        expected = build_update_query(entity=v, values=values, mapper=self.mapper,
            params=params, value_properties=value_properties)
        self.assertEqual(expected, entry['script'])

        # +1 because we cannot add the _id var to the values list and alias
        self.assertEqual(len(values) + 2, len(params))