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


Python DataQuery.save方法代码示例

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


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

示例1: test_put

# 需要导入模块: from avocado.models import DataQuery [as 别名]
# 或者: from avocado.models.DataQuery import save [as 别名]
    def test_put(self):
        # Add a query so we can try to update it later
        query = DataQuery(user=self.user, name='Query 1')
        query.save()
        response = self.client.get('/api/queries/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/queries/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/queries/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/queries/1/',
                                   data=u'{"view_json":"[~][~]"}',
                                   content_type='application/json')
        self.assertEqual(response.status_code, codes.unprocessable_entity)
开发者ID:rv816,项目名称:serrano_night,代码行数:30,代码来源:query.py

示例2: test_get_session

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

        # All results for session query.
        response = self.client.get('/api/queries/session/results/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertTrue(response.content)

        # Single page of results for session query.
        response = self.client.get('/api/queries/session/results/3/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertTrue(response.content)

        # Page range of results for session query.
        response = self.client.get('/api/queries/session/results/1...5/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertTrue(response.content)

        query.session = False
        query.save()

        response = self.client.get('/api/queries/session/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.not_found)
开发者ID:chop-dbhi,项目名称:serrano,代码行数:30,代码来源:query.py

示例3: test_no_create_on_share

# 需要导入模块: from avocado.models import DataQuery [as 别名]
# 或者: from avocado.models.DataQuery import save [as 别名]
    def test_no_create_on_share(self):
        # Make sure we are starting with the anticipated number of users.
        self.assertEqual(User.objects.count(), 1)

        # Assign an email to the existing user
        User.objects.all().update(email=self.existing_email)

        query = DataQuery(template=True, default=True)
        query.save()

        self.assertEqual(query.shared_users.count(), 0)

        # Test when both settings are False
        response = query.share_with_user(self.existing_email)
        self.assertEqual(response, False)

        with self.settings(AVOCADO_SHARE_BY_EMAIL=True):
            # Share with all the emails but, with create_user set to False, the
            # query should only be shared with the 1 existing user.
            [query.share_with_user(e, create_user=False)
                for e in self.emails]
            # Check that the user count increased for the email-based users
            self.assertEqual(User.objects.count(), 1)

            # Check that the users are in the query's shared_users
            self.assertEqual(query.shared_users.count(), 1)
开发者ID:chop-dbhi,项目名称:avocado,代码行数:28,代码来源:tests.py

示例4: test_add_shared_user

# 需要导入模块: from avocado.models import DataQuery [as 别名]
# 或者: from avocado.models.DataQuery import save [as 别名]
    def test_add_shared_user(self):
        # Make sure we are starting with the anticipated number of users.
        self.assertEqual(User.objects.count(), 1)

        # Assign an email to the existing user
        User.objects.update(email=self.existing_email,
                            username=self.existing_username)

        query = DataQuery(template=True, default=True)
        query.save()

        self.assertEqual(query.shared_users.count(), 0)
        # Try add an existing user to shared users by username
        query.share_with_user(self.existing_username)
        self.assertEqual(query.shared_users.count(), 1)

        [query.share_with_user(e) for e in self.emails]

        # Looking up non existant users with usernames should not
        # create new users
        [query.share_with_user(u) for u in self.usernames]

        # Check that the user count increased for the email-based users
        # and no extra users were created when queried w/ username
        self.assertEqual(User.objects.count(), 4)

        # Check that the users are in the query's shared_users
        self.assertEqual(query.shared_users.count(), 4)
开发者ID:chop-dbhi,项目名称:avocado,代码行数:30,代码来源:tests.py

示例5: post

# 需要导入模块: from avocado.models import DataQuery [as 别名]
# 或者: from avocado.models.DataQuery import save [as 别名]
    def post(self, request, **kwargs):
        instance = self.get_object(request, **kwargs)

        if self._requestor_can_fork(request, instance):
            fork = DataQuery(name=instance.name,
                             description=instance.description,
                             view_json=instance.view_json,
                             context_json=instance.context_json,
                             parent=instance)

            if getattr(request, 'user', None):
                fork.user = request.user
            elif request.session.session_key:
                fork.session_key = request.session.session_key

            fork.save()
            request.session.modified = True

            posthook = functools.partial(query_posthook, request=request)
            data = serialize(fork, posthook=posthook, **templates.Query)

            return self.render(request, data, status=codes.created)

        data = {
            'message': 'Cannot fork query',
        }
        return self.render(request, data, status=codes.unauthorized)
开发者ID:rv816,项目名称:serrano_monkey,代码行数:29,代码来源:query.py

示例6: test_get

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

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

示例7: test_session

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

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

        data = json.loads(response.content)
        self.assertEqual(data['distinct_count'], 6)
        self.assertEqual(data['record_count'], 6)
开发者ID:rv816,项目名称:serrano_night,代码行数:12,代码来源:query.py

示例8: test_delete

# 需要导入模块: from avocado.models import DataQuery [as 别名]
# 或者: from avocado.models.DataQuery import save [as 别名]
    def test_delete(self):
        query_name = u'ĘƞĵôƔ ťƕîš ǫųęŕƳ'

        query = DataQuery(user=self.user, name=query_name)
        query.save()
        session_query = DataQuery(user=self.user, name="SessionQuery",
                                  session=True)
        session_query.save()

        user1 = User(username='u1', first_name='Shared', last_name='User',
                     email='[email protected]')
        user1.save()
        query.shared_users.add(user1)
        user2 = User(username='u2', first_name='Shared', last_name='User',
                     email='')
        user2.save()
        query.shared_users.add(user2)
        user3 = User(username='u3', first_name='Shared', last_name='User',
                     email='[email protected]')
        user3.save()
        query.shared_users.add(user3)

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

        response = self.client.delete('/api/queries/{0}/'.format(query.pk),
                                      HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.no_content)

        # Since the delete handler send email asynchronously, wait for a while
        # while the mail goes through.
        time.sleep(5)

        # Make sure the mail was sent
        self.assertEqual(len(mail.outbox), 1)
        # Make sure the subject is correct
        self.assertEqual(mail.outbox[0].subject,
                         u"'{0}' has been deleted".format(query_name))
        # Make sure the recipient list is correct
        self.assertSequenceEqual(
            mail.outbox[0].to, ['[email protected]', '', '[email protected]'])

        response = self.client.get('/api/queries/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(len(json.loads(response.content)), 1)

        # Make sure that we cannot delete the session query
        response = self.client.delete('/api/queries/{0}/'
                                      .format(session_query.pk))
        self.assertEqual(response.status_code, codes.bad_request)

        response = self.client.get('/api/queries/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(len(json.loads(response.content)), 1)
开发者ID:chop-dbhi,项目名称:serrano,代码行数:57,代码来源:query.py

示例9: test_duplicate_share

# 需要导入模块: from avocado.models import DataQuery [as 别名]
# 或者: from avocado.models.DataQuery import save [as 别名]
    def test_duplicate_share(self):
        query = DataQuery(template=True, default=True)
        query.save()

        [query.share_with_user(e) for e in self.emails]

        share_count = query.shared_users.count()
        user_count = User.objects.count()

        # Make sure that requests to share with users that are already shared
        # with don't cause new user or shared_user entries.
        [query.share_with_user(e) for e in self.emails]

        self.assertEqual(share_count, query.shared_users.count())
        self.assertEqual(user_count, User.objects.count())
开发者ID:hassanNS,项目名称:avocado,代码行数:17,代码来源:tests.py

示例10: test_get_session

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

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

        query.session = False
        query.save()

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

示例11: test_processor

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

        response = self.client.get('/api/queries/{0}/stats/'.format(query.pk),
                                   HTTP_ACCEPT='application/json')
        data = json.loads(response.content)
        self.assertEqual(data['distinct_count'], 6)
        self.assertEqual(data['record_count'], 6)

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

示例12: test_only_owner

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

        query2 = DataQuery()
        query2.save()

        # Ensure that there are 2 queries to start
        self.assertEqual(DataQuery.objects.count(), 2)

        response = self.client.get('/api/queries/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(len(json.loads(response.content)), 1)

        query = json.loads(response.content)[0]
        self.assertTrue(query['is_owner'])
        self.assertTrue('shared_users' in query)
开发者ID:rv816,项目名称:serrano_night,代码行数:19,代码来源:query.py

示例13: test_owner_and_shared

# 需要导入模块: from avocado.models import DataQuery [as 别名]
# 或者: from avocado.models.DataQuery import save [as 别名]
    def test_owner_and_shared(self):
        # Create a query this user owns
        query = DataQuery(user=self.user)
        query.save()

        # Create a query owned by and shared with no one
        query2 = DataQuery()
        query2.save()

        # Create a query with no owner but shared with this user
        query3 = DataQuery()
        query3.save()
        query3.shared_users.add(self.user)
        query3.save()

        self.assertEqual(DataQuery.objects.count(), 3)

        # Retrieve the queries shared with and owned by this user, the count
        # should be 2 since this user owns one and is the sharee on another.
        response = self.client.get('/api/queries/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(len(json.loads(response.content)), 2)

        # Verify that the order is descending based on accessed time. The 3rd
        # query was created most recently so it should be first in the list
        # over the 1st query.
        shared_queries = json.loads(response.content)
        self.assertEqual(shared_queries[0]['id'], query3.pk)
        self.assertEqual(shared_queries[1]['id'], query.pk)

        # Access the 1st query. This should make its accessed time update thus
        # making the 1st query the most recent of this users' shared queries.
        response = self.client.get('/api/queries/{0}/'.format(query.pk),
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)

        # Retrieve the queries shared with and owned by this user once again
        # to make sure the order has changed.
        response = self.client.get('/api/queries/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(len(json.loads(response.content)), 2)

        # Since the 1st query was just accessed, it should now be the first
        # query in the result followed by the 3rd query.
        shared_queries = json.loads(response.content)
        self.assertEqual(shared_queries[0]['id'], query.pk)
        self.assertEqual(shared_queries[1]['id'], query3.pk)

        # If we logout and submit the request without a user, there should
        # be 0 shared queries returned.
        self.client.logout()
        response = self.client.get('/api/queries/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(len(json.loads(response.content)), 0)
开发者ID:rv816,项目名称:serrano_night,代码行数:56,代码来源:query.py

示例14: test_add_shared_user

# 需要导入模块: from avocado.models import DataQuery [as 别名]
# 或者: from avocado.models.DataQuery import save [as 别名]
    def test_add_shared_user(self):
        # Make sure we are starting with the anticipated number of users.
        self.assertEqual(User.objects.count(), 1)

        # Assign an email to the existing user
        User.objects.all().update(email=self.existing_email)

        query = DataQuery(template=True, default=True)
        query.save()

        self.assertEqual(query.shared_users.count(), 0)

        [query.share_with_user(e) for e in self.emails]

        # Check that the user count increased for the email-based users
        self.assertEqual(User.objects.count(), 4)

        # Check that the users are in the query's shared_users
        self.assertEqual(query.shared_users.count(), 4)
开发者ID:hassanNS,项目名称:avocado,代码行数:21,代码来源:tests.py

示例15: test_get_session

# 需要导入模块: from avocado.models import DataQuery [as 别名]
# 或者: from avocado.models.DataQuery import save [as 别名]
    def test_get_session(self):
        # Make sure we have a session query.
        query = DataQuery(user=self.user, name='Query', session=True)
        query.save()

        # All results for session query.
        response = self.client.get('/api/async/queries/session/results/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(
            response.status_code, HttpResponseRedirect.status_code)
        normal_job_id = response['Location'].split('/')[-2]

        # Single page of results for session query.
        response = self.client.get('/api/async/queries/session/results/3/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(
            response.status_code, HttpResponseRedirect.status_code)
        paged_job_id = response['Location'].split('/')[-2]

        # Page range of results for session query.
        response = self.client.get('/api/async/queries/session/results/1...5/',
                                   HTTP_ACCEPT='application/json')
        self.assertEqual(
            response.status_code, HttpResponseRedirect.status_code)
        range_job_id = response['Location'].split('/')[-2]

        # The three requests above should have triggered 3 queued jobs.
        self.assertEqual(utils.get_job_count(), 3)
        for job_id in [normal_job_id, paged_job_id, range_job_id]:
            self.assert_job_status_equal(
                utils.get_job(job_id), 'queued')

        # Sleeping a couple seconds should leave plenty of time for the worker
        # to do its thing and finish up the three jobs from above.
        utils.run_jobs()
        time.sleep(3)

        # The three previous requests should now all be completed and their
        # items should match what we expect.
        for job_id in [normal_job_id, paged_job_id, range_job_id]:
            self.assert_job_status_equal(
                utils.get_job(job_id), 'finished')
            self.assert_job_result_equal(utils.get_job(job_id), [])
开发者ID:chop-dbhi,项目名称:serrano,代码行数:45,代码来源:query.py


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