当前位置: 首页>>代码示例>>Python>>正文


Python DataContext.save方法代码示例

本文整理汇总了Python中avocado.models.DataContext.save方法的典型用法代码示例。如果您正苦于以下问题:Python DataContext.save方法的具体用法?Python DataContext.save怎么用?Python DataContext.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在avocado.models.DataContext的用法示例。


在下文中一共展示了DataContext.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_change

# 需要导入模块: from avocado.models import DataContext [as 别名]
# 或者: from avocado.models.DataContext import save [as 别名]
    def test_change(self):
        c = DataContext()
        c.save()

        revisions = Revision.objects.get_for_object(c)
        self.assertEqual(revisions.count(), 1)

        latest_revision = Revision.objects.latest_for_object(c)
        self.assertFalse('old_value' in latest_revision.changes)
        self.assertEqual(latest_revision.changes, {
            'json': {'new_value': {}},
            'name': {'new_value': None},
            'description': {'new_value': None}
        })

        c.name = "New Name"
        c.save()

        revisions = Revision.objects.get_for_object(c)
        self.assertEqual(revisions.count(), 2)

        latest_revision = Revision.objects.latest_for_object(c)
        self.assertEqual(latest_revision.changes, {
            'name': {'old_value': None, 'new_value': 'New Name'}
        })
开发者ID:hassanNS,项目名称:avocado,代码行数:27,代码来源:tests.py

示例2: test_put

# 需要导入模块: from avocado.models import DataContext [as 别名]
# 或者: from avocado.models.DataContext import save [as 别名]
    def test_put(self):
        # Add a context so we can try to update it later.
        ctx = DataContext(user=self.user, name='Context 1')
        ctx.save()
        response = self.client.get('/api/contexts/1/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertTrue(response.content)

        # Attempt to update the name via a PUT request.
        response = self.client.put(
            '/api/contexts/1/',
            data=u'{"name":"New Name"}',
            content_type='application/json')
        self.assertEqual(response.status_code, codes.ok)

        # Make sure our changes from the PUT request are persisted.
        response = self.client.get('/api/contexts/1/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertTrue(response.content)
        self.assertEqual(json.loads(response.content)['name'], 'New Name')

        # Make a PUT request with invalid JSON and make sure we get an
        # unprocessable status code back.
        response = self.client.put(
            '/api/contexts/1/',
            data=u'{"json":"]]]"}',
            content_type='application/json')
        self.assertEqual(response.status_code, codes.unprocessable_entity)
开发者ID:rv816,项目名称:serrano,代码行数:32,代码来源:context.py

示例3: test_get

# 需要导入模块: from avocado.models import DataContext [as 别名]
# 或者: from avocado.models.DataContext import save [as 别名]
    def test_get(self):
        ctx = DataContext(user=self.user)
        ctx.save()

        response = self.client.get('/api/contexts/revisions/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertEqual(len(json.loads(response.content)), 1)
开发者ID:rv816,项目名称:serrano,代码行数:10,代码来源:context.py

示例4: test_multiple_contexts

# 需要导入模块: from avocado.models import DataContext [as 别名]
# 或者: from avocado.models.DataContext import save [as 别名]
 def test_multiple_contexts(self):
     cxt1 = DataContext(session=True, user=self.user)
     cxt1.save()
     cxt2 = DataContext(user=self.user, session=True)
     cxt2.save()
     response = self.client.get('/api/data/preview/',
                                HTTP_ACCEPT='application/json')
     self.assertEqual(response.status_code, codes.ok)
开发者ID:rv816,项目名称:serrano,代码行数:10,代码来源:base.py

示例5: test_session

# 需要导入模块: from avocado.models import DataContext [as 别名]
# 或者: from avocado.models.DataContext import save [as 别名]
    def test_session(self):
        cxt = DataContext(session=True, user=self.user)
        cxt.save()

        response = self.client.get('/api/contexts/session/stats/',
                                   HTTP_ACCEPT='application/json')

        self.assertEqual(json.loads(response.content)['count'], 6)
开发者ID:rv816,项目名称:serrano,代码行数:10,代码来源:context.py

示例6: test_deleted_revision

# 需要导入模块: from avocado.models import DataContext [as 别名]
# 或者: from avocado.models.DataContext import save [as 别名]
    def test_deleted_revision(self):
        c = DataContext(name="Test", json={})
        c.save()
        fields = ["name", "description", "json"]

        revision = Revision.objects.create_revision(c, fields=fields, deleted=True)

        self.assertEqual(revision.data, None)
        self.assertEqual(revision.changes, None)
开发者ID:chop-dbhi,项目名称:avocado,代码行数:11,代码来源:tests.py

示例7: test_nochange

# 需要导入模块: from avocado.models import DataContext [as 别名]
# 或者: from avocado.models.DataContext import save [as 别名]
    def test_nochange(self):
        c = DataContext()
        c.save()

        revisions = Revision.objects.get_for_object(c)
        self.assertEqual(revisions.count(), 1)

        # No changes, no new revision
        c.save()
        self.assertEqual(revisions.count(), 1)
开发者ID:chop-dbhi,项目名称:avocado,代码行数:12,代码来源:tests.py

示例8: test_deleted_revision

# 需要导入模块: from avocado.models import DataContext [as 别名]
# 或者: from avocado.models.DataContext import save [as 别名]
    def test_deleted_revision(self):
        c = DataContext(name='Test', json={})
        c.save()
        fields = ['name', 'description', 'json']

        revision = Revision.objects.create_revision(c,
            fields=fields, deleted=True)

        self.assertEqual(revision.data, None)
        self.assertEqual(revision.changes, None)
开发者ID:hassanNS,项目名称:avocado,代码行数:12,代码来源:tests.py

示例9: test_apply

# 需要导入模块: from avocado.models import DataContext [as 别名]
# 或者: from avocado.models.DataContext import save [as 别名]
    def test_apply(self):
        c = DataContext({'field': 1, 'operator': 'exact', 'value': 30})
        c.save()

        revision = Revision.objects.create_revision(c, fields=['json'])

        c.json['value'] = 50
        c.save()

        revision.apply(c)
        self.assertEqual(c.json['value'], 30)
开发者ID:hassanNS,项目名称:avocado,代码行数:13,代码来源:tests.py

示例10: setUp

# 需要导入模块: from avocado.models import DataContext [as 别名]
# 或者: from avocado.models.DataContext import save [as 别名]
    def setUp(self):
        c1 = DataContext({'field': 1, 'operator': 'exact', 'value': 30})
        c1.save()
        Revision.objects.create_revision(c1, fields=['json'])

        c2 = DataContext({'field': 2, 'operator': 'in', 'value': [1, 2]})
        c2.save()
        Revision.objects.create_revision(c2, fields=['json'])

        self.c1 = c1
        self.c2 = c2
开发者ID:hassanNS,项目名称:avocado,代码行数:13,代码来源:tests.py

示例11: test_processor

# 需要导入模块: from avocado.models import DataContext [as 别名]
# 或者: from avocado.models.DataContext import save [as 别名]
    def test_processor(self):
        cxt = DataContext(session=True, user=self.user)
        cxt.save()

        response = self.client.get('/api/contexts/{0}/stats/'.format(cxt.pk),
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(json.loads(response.content)['count'], 6)

        response = self.client.get('/api/contexts/{0}/stats/?processor=manager'
                                   .format(cxt.pk),
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(json.loads(response.content)['count'], 1)
开发者ID:chop-dbhi,项目名称:serrano,代码行数:14,代码来源:context.py

示例12: test_multiple_context_and_view

# 需要导入模块: from avocado.models import DataContext [as 别名]
# 或者: from avocado.models.DataContext import save [as 别名]
 def test_multiple_context_and_view(self):
     # Create two Contexts and views, an illegal action that
     # Our base resource should handle
     cxt3 = DataContext(session=True, user=self.user)
     cxt3.save()
     cxt4 = DataContext(user=self.user, session=True)
     cxt4.save()
     dv3 = DataView(session=True, user=self.user)
     dv3.save()
     dv4 = DataView(session=True, user=self.user)
     dv4.save()
     response = self.client.get('/api/data/preview/',
                                HTTP_ACCEPT='application/json')
     self.assertTrue(response.content)
     self.assertEqual(response.status_code, codes.ok)
开发者ID:rv816,项目名称:serrano,代码行数:17,代码来源:base.py

示例13: test_get_session

# 需要导入模块: from avocado.models import DataContext [as 别名]
# 或者: from avocado.models.DataContext import save [as 别名]
    def test_get_session(self):
        context = DataContext(user=self.user, name='Session Context', session=True)
        context.save()

        response = self.client.get('/api/contexts/session/',
            HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertTrue(response.content)

        context.session = False
        context.save()

        response = self.client.get('/api/contexts/session/',
            HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.not_found)
开发者ID:awenocur,项目名称:serrano,代码行数:17,代码来源:context.py

示例14: test_get

# 需要导入模块: from avocado.models import DataContext [as 别名]
# 或者: from avocado.models.DataContext import save [as 别名]
    def test_get(self):
        ctx = DataContext(user=self.user)
        ctx.save()
        response = self.client.get('/api/contexts/1/',
            HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertTrue(response.content)
        self.assertLess(ctx.accessed,
                DataContext.objects.get(pk=ctx.pk).accessed)

        # Make sure that accessing a non-existent context returns a 404 error
        # indicating that it wasn't found.
        response = self.client.get('/api/contexts/999/',
            HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.not_found)
开发者ID:awenocur,项目名称:serrano,代码行数:17,代码来源:context.py

示例15: test_create_revision

# 需要导入模块: from avocado.models import DataContext [as 别名]
# 或者: from avocado.models.DataContext import save [as 别名]
    def test_create_revision(self):
        c = DataContext(name="Test", json={})
        c.save()

        revision = Revision.objects.create_revision(c, fields=["name", "description", "json"])

        self.assertEqual(revision.data, {"name": "Test", "description": None, "json": {}})

        revisions = Revision.objects.get_for_object(c)
        self.assertEqual(revisions.count(), 1)

        self.assertFalse(Revision.objects.object_has_changed(c))
        self.assertEqual(
            revisions[0].changes,
            {"name": {"new_value": "Test"}, "description": {"new_value": None}, "json": {"new_value": {}}},
        )
开发者ID:chop-dbhi,项目名称:avocado,代码行数:18,代码来源:tests.py


注:本文中的avocado.models.DataContext.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。