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


Python models.DataQuery类代码示例

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


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

示例1: test_no_create_on_share

    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,代码行数:26,代码来源:tests.py

示例2: test_put

    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,代码行数:28,代码来源:query.py

示例3: test_count

    def test_count(self):
        c = DataConcept.objects.get(fields__model_name='title',
                                    fields__field_name='salary')

        json = {
            'context': {
                'field': 'tests.title.salary',
                'operator': 'gt',
                'value': '1000'
            },
            'view': [{
                'concept': c.id,
                'visible': True,
            }]
        }

        query = DataQuery(json)

        # Default tree is Employee so we should get 6 unique employee objects
        # regardless of distinct setting since all are distinct.
        self.assertEqual(query.count(), 6)
        self.assertEqual(query.count(distinct=False), 6)

        # Switching the tree should allow us to exercise the distinct keyword
        # since there are 3 titles all with the same 15,000 unit salary. We
        # need to eliminate the PK so that we are only getting salaries
        # back. Including the PK causes everything to be unique.
        self.assertEqual(query.count(tree='title', include_pk=False), 5)
        self.assertEqual(
            query.count(tree='title', include_pk=False, distinct=False), 7)
开发者ID:chop-dbhi,项目名称:avocado,代码行数:30,代码来源:tests.py

示例4: post

    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,代码行数:27,代码来源:query.py

示例5: test_get

    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,代码行数:8,代码来源:query.py

示例6: test_session

    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,代码行数:10,代码来源:query.py

示例7: test_get

    def test_get(self):
        query = DataQuery(user=self.user)
        query.save()

        child_query = DataQuery(name='Child 1', parent=query)
        child_query.save()
        child_query = DataQuery(name='Child 2', parent=query)
        child_query.save()

        url = '/api/queries/{0}/'.format(query.pk)
        response = self.client.get(url, HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertTrue(response.content)
        self.assertLess(query.accessed,
                DataQuery.objects.get(pk=query.pk).accessed)

        # When we access a query it should contain a valid link to the forks
        # of that query.
        data = json.loads(response.content)
        response = self.client.get(data['_links']['forks']['href'],
            HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.ok)
        self.assertTrue(response.content)
        self.assertEqual(len(json.loads(response.content)), 2)

        # Make sure we get a codes.not_found when accessing a query that
        # doesn't exist
        response = self.client.get('/api/queries/123456/',
            HTTP_ACCEPT='application/json')
        self.assertEqual(response.status_code, codes.not_found)
开发者ID:awenocur,项目名称:serrano,代码行数:30,代码来源:query.py

示例8: test_duplicate_share

    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,代码行数:15,代码来源:tests.py

示例9: test_processor

    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,代码行数:16,代码来源:query.py

示例10: test_add_shared_user

    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,代码行数:28,代码来源:tests.py

示例11: test_clean

    def test_clean(self):
        # Save default template
        query = DataQuery(template=True, default=True)
        query.save()

        # Save new template (not default)
        query2 = DataQuery(template=True)
        query2.save()

        # Try changing the second query to the default
        query2.default = True
        self.assertRaises(ValidationError, query2.save)

        query.save()
开发者ID:hassanNS,项目名称:avocado,代码行数:14,代码来源:tests.py

示例12: test_shared_users_count

    def test_shared_users_count(self):
        u1 = User(username='user1', email='[email protected]')
        u1.save()
        u2 = User(username='user2', email='[email protected]')
        u2.save()

        query = DataQuery(user=self.user)
        query.save()
        query.shared_users.add(u1)
        query.shared_users.add(u2)
        query.save()

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

        content = json.loads(response.content)[0]
        self.assertEqual(len(content['shared_users']), 2)

        u3 = User(username='user3', email='[email protected]')
        u3.save()
        u4 = User(username='user4', email='[email protected]')
        u4.save()

        query.shared_users.remove(u1)
        query.shared_users.add(u3)
        query.shared_users.add(u4)
        query.save()

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

        content = json.loads(response.content)[0]
        self.assertEqual(len(content['shared_users']), 3)
开发者ID:awenocur,项目名称:serrano,代码行数:35,代码来源:query.py

示例13: test_apply

    def test_apply(self):
        attrs = {
            'context': {
                'field': 'tests.title.boss',
                'operator': 'exact',
                'value': True
            },
            'view': {
                'columns': [1],
            }
        }
        query = DataQuery(attrs)

        self.assertEqual(unicode(query.apply(tree=Employee).query), 'SELECT DISTINCT "tests_employee"."id", "tests_office"."location", "tests_title"."name" FROM "tests_employee" INNER JOIN "tests_title" ON ("tests_employee"."title_id" = "tests_title"."id") INNER JOIN "tests_office" ON ("tests_employee"."office_id" = "tests_office"."id") WHERE "tests_title"."boss" = True ')

        query = DataQuery({'view': {'ordering': [(1, 'desc')]}})
        queryset = Employee.objects.all().distinct()
        self.assertEqual(unicode(query.apply(queryset=queryset).query), 'SELECT DISTINCT "tests_employee"."id", "tests_office"."location", "tests_title"."name" FROM "tests_employee" INNER JOIN "tests_office" ON ("tests_employee"."office_id" = "tests_office"."id") LEFT OUTER JOIN "tests_title" ON ("tests_employee"."title_id" = "tests_title"."id") ORDER BY "tests_office"."location" DESC, "tests_title"."name" DESC')
开发者ID:hassanNS,项目名称:avocado,代码行数:18,代码来源:tests.py

示例14: test_get_session

    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,代码行数:43,代码来源:query.py

示例15: test_add_shared_user

    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,代码行数:19,代码来源:tests.py


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