當前位置: 首頁>>代碼示例>>Python>>正文


Python models.DataContext類代碼示例

本文整理匯總了Python中avocado.models.DataContext的典型用法代碼示例。如果您正苦於以下問題:Python DataContext類的具體用法?Python DataContext怎麽用?Python DataContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了DataContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_put

    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,代碼行數:30,代碼來源:context.py

示例2: test_requires_any

 def test_requires_any(self):
     c = DataContext(json={
         'field': self.f.pk,
         'operator': 'in',
         'value': [3]
     })
     self.assertEqual([1, 2, 3], sorted([x.pk for x in c.apply(tree=TicketHolder)]))
開發者ID:chop-dbhi,項目名稱:harvest-vocab,代碼行數:7,代碼來源:tests.py

示例3: test_excludes_any

 def test_excludes_any(self):
     c = DataContext(json={
         'field': self.f.pk,
         'operator': '-in',
         'value': [1, 2]
     })
     self.assertEqual([2], [x.pk for x in c.apply(tree=TicketHolder)])
開發者ID:chop-dbhi,項目名稱:harvest-vocab,代碼行數:7,代碼來源:tests.py

示例4: test_excludes_all

 def test_excludes_all(self):
     c = DataContext(json={
         'field': self.f.pk,
         'operator': '-all',
         'value': [1, 5]
     })
     self.assertEqual([1, 2], sorted([x.pk for x in c.apply(tree=TicketHolder)]))
開發者ID:chop-dbhi,項目名稱:harvest-vocab,代碼行數:7,代碼來源:tests.py

示例5: test_only

 def test_only(self):
     c = DataContext(json={
         'field': self.f.pk,
         'operator': 'only',
         'value': [1, 6]
     })
     self.assertEqual([3], [x.pk for x in c.apply(tree=TicketHolder)])
開發者ID:chop-dbhi,項目名稱:harvest-vocab,代碼行數:7,代碼來源:tests.py

示例6: test_session

    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,代碼行數:8,代碼來源:context.py

示例7: test_get

    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,代碼行數:8,代碼來源:context.py

示例8: test_deleted_revision

    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,代碼行數:9,代碼來源:tests.py

示例9: test_nochange

    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,代碼行數:10,代碼來源:tests.py

示例10: test_count

    def test_count(self):
        json = {
            'field': 'tests.title.salary',
            'operator': 'gt',
            'value': '10000'
        }
        ctx = DataContext(json)

        self.assertEqual(ctx.count(), 6)
        self.assertEqual(ctx.count(tree='office'), 1)
開發者ID:chop-dbhi,項目名稱:avocado,代碼行數:10,代碼來源:tests.py

示例11: test_deleted_revision

    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,代碼行數:10,代碼來源:tests.py

示例12: test_delete

    def test_delete(self):
        ctx1 = DataContext(user=self.user, name='Context 1')
        ctx1.save()
        ctx2 = DataContext(user=self.user, name='Context 2')
        ctx2.save()
        ctx3 = DataContext(user=self.user, name='Context 3', session=True)
        ctx3.save()

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

        response = self.client.delete('/api/contexts/{0}/'.format(ctx1.pk))
        self.assertEqual(response.status_code, codes.no_content)

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

        # Cannot delete the session
        response = self.client.delete('/api/contexts/{0}/'.format(ctx3.pk))
        self.assertEqual(response.status_code, codes.bad_request)

        response = self.client.get('/api/contexts/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertEqual(len(json.loads(response.content)), 2)
開發者ID:chop-dbhi,項目名稱:serrano,代碼行數:29,代碼來源:context.py

示例13: test_delete

    def test_delete(self):
        ctx = DataContext(user=self.user, name='Context 1')
        ctx.save()
        ctx = DataContext(user=self.user, name='Context 2')
        ctx.save()
        ctx = DataContext(user=self.user, name='Context 3', session=True)
        ctx.save()

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

        response = self.client.delete('/api/contexts/1/')
        self.assertEqual(response.status_code, codes.no_content)

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

        response = self.client.delete('/api/contexts/3/')
        self.assertEqual(response.status_code, codes.bad_request)

        response = self.client.get('/api/contexts/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertEqual(len(json.loads(response.content)), 2)
開發者ID:rv816,項目名稱:serrano,代碼行數:28,代碼來源:context.py

示例14: test_processor

    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,代碼行數:12,代碼來源:context.py

示例15: test_get

    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,代碼行數:15,代碼來源:context.py


注:本文中的avocado.models.DataContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。