예제 #1
0
 def test_all_method_invalid_length(self):
     e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)
     e2 = TestEdgeModel.create(self.v1, self.v2, test_val=4)
     from mogwai.exceptions import MogwaiQueryError
     with self.assertRaises(MogwaiQueryError):
         TestEdgeModel.all([e1.id, e2.id, 'invalid'])
     e1.delete()
     e2.delete()
예제 #2
0
 def test_validation_error(self):
     from mogwai.exceptions import ValidationError
     with self.assertRaises(ValidationError):
         e1 = TestEdgeModel.create(self.v1, None, test_val=3)
     with self.assertRaises(ValidationError):
         e1 = TestEdgeModel.create(None, self.v2, test_val=3)
     with self.assertRaises(ValidationError):
         e1 = TestEdgeModel.create(None, None, test_val=3)
예제 #3
0
 def test_validation_error(self):
     from mogwai.exceptions import ValidationError
     with self.assertRaises(ValidationError):
         e1 = TestEdgeModel.create(self.v1, None, test_val=3)
     with self.assertRaises(ValidationError):
         e1 = TestEdgeModel.create(None, self.v2, test_val=3)
     with self.assertRaises(ValidationError):
         e1 = TestEdgeModel.create(None, None, test_val=3)
예제 #4
0
 def test_all_method_invalid_length(self):
     e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)
     e2 = TestEdgeModel.create(self.v1, self.v2, test_val=4)
     from mogwai.exceptions import MogwaiQueryError
     with self.assertRaises(MogwaiQueryError):
         TestEdgeModel.all([e1.id, e2.id, 'invalid'])
     e1.delete()
     e2.delete()
예제 #5
0
 def test_all_method_for_known_ids(self):
     e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)
     e2 = TestEdgeModel.create(self.v1, self.v2, test_val=4)
     results = TestEdgeModel.all([e1.id, e2.id])
     self.assertEqual(len(results), 2)
     for result in results:
         self.assertIsInstance(result, TestEdgeModel)
         self.assertIn(result, [e1, e2])
     e1.delete()
     e2.delete()
예제 #6
0
 def test_all_method_for_known_ids(self):
     e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)
     e2 = TestEdgeModel.create(self.v1, self.v2, test_val=4)
     results = TestEdgeModel.all([e1.id, e2.id])
     self.assertEqual(len(results), 2)
     for result in results:
         self.assertIsInstance(result, TestEdgeModel)
         self.assertIn(result, [e1, e2])
     e1.delete()
     e2.delete()
예제 #7
0
    def test_multiple_label_traversals(self):
        """ Tests that using multiple edges for traversals works """
        e1 = TestEdgeModel.create(self.v1, self.v2)
        e2 = OtherTestEdge.create(self.v1, self.v3)
        e3 = YetAnotherTestEdge.create(self.v1, self.v4)

        self.assertEqual(len(self.v1.outV()), 3)

        self.assertEqual(len(self.v1.outV(TestEdgeModel)), 1)
        self.assertEqual(len(self.v1.outV(OtherTestEdge)), 1)
        self.assertEqual(len(self.v1.outV(YetAnotherTestEdge)), 1)

        out = self.v1.outV(TestEdgeModel, OtherTestEdge)
        self.assertEqual(len(out), 2)
        self.assertIn(self.v2.id, [v.id for v in out])
        self.assertIn(self.v3.id, [v.id for v in out])

        out = self.v1.outV(OtherTestEdge, YetAnotherTestEdge)
        self.assertEqual(len(out), 2)
        self.assertIn(self.v3.id, [v.id for v in out])
        self.assertIn(self.v4.id, [v.id for v in out])

        e1.delete()
        e2.delete()
        e3.delete()
예제 #8
0
    def test_incoming_edge_traversals(self):
        """Test that incoming edge traversals work."""
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=12)
        e2 = TestEdgeModel.create(self.v1, self.v3, test_val=13)
        e3 = OtherTestEdge.create(self.v2, self.v3, test_val=14)

        results = self.v2.inE()
        self.assertEqual(len(results), 1)
        self.assertIn(e1, results)

        results = self.v2.inE(types=[OtherTestEdge])
        self.assertEqual(len(results), 0)

        e1.delete()
        e2.delete()
        e3.delete()
예제 #9
0
    def test_incoming_vertex_traversal(self):
        """Test that incoming vertex traversals work."""
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=12)
        e2 = TestEdgeModel.create(self.v1, self.v3, test_val=13)
        e3 = TestEdgeModel.create(self.v2, self.v3, test_val=14)

        results = self.v2.inV(TestEdgeModel)
        self.assertEqual(len(results), 1)
        self.assertIn(self.v1, results)

        results = self.v2.inV(TestEdgeModel, types=[OtherTestModel])
        self.assertEqual(len(results), 0)

        e1.delete()
        e2.delete()
        e3.delete()
예제 #10
0
    def test_inV_ouV_vertex_traversal(self):
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)

        v1 = e1.outV()
        v2 = e1.inV()
        self.assertEqual(v1, self.v1)
        self.assertEqual(v2, self.v2)

        e1.delete()
예제 #11
0
    def test_find_by_value_method(self):
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=-99, name='e1')
        e2 = TestEdgeModel.create(self.v1, self.v2, test_val=-100, name='e2')
        e3 = TestEdgeModelDouble.create(self.v1, self.v2, test_val=-101.0, name='e3')

        self.assertEqual(len(TestEdgeModel.find_by_value('test_val', -99)), 1)
        self.assertEqual(len(TestEdgeModel.find_by_value('test_val', -100)), 1)
        self.assertEqual(len(TestEdgeModel.find_by_value('test_val', -102)), 0)
        self.assertEqual(len(TestEdgeModel.find_by_value('name', 'e2')), 1)
        self.assertEqual(len(TestEdgeModelDouble.find_by_value('test_val', -101.0)), 1)

        print_(e1)
        print_(e2)
        print_(e3)

        e1.delete()
        e2.delete()
        e3.delete()
예제 #12
0
    def test_inV_ouV_vertex_traversal(self):
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)

        v1 = e1.outV()
        v2 = e1.inV()
        self.assertEqual(v1, self.v1)
        self.assertEqual(v2, self.v2)

        e1.delete()
예제 #13
0
    def test_model_save_and_load(self):
        """
        Tests that models can be saved and retrieved
        """
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)

        edges = self.v1.outE()
        self.assertEqual(len(edges), 1)
        self.assertEqual(edges[0].id, e1.id)

        e1.delete()
예제 #14
0
    def test_model_save_and_load(self):
        """
        Tests that models can be saved and retrieved
        """
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)

        edges = self.v1.outE()
        self.assertEqual(len(edges), 1)
        self.assertEqual(edges[0].id, e1.id)

        e1.delete()
예제 #15
0
    def test_multiple_edge_traversal_with_type_filtering(self):
        """ Tests that using multiple edges for traversals works """
        v = TestVertexModel.create(test_val=1, name='Test1')

        v1 = TestVertexModel.create()
        e1 = TestEdgeModel.create(v, v1)

        v2 = TestVertexModel.create()
        e2 = OtherTestEdge.create(v, v2)

        v3 = TestVertexModel.create()
        e3 = YetAnotherTestEdge.create(v, v3)

        v4 = OtherTestModel.create()
        e4 = TestEdgeModel.create(v, v4)

        v5 = OtherTestModel.create()
        e5 = OtherTestEdge.create(v, v5)

        v6 = OtherTestModel.create()
        e6 = YetAnotherTestEdge.create(v, v6)

        self.assertEqual(len(v.outV()), 6)

        self.assertEqual(len(v.outV(TestEdgeModel, OtherTestEdge)), 4)
        self.assertEqual(len(v.outV(TestEdgeModel, OtherTestEdge, types=[TestVertexModel])), 2)

        e1.delete()
        e2.delete()
        e3.delete()
        e4.delete()
        e5.delete()
        e6.delete()
        v.delete()
        v1.delete()
        v2.delete()
        v3.delete()
        v4.delete()
        v5.delete()
        v6.delete()
예제 #16
0
    def test_find_by_value_method(self):
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=-99, name='e1')
        e2 = TestEdgeModel.create(self.v1, self.v2, test_val=-100, name='e2')
        e3 = TestEdgeModelDouble.create(self.v1,
                                        self.v2,
                                        test_val=-101.0,
                                        name='e3')

        self.assertEqual(len(TestEdgeModel.find_by_value('test_val', -99)), 1)
        self.assertEqual(len(TestEdgeModel.find_by_value('test_val', -100)), 1)
        self.assertEqual(len(TestEdgeModel.find_by_value('test_val', -102)), 0)
        self.assertEqual(len(TestEdgeModel.find_by_value('name', 'e2')), 1)
        self.assertEqual(
            len(TestEdgeModelDouble.find_by_value('test_val', -101.0)), 1)

        print_(e1)
        print_(e2)
        print_(e3)

        e1.delete()
        e2.delete()
        e3.delete()
예제 #17
0
    def test_delete_methods(self):
        v1 = TestVertexModel.create()
        v2 = TestVertexModel.create()

        # delete_outE
        e1 = TestEdgeModel.create(v1, v2)
        v1.delete_outE(TestEdgeModel)

        # delete_inE
        e1 = TestEdgeModel.create(v1, v2)
        v2.delete_inE(TestEdgeModel)

        # delete_inV
        e1 = TestEdgeModel.create(v1, v2)
        v1.delete_inV(TestEdgeModel)

        # delete_outV
        v2 = TestVertexModel.create()
        e1 = TestEdgeModel.create(v1, v2)
        v2.delete_outV(TestEdgeModel)

        v2.delete()
예제 #18
0
    def test_model_updating_works_properly(self):
        """
        Tests that subsequent saves after initial model creation work
        """
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)

        e1.test_val = 20
        e1.save()

        edges = self.v1.outE()
        self.assertEqual(len(edges), 1)
        self.assertEqual(edges[0].test_val, 20)

        e1.delete()
예제 #19
0
    def test_model_updating_works_properly(self):
        """
        Tests that subsequent saves after initial model creation work
        """
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)

        e1.test_val = 20
        e1.save()

        edges = self.v1.outE()
        self.assertEqual(len(edges), 1)
        self.assertEqual(edges[0].test_val, 20)

        e1.delete()
예제 #20
0
    def test_model_deleting_works_properly(self):
        """
        Tests that an instance's delete method deletes the instance
        """
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)

        e1.delete()
        edges = self.v1.outE()
        self.assertEqual(len(edges), 0)

        e1.delete()

        # don't actually create a db model and try to delete
        e2 = TestEdgeModel(self.v1, self.v2, test_val=3, name='nonexistant')
        e2.delete()
예제 #21
0
    def test_model_deleting_works_properly(self):
        """
        Tests that an instance's delete method deletes the instance
        """
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)

        e1.delete()
        edges = self.v1.outE()
        self.assertEqual(len(edges), 0)

        e1.delete()

        # don't actually create a db model and try to delete
        e2 = TestEdgeModel(self.v1, self.v2, test_val=3, name='nonexistant')
        e2.delete()
예제 #22
0
    def test_reload(self):
        """
        Tests that the reload method performs an inplace update of an instance's values
        """
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)
        e2 = TestEdgeModel.get(e1.id)
        print_('\n{} {} {}: {} {}'.format(e1.id, e2.id, e1 == e2, e1.test_val, e2.test_val))
        e2.test_val = 5
        e2.save()
        print_("{} {} {}: {} {}".format(e1.id, e2.id, e1 == e2, e1.test_val, e2.test_val))

        self.assertEqual(e1.test_val, 3)
        e1.reload()
        self.assertEqual(e1.test_val, 5)
        e1 = self.v1.outE()[0]
        self.assertEqual(e1.test_val, 5)

        e2.delete()
예제 #23
0
    def test_unknown_edge_traversal_filter_type_fails(self):
        """
        Tests an exception is raised if a traversal filter is
        used that's not an edge class, instance or label string fails
        """
        e1 = TestEdgeModel.create(self.v1, self.v2)
        e2 = OtherTestEdge.create(self.v1, self.v3)
        e3 = YetAnotherTestEdge.create(self.v1, self.v4)

        with self.assertRaises(MogwaiException):
            out = self.v1.outV(5)

        with self.assertRaises(MogwaiException):
            out = self.v1.outV(True)

        e1.delete()
        e2.delete()
        e3.delete()
예제 #24
0
    def test_edge_instance_traversal_types(self):
        """ Test traversals with edge instances work properly """
        te = TestEdgeModel.create(self.v1, self.v2)
        ote = OtherTestEdge.create(self.v1, self.v3)
        yate = YetAnotherTestEdge.create(self.v1, self.v4)

        out = self.v1.outV(te, ote)
        self.assertEqual(len(out), 2)
        self.assertIn(self.v2.id, [v.id for v in out])
        self.assertIn(self.v3.id, [v.id for v in out])

        out = self.v1.outV(ote, yate)
        self.assertEqual(len(out), 2)
        self.assertIn(self.v3.id, [v.id for v in out])
        self.assertIn(self.v4.id, [v.id for v in out])

        te.delete()
        ote.delete()
        yate.delete()
예제 #25
0
    def test_edge_label_string_traversal_types(self):
        """ Test traversals with edge instances work properly """
        e1 = TestEdgeModel.create(self.v1, self.v2)
        e2 = OtherTestEdge.create(self.v1, self.v3)
        e3 = YetAnotherTestEdge.create(self.v1, self.v4)

        out = self.v1.outV(TestEdgeModel.get_label(), OtherTestEdge.get_label())
        self.assertEqual(len(out), 2)
        self.assertIn(self.v2.id, [v.id for v in out])
        self.assertIn(self.v3.id, [v.id for v in out])

        out = self.v1.outV(OtherTestEdge.get_label(), YetAnotherTestEdge.get_label())
        self.assertEqual(len(out), 2)
        self.assertIn(self.v3.id, [v.id for v in out])
        self.assertIn(self.v4.id, [v.id for v in out])

        e1.delete()
        e2.delete()
        e3.delete()
예제 #26
0
    def test_get_by_id(self):
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)
        results = TestEdgeModel.get(e1.id)
        self.assertIsInstance(results, TestEdgeModel)
        self.assertEqual(results, e1)

        from mogwai.exceptions import MogwaiQueryError
        with self.assertRaises(TestEdgeModel.DoesNotExist):
            results = TestEdgeModel.get(None)

        with self.assertRaises(TestEdgeModel.DoesNotExist):
            results = TestEdgeModel.get('nonexistant')

        e2 = TestEdgeModel2.create(self.v1, self.v2, test_val=2)
        with self.assertRaises(TestEdgeModel.WrongElementType):
            results = TestEdgeModel.get(e2.id)

        e1.delete()
        e2.delete()
예제 #27
0
    def test_get_by_id(self):
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)
        results = TestEdgeModel.get(e1.id)
        self.assertIsInstance(results, TestEdgeModel)
        self.assertEqual(results, e1)

        from mogwai.exceptions import MogwaiQueryError
        with self.assertRaises(TestEdgeModel.DoesNotExist):
            results = TestEdgeModel.get(None)

        with self.assertRaises(TestEdgeModel.DoesNotExist):
            results = TestEdgeModel.get('nonexistant')

        e2 = TestEdgeModel2.create(self.v1, self.v2, test_val=2)
        with self.assertRaises(TestEdgeModel.WrongElementType):
            results = TestEdgeModel.get(e2.id)

        e1.delete()
        e2.delete()
예제 #28
0
    def test_reload(self):
        """
        Tests that the reload method performs an inplace update of an instance's values
        """
        e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)
        e2 = TestEdgeModel.get(e1.id)
        print_('\n{} {} {}: {} {}'.format(e1.id, e2.id, e1 == e2, e1.test_val,
                                          e2.test_val))
        e2.test_val = 5
        e2.save()
        print_("{} {} {}: {} {}".format(e1.id, e2.id, e1 == e2, e1.test_val,
                                        e2.test_val))

        self.assertEqual(e1.test_val, 3)
        e1.reload()
        self.assertEqual(e1.test_val, 5)
        e1 = self.v1.outE()[0]
        self.assertEqual(e1.test_val, 5)

        e2.delete()
예제 #29
0
 def test_reload_no_changes(self):
     # NOTE titan 0.4.2 and earlier changes made to an edge deletes and then creates a new edge
     e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)
     e1.reload()
     e1.delete()
예제 #30
0
 def test_in_between_method(self):
     e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)
     results = TestEdgeModel.get_between(self.v1, self.v2)
     self.assertIsInstance(results, list)
     self.assertEqual(results[0], e1)
     e1.delete()
예제 #31
0
 def test_in_between_method(self):
     e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)
     results = TestEdgeModel.get_between(self.v1, self.v2)
     self.assertIsInstance(results, list)
     self.assertEqual(results[0], e1)
     e1.delete()
예제 #32
0
 def test_reload_no_changes(self):
     # NOTE titan 0.4.2 and earlier changes made to an edge deletes and then creates a new edge
     e1 = TestEdgeModel.create(self.v1, self.v2, test_val=3)
     e1.reload()
     e1.delete()