本文整理汇总了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)
示例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)]))
示例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)])
示例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)]))
示例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)])
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)