Example #1
0
def home():
    """
    Create a row in Cassandra and show count of rows
    """
    from models import Foo
    Foo.create(kind=0, description='testcreate', created_at=datetime.now())
    return render_template('index.html', count=Foo.objects.count())
Example #2
0
    def test_custom_hooks_are_class_local(self):
        """Test that all custom hooks affect single classes."""

        self._clear_tables()
        node_id = 'test_locality'

        def bad_hook(target, session, *args, **kwargs):
            raise RuntimeError

        Test._session_hooks_before_insert = [
            bad_hook,
        ]

        try:
            with self.assertRaises(RuntimeError):
                with g.session_scope() as s:
                    test = Test(node_id)
                    s.merge(test)

            with g.session_scope() as s:
                foo = Foo(node_id)
                s.merge(foo)

            with g.session_scope():
                foo = g.nodes(Foo).ids(node_id).one()
                self.assertEqual(foo.bar, None)
                self.assertEqual(foo.baz, None)

        finally:
            Test._session_hooks_before_insert = []
Example #3
0
 def test_edge_attributes(self):
     foo = Foo('foonode')
     edge = Edge2(self.nid, 'foonode')
     with g.session_scope() as s:
         s.add_all((edge, foo))
     with g.session_scope() as s:
         n = g.nodes().ids(self.nid).one()
         self.assertEqual(n.foos[0].node_id, 'foonode')
Example #4
0
 def test_relationship_population_constructer(self):
     a = Test('a')
     b = Foo('b')
     e = Edge2(src=a, dst=b)
     with g.session_scope() as s:
         a, b = map(s.merge, (a, b))
         e2 = s.query(Edge2).src('a').dst('b').one()
         e = a._Edge2_out[0]
         self.assertEqual(e2, e)
Example #5
0
 def test_cascade_delete(self):
     a = Test('a')
     b = Foo('b')
     a.foos = [b]
     with g.session_scope() as s:
         a, b = map(s.merge, (a, b))
     with g.session_scope() as s:
         s.delete(g.nodes(Test).ids('a').one())
     with g.session_scope() as s:
         self.assertIsNone(g.nodes(Test).ids('a').scalar())
         self.assertIsNone(g.edges(Edge2).src('a').dst('b').scalar())
Example #6
0
 def test_association_proxy(self):
     a = Test('a')
     b = Foo('b')
     c = Test('c')
     a.foos.append(b)
     a.tests = [c]
     with g.session_scope() as s:
         a, b, c = map(s.merge, (a, b, c))
     with g.session_scope() as s:
         a = g.nodes(Test).ids('a').one()
         self.assertTrue(b in a.foos)
         self.assertEqual(a.tests, [c])
Example #7
0
 def create(self, user=None, firstname=None):
     try:
         f = Foo()
         f.user = user
         f.firstname = firstname
         f.put()
     except Exception as e:
         details = str(e)
         logging.info(details)
         raise CustomException(details=details)
     return f
Example #8
0
    def post(self):
        """
        创建一条记录
        :return:
        """
        # 参数
        params = request.get_json()
        name = params.get("name")
        age = params.get("age")
        # 构建一个模型
        foo = Foo(name=name, age=age)

        # 加入到数据库
        db.session.add(foo)
        db.session.commit()

        return success("新增一条记录成功!")
Example #9
0
def foo_service3():
    foo = Foo()
    foo.name = "foo name"
    foo.desc = "foo desc"
    foo.save()
Example #10
0
def foo_service2():
    foo = Foo(desc="foo desc")
    foo.name = "foo name"
    foo.save()
Example #11
0
def addfoo(request):
    foo = Foo(name="New Foo")
    foo.save()

    return HttpResponseRedirect(reverse("list"))
Example #12
0
def foo_service3():
    foo = Foo()
    foo.name = "foo name"
    foo.desc = "foo desc"
    foo.save()
Example #13
0
def foo_service1():
    foo = Foo(name="foo name")
    foo.desc = "foo desc"
    foo.save()
Example #14
0
def foo_service2():
    foo = Foo(desc="foo desc")
    foo.name = "foo name"
    foo.save()
Example #15
0
def foo_service():
    foo = Foo("name")
    foo.desc = "desc"
    foo.save()
    return foo
Example #16
0
 def test_type_enum(self):
     with self.assertRaises(ValidationError):
         Foo().fobble = 'test'
Example #17
0
def foo_service1():
    foo = Foo(name="foo name")
    foo.desc = "foo desc"
    foo.save()
Example #18
0
 def test_validate_enum(self):
     n = Foo('foonode')
     n.baz = 'allowed_1'
     n.baz = 'allowed_2'
     with self.assertRaises(ValidationError):
         n.baz = 'not allowed'