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


Python DataView.save方法代碼示例

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


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

示例1: test_session

# 需要導入模塊: from avocado.models import DataView [as 別名]
# 或者: from avocado.models.DataView import save [as 別名]
    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)
開發者ID:awenocur,項目名稱:serrano,代碼行數:27,代碼來源:view.py

示例2: test_embedded

# 需要導入模塊: from avocado.models import DataView [as 別名]
# 或者: from avocado.models.DataView import save [as 別名]
    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'])
開發者ID:chop-dbhi,項目名稱:serrano,代碼行數:33,代碼來源:view.py

示例3: test_put

# 需要導入模塊: from avocado.models import DataView [as 別名]
# 或者: from avocado.models.DataView import save [as 別名]
    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)
開發者ID:awenocur,項目名稱:serrano,代碼行數:28,代碼來源:view.py

示例4: test_multiple_views

# 需要導入模塊: from avocado.models import DataView [as 別名]
# 或者: from avocado.models.DataView import save [as 別名]
 def test_multiple_views(self):
     dv1 = DataView(session=True, user=self.user)
     dv1.save()
     dv2 = DataView(session=True, user=self.user)
     dv2.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,代碼行數:11,代碼來源:base.py

示例5: test_non_existent_revision

# 需要導入模塊: from avocado.models import DataView [as 別名]
# 或者: from avocado.models.DataView import save [as 別名]
    def test_non_existent_revision(self):
        view = DataView(user=self.user)
        view.save()

        view.name = "Fake name"
        view.save()

        url = '/api/views/{0}/revisions/{1}/'.format(view.id, 123456789)

        response = self.client.get(url, HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.not_found)
開發者ID:chop-dbhi,項目名稱:serrano,代碼行數:13,代碼來源:view.py

示例6: test_get

# 需要導入模塊: from avocado.models import DataView [as 別名]
# 或者: from avocado.models.DataView import save [as 別名]
    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)
開發者ID:chop-dbhi,項目名稱:serrano,代碼行數:14,代碼來源:view.py

示例7: test_no_object_model

# 需要導入模塊: from avocado.models import DataView [as 別名]
# 或者: from avocado.models.DataView import save [as 別名]
    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)
開發者ID:rv816,項目名稱:serrano,代碼行數:14,代碼來源:base.py

示例8: test_bad_urls

# 需要導入模塊: from avocado.models import DataView [as 別名]
# 或者: from avocado.models.DataView import save [as 別名]
    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)
開發者ID:rv816,項目名稱:serrano,代碼行數:15,代碼來源:base.py

示例9: test_non_existent_object

# 需要導入模塊: from avocado.models import DataView [as 別名]
# 或者: from avocado.models.DataView import save [as 別名]
    def test_non_existent_object(self):
        view = DataView(user=self.user)
        view.save()

        view.name = "Fake name"
        view.save()

        target_revision_id = Revision.objects.all().count()

        url = '/api/views/{0}/revisions/{1}/'.format(123456789, target_revision_id)

        response = self.client.get(url,
            HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.not_found)
開發者ID:awenocur,項目名稱:serrano,代碼行數:16,代碼來源:view.py

示例10: test_custom_template

# 需要導入模塊: from avocado.models import DataView [as 別名]
# 或者: from avocado.models.DataView import save [as 別名]
    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)
開發者ID:rv816,項目名稱:serrano,代碼行數:16,代碼來源:base.py

示例11: test_user

# 需要導入模塊: from avocado.models import DataView [as 別名]
# 或者: from avocado.models.DataView import save [as 別名]
    def test_user(self):
        view = DataView(user=self.user)
        view.save()

        user2 = User.objects.create_user(username='FAKE', password='ALSO_FAKE')
        view2 = DataView(user=user2)
        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)
開發者ID:awenocur,項目名稱:serrano,代碼行數:17,代碼來源:view.py

示例12: test_multiple_context_and_view

# 需要導入模塊: from avocado.models import DataView [as 別名]
# 或者: from avocado.models.DataView 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 DataView [as 別名]
# 或者: from avocado.models.DataView import save [as 別名]
    def test_get_session(self):
        view = DataView(user=self.user, name='Session View', session=True)
        view.save()

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

        view.session = False
        view.save()

        response = self.client.get('/api/views/session/',
            HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.not_found)
開發者ID:awenocur,項目名稱:serrano,代碼行數:17,代碼來源:view.py

示例14: test_get

# 需要導入模塊: from avocado.models import DataView [as 別名]
# 或者: from avocado.models.DataView import save [as 別名]
    def test_get(self):
        view = DataView(user=self.user)
        view.save()
        response = self.client.get('/api/views/1/',
            HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertTrue(response.content)
        self.assertLess(view.accessed,
                DataView.objects.get(pk=view.pk).accessed)

        # Make sure that accessing a non-existent view returns a 404 error
        # indicating that it wasn't found.
        response = self.client.get('/api/views/999/',
            HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.not_found)
開發者ID:awenocur,項目名稱:serrano,代碼行數:17,代碼來源:view.py

示例15: test_no_identifier

# 需要導入模塊: from avocado.models import DataView [as 別名]
# 或者: from avocado.models.DataView import save [as 別名]
    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)
開發者ID:awenocur,項目名稱:serrano,代碼行數:19,代碼來源:view.py


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