本文整理汇总了Python中avocado.models.DataView类的典型用法代码示例。如果您正苦于以下问题:Python DataView类的具体用法?Python DataView怎么用?Python DataView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_put
def test_put(self):
# Add a view so we can try to update it later
view = DataView(user=self.user, name='Initial Name')
view.save()
response = self.client.get('/api/views/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/views/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/views/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/views/1/',
data=u'{"json":"]]]"}', content_type='application/json')
self.assertEqual(response.status_code, codes.unprocessable_entity)
示例2: test_embedded
def test_embedded(self):
view = DataView(user=self.user, name='My View',
description='This is not a descriptive description')
view.save()
# Retrieve the revisions the normal way and make sure the object
# itself is not included.
response = self.client.get('/api/views/revisions/',
HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.ok)
self.assertEqual(len(json.loads(response.content)), 1)
no_embed_revision = json.loads(response.content)[0]
self.assertFalse('object' in no_embed_revision)
# Now retrieve the revisiosn with the embed flag enabled and verify
# that the object is now included with the revision.
response = self.client.get('/api/views/revisions/', {'embed': True},
HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.ok)
self.assertEqual(len(json.loads(response.content)), 1)
embed_revision = json.loads(response.content)[0]
self.assertTrue('object' in embed_revision)
# Make sure the included object matches the copy of the object directly
# from the object resource itself.
response = self.client.get('/api/views/{0}/'.format(view.pk),
HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.ok)
revision_view = json.loads(response.content)
self.assertEqual(revision_view, embed_revision['object'])
示例3: test_sort_related
def test_sort_related(self):
"Sorts on a reverse foreign key property."
view = DataView(
json=[
{"concept": self.first_name.pk},
{"concept": self.last_name.pk},
{"concept": self.project_name.pk, "sort": "asc", "visible": False},
]
)
queryset = view.apply()
exporter = export.BaseExporter(view)
exporter.params.insert(0, (RawFormatter(keys=["pk"]), 1))
exporter.row_length += 1
self.assertEqual(
list(exporter.write(queryset.raw())),
[
(3, u"Erick", u"Smith"),
(4, u"Aaron", u"Harris"),
(5, u"Zac", u"Cook"),
(6, u"Mel", u"Brooks"),
(1, u"Eric", u"Smith"),
(2, u"Erin", u"Jones"),
],
)
示例4: setUp
def setUp(self):
management.call_command("avocado", "init", "tests", quiet=True)
salary_concept = DataField.objects.get(field_name="salary").concepts.all()[0]
view = DataView(json={"ordering": [[salary_concept.pk, "desc"]]})
self.query = view.apply(tree=models.Employee).raw()
# Ick..
self.exporter = export.BaseExporter(view)
self.exporter.params.insert(0, (RawFormatter(keys=["pk"]), 1))
self.exporter.row_length += 1
示例5: test_delete
def test_delete(self):
view = DataView(user=self.user, name='View 1')
view.save()
view = DataView(user=self.user, name='View 2')
view.save()
view = DataView(user=self.user, name='View 3', session=True)
view.save()
response = self.client.get('/api/views/',
HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.ok)
self.assertEqual(len(json.loads(response.content)), 3)
response = self.client.delete('/api/views/1/')
self.assertEqual(response.status_code, codes.no_content)
response = self.client.get('/api/views/',
HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.ok)
self.assertEqual(len(json.loads(response.content)), 2)
response = self.client.delete('/api/views/3/')
self.assertEqual(response.status_code, codes.bad_request)
response = self.client.get('/api/views/',
HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.ok)
self.assertEqual(len(json.loads(response.content)), 2)
示例6: test_get
def test_get(self):
view = DataView(user=self.user)
view.save()
view.name = "Fake name"
view.save()
target_revision_id = Revision.objects.all().count()
view.description = "Terribly vague description"
view.save()
url = '/api/views/{0}/revisions/{1}/'.format(view.id, target_revision_id)
response = self.client.get(url,
HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.ok)
self.assertTrue(response.content)
revision = json.loads(response.content)
self.assertEqual(revision['changes'], {
'name': {
'old_value': None,
'new_value': 'Fake name'
}
})
self.assertFalse("description" in revision['changes'])
示例7: test_no_object_model
def test_no_object_model(self):
# This will trigger a revision to be created
view = DataView(user=self.user)
view.save()
# Make sure we have a revision for this user
self.assertEqual(Revision.objects.filter(user=self.user).count(), 1)
response = self.client.get('/api/test/no_model/',
HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.ok)
self.assertEqual(len(json.loads(response.content)), 0)
示例8: test_get
def test_get(self):
view = DataView(user=self.user)
view.save()
response = self.client.get('/api/views/revisions/',
HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.ok)
self.assertEqual(len(json.loads(response.content)), 1)
response = self.client.get('/api/viewss/999/',
HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.not_found)
示例9: test_bad_urls
def test_bad_urls(self):
view = DataView(user=self.user)
view.save()
target_revision_id = Revision.objects.all().count()
url = '/api/test/revisions/{0}/'.format(target_revision_id)
response = self.client.get(url, HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.not_found)
url = '/api/test/{0}/revisions/'.format(view.id)
response = self.client.get(url, HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.not_found)
示例10: test_dataview_order_by
def test_dataview_order_by(self):
f = DataField(app_name='lexicon', model_name='month', field_name='id')
f.save()
c = DataConcept()
c.save()
cf = DataConceptField(field=f, concept=c)
cf.save()
v = DataView({'ordering': [c.pk]})
qs = Month.objects.filter(label__startswith='J').values('id')
self.assertEqual(str(v.apply(qs).query), 'SELECT "lexicon_month"."id" FROM "lexicon_month" WHERE "lexicon_month"."label" LIKE J% ESCAPE \'\\\' ORDER BY "lexicon_month"."order" ASC')
示例11: test_custom_template
def test_custom_template(self):
view = DataView(user=self.user)
view.save()
response = self.client.get('/api/test/template/',
HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.ok)
self.assertEqual(len(json.loads(response.content)), 1)
revision = json.loads(response.content)[0]
self.assertEqual(revision['id'], 1)
self.assertEqual(revision['object_id'], 1)
self.assertTrue(response['Link-Template'])
self.assertFalse('content_type' in revision)
示例12: test_no_identifier
def test_no_identifier(self):
view = DataView()
view.save()
# Make sure the revision was created but has nothing useful in
# either of the "owner" properties.
self.assertEqual(Revision.objects.filter(
content_type=ContentType.objects.get_for_model(DataView),
user=None, session_key=None).count(), 1)
# We want this request to come from an anonymous user
self.client.logout()
response = self.client.get('/api/views/revisions/',
HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.ok)
self.assertEqual(len(json.loads(response.content)), 0)
示例13: test_clean
def test_clean(self):
# Save a default template
view = DataView(template=True, default=True)
view.save()
# Save new template (not default)
view2 = DataView(template=True)
view2.save()
# Try changing it to default
view2.default = True
self.assertRaises(ValidationError, view2.save)
view.save()
示例14: test_view
def test_view(self):
salary_field = DataField.objects.get_by_natural_key('exporting', 'title', 'salary')
salary_concept = DataConcept()
salary_concept.save()
DataConceptField(concept=salary_concept, field=salary_field, order=1).save()
view = DataView(json={'ordering': [[salary_concept.pk, 'desc']]})
query = view.apply(tree=models.Employee).raw()
# Ick..
exporter = export.CSVExporter(view)
exporter.params.insert(0, (RawFormatter(keys=['pk']), 1))
exporter.row_length += 1
buff = exporter.write(query)
buff.seek(0)
lines = buff.read().splitlines()
# Skip the header
self.assertEqual([int(x) for x in lines[1:]], [2, 4, 6, 1, 3, 5])
示例15: test_session
def test_session(self):
# This session mumbo-jumbo is from:
# https://code.djangoproject.com/ticket/10899
self.client = Client()
from django.conf import settings
from django.utils.importlib import import_module
engine = import_module(settings.SESSION_ENGINE)
store = engine.SessionStore()
store.save() # we need to make load() work, or the cookie is worthless
session_key = store.session_key
self.client.cookies[settings.SESSION_COOKIE_NAME] = session_key
view = DataView(session_key=self.client.session.session_key)
view.save()
view2 = DataView(session_key='XYZ')
view2.save()
self.assertEqual(Revision.objects.filter(
content_type=ContentType.objects.get_for_model(DataView)).count(), 2)
response = self.client.get('/api/views/revisions/',
HTTP_ACCEPT='application/json')
self.assertEqual(response.status_code, codes.ok)
self.assertEqual(len(json.loads(response.content)), 1)