コード例 #1
0
    def test_clone(self):
        """Testing LocalDataQuerySet.clone"""
        values = [1, 2, 3]
        queryset = LocalDataQuerySet(values)
        clone = queryset.clone()

        self.assertEqual(list(clone), values)
        values.append(4)
        self.assertNotEqual(list(clone), values)
コード例 #2
0
ファイル: tests.py プロジェクト: CptJason/djblets
    def test_clone(self):
        """Testing LocalDataQuerySet.clone"""
        values = [1, 2, 3]
        queryset = LocalDataQuerySet(values)
        clone = queryset.clone()

        self.assertEqual(list(clone), values)
        values.append(4)
        self.assertNotEqual(list(clone), values)
コード例 #3
0
ファイル: tests.py プロジェクト: CptJason/djblets
    def test_get_with_filters(self):
        """Testing LocalDataQuerySet.get with filters"""
        obj1 = Mock()
        obj1.a = 1

        obj2 = Mock()
        obj2.a = 2

        queryset = LocalDataQuerySet([obj1, obj2])

        self.assertEqual(queryset.get(a=1), obj1)
コード例 #4
0
    def test_get_with_filters(self):
        """Testing LocalDataQuerySet.get with filters"""
        obj1 = Mock()
        obj1.a = 1

        obj2 = Mock()
        obj2.a = 2

        queryset = LocalDataQuerySet([obj1, obj2])

        self.assertEqual(queryset.get(a=1), obj1)
コード例 #5
0
ファイル: tests.py プロジェクト: CptJason/djblets
    def test_exclude(self):
        """Testing LocalDataQuerySet.exclude"""
        obj1 = Mock()
        obj1.a = 1
        obj1.b = 2

        obj2 = Mock()
        obj2.a = 10
        obj2.b = 20

        queryset = LocalDataQuerySet([obj1, obj2])
        queryset = queryset.exclude(a=1)

        self.assertEqual(len(queryset), 1)
        self.assertEqual(queryset[0], obj2)
コード例 #6
0
    def test_exclude(self):
        """Testing LocalDataQuerySet.exclude"""
        obj1 = Mock()
        obj1.a = 1
        obj1.b = 2

        obj2 = Mock()
        obj2.a = 10
        obj2.b = 20

        queryset = LocalDataQuerySet([obj1, obj2])
        queryset = queryset.exclude(a=1)

        self.assertEqual(len(queryset), 1)
        self.assertEqual(queryset[0], obj2)
コード例 #7
0
    def get_queryset(self,
                     request,
                     start=None,
                     is_list=False,
                     repository_id=None,
                     *args,
                     **kwargs):
        account = resources.hosting_service_account.get_object(
            request, *args, **kwargs)

        if is_list:
            # Wrap the paginator in a LocalDataQuerySet, so that we can get
            # to it later in RemoteRepositoryResponsePaginated.
            lookup_kwargs = {}

            for name in ('owner', 'owner-type', 'filter-type'):
                if kwargs.get(name):
                    arg = name.replace('-', '_')
                    lookup_kwargs[arg] = kwargs[name]

            result = account.service.get_remote_repositories(start=start,
                                                             **lookup_kwargs)
        else:
            result = account.service.get_remote_repository(repository_id)

        return LocalDataQuerySet([result])
コード例 #8
0
    def test_get_with_multiple_results(self):
        """Testing LocalDataQuerySet.get with multiple results"""
        obj1 = Mock()
        obj2 = Mock()

        queryset = LocalDataQuerySet([obj1, obj2])

        self.assertRaises(MultipleObjectsReturned, queryset.get)
コード例 #9
0
    def test_iter(self):
        """Testing LocalDataQuerySet.__iter__"""
        values = [1, 2]
        queryset = LocalDataQuerySet(values)
        gen = iter(queryset)

        self.assertEqual(next(gen), 1)
        self.assertEqual(next(gen), 2)
コード例 #10
0
    def test_filter_with_multiple_args(self):
        """Testing LocalDataQuerySet.filter with multiple arguments"""
        obj1 = Mock()
        obj1.a = 1
        obj1.b = 2

        obj2 = Mock()
        obj2.a = 1
        obj2.b = 20

        obj3 = Mock()
        obj3.a = 2
        obj3.b = 20

        queryset = LocalDataQuerySet([obj1, obj2, obj3])
        queryset = queryset.filter(a=1, b=20)

        self.assertEqual(len(queryset), 1)
        self.assertEqual(queryset[0], obj2)
コード例 #11
0
    def test_filter(self):
        """Testing LocalDataQuerySet.filter"""
        obj1 = Mock()
        obj1.a = 1
        obj1.b = 2

        obj2 = Mock()
        obj2.a = 10
        obj2.b = 20

        obj3 = Mock()
        obj3.a = 1
        obj3.b = 40

        queryset = LocalDataQuerySet([obj1, obj2, obj3])
        queryset = queryset.filter(a=1)

        self.assertEqual(len(queryset), 2)
        self.assertEqual(list(queryset), [obj1, obj3])
コード例 #12
0
    def test_exclude_with_multiple_args(self):
        """Testing LocalDataQuerySet.exclude with multiple arguments"""
        obj1 = Mock()
        obj1.a = 1
        obj1.b = 2

        obj2 = Mock()
        obj2.a = 1
        obj2.b = 20

        obj3 = Mock()
        obj3.a = 1
        obj3.b = 40

        queryset = LocalDataQuerySet([obj1, obj2, obj3])
        queryset = queryset.exclude(a=1, b=20)

        self.assertEqual(len(queryset), 2)
        self.assertEqual(list(queryset), [obj1, obj3])
コード例 #13
0
ファイル: tests.py プロジェクト: CptJason/djblets
    def test_exclude_with_multiple_args(self):
        """Testing LocalDataQuerySet.exclude with multiple arguments"""
        obj1 = Mock()
        obj1.a = 1
        obj1.b = 2

        obj2 = Mock()
        obj2.a = 1
        obj2.b = 20

        obj3 = Mock()
        obj3.a = 1
        obj3.b = 40

        queryset = LocalDataQuerySet([obj1, obj2, obj3])
        queryset = queryset.exclude(a=1, b=20)

        self.assertEqual(len(queryset), 2)
        self.assertEqual(list(queryset), [obj1, obj3])
コード例 #14
0
ファイル: tests.py プロジェクト: CptJason/djblets
    def test_filter(self):
        """Testing LocalDataQuerySet.filter"""
        obj1 = Mock()
        obj1.a = 1
        obj1.b = 2

        obj2 = Mock()
        obj2.a = 10
        obj2.b = 20

        obj3 = Mock()
        obj3.a = 1
        obj3.b = 40

        queryset = LocalDataQuerySet([obj1, obj2, obj3])
        queryset = queryset.filter(a=1)

        self.assertEqual(len(queryset), 2)
        self.assertEqual(list(queryset), [obj1, obj3])
コード例 #15
0
ファイル: tests.py プロジェクト: CptJason/djblets
    def test_filter_with_multiple_args(self):
        """Testing LocalDataQuerySet.filter with multiple arguments"""
        obj1 = Mock()
        obj1.a = 1
        obj1.b = 2

        obj2 = Mock()
        obj2.a = 1
        obj2.b = 20

        obj3 = Mock()
        obj3.a = 2
        obj3.b = 20

        queryset = LocalDataQuerySet([obj1, obj2, obj3])
        queryset = queryset.filter(a=1, b=20)

        self.assertEqual(len(queryset), 1)
        self.assertEqual(queryset[0], obj2)
コード例 #16
0
    def test_get_with_no_results(self):
        """Testing LocalDataQuerySet.get with no results"""
        obj1 = Mock()
        obj1.a = 1

        obj2 = Mock()
        obj2.a = 1

        queryset = LocalDataQuerySet([obj1, obj2])

        self.assertRaises(ObjectDoesNotExist, queryset.get, a=2)
コード例 #17
0
    def get_queryset(self, request, is_list=False, *args, **kwargs):
        """Returns a queryset for ToolExecution models.

        By default, this returns all tool executions.

        If the queryset is being used for a list of tool execution resources,
        this is filtered for tool executions matching the given review request
        ID and diff revision arguments. This can be further filtered by the
        optional arguments.
        """
        if is_list:
            review_request_id = request.GET.get('review-request-id')
            diff_revision = request.GET.get('diff-revision')

            q = Q()

            if 'status' in request.GET:
                statuses = request.GET.get('status').split(',')

                for status in statuses:
                    if status in (u'Q', u'R', u'S', u'F', u'T'):
                        q = q | Q(status=status)

            queryset = self.model.objects.filter(
                q,
                review_request_id=review_request_id,
                diff_revision=diff_revision)

            if 'get-latest' in request.GET:
                get_latest = request.GET.get('get-latest')

                if get_latest in ('1', 'true', 'True'):
                    # Get the last-updated tool executions for unique profiles.
                    # This will be used to display the status of each executed
                    # tool profile in the manual execution UI.
                    # Note: We cannot use distinct(profile__id) since it is
                    # only supported on PostgreSQL. Instead, we make use of the
                    # fact that ToolExecution objects are ordered by
                    # last_updated descending.
                    profiles = set()
                    tool_executions = []

                    for tool_execution in queryset:
                        profile = tool_execution.profile.id

                        if profile not in profiles:
                            profiles.add(profile)
                            tool_executions.append(tool_execution)

                    queryset = LocalDataQuerySet(tool_executions)

            return queryset
        else:
            return self.model.objects.all()
コード例 #18
0
    def test_order_by(self):
        """Testing LocalDataQuerySet.order_by"""
        obj1 = TestObjectsForOrder(2, 'first', 'string', 0)
        obj2 = TestObjectsForOrder(1, 'second', 'string', 0)
        obj3 = TestObjectsForOrder(4, 'test', 'string', 3)
        obj4 = TestObjectsForOrder(1, 'first', 'string', 0)
        obj5 = TestObjectsForOrder(2, 'second', 'string', 0)
        obj6 = TestObjectsForOrder(4, 'test', 'string', 0)
        obj7 = TestObjectsForOrder(2, 'third', 'string', 0)

        data = [obj1, obj2, obj3, obj4, obj5, obj6, obj7]
        answer = [obj2, obj4, obj7, obj5, obj1, obj3, obj6]

        queryset = LocalDataQuerySet(data).order_by('param1', '-param4',
                                                    '-param2')

        self.assertEqual(len(queryset._data), len(answer))

        for i in range(len(data)):
            self.assertEqual(queryset._data[i], answer[i])
コード例 #19
0
ファイル: tests.py プロジェクト: CptJason/djblets
    def test_count(self):
        """Testing LocalDataQuerySet.count"""
        values = [1, 2, 3]
        queryset = LocalDataQuerySet(values)

        self.assertEqual(queryset.count(), 3)
コード例 #20
0
    def test_count(self):
        """Testing LocalDataQuerySet.count"""
        values = [1, 2, 3]
        queryset = LocalDataQuerySet(values)

        self.assertEqual(queryset.count(), 3)
コード例 #21
0
    def test_len(self):
        """Testing LocalDataQuerySet.__len__"""
        values = [1, 2, 3]
        queryset = LocalDataQuerySet(values)

        self.assertEqual(len(queryset), 3)
コード例 #22
0
    def test_getslice(self):
        """Testing LocalDataQuerySet.__getitem__"""
        values = [1, 2, 3]
        queryset = LocalDataQuerySet(values)

        self.assertEqual(queryset[1:3], [2, 3])
コード例 #23
0
 def get_queryset(self, request, *args, **kwargs):
     return LocalDataQuerySet(get_hosting_services())
コード例 #24
0
    def test_get(self):
        """Testing LocalDataQuerySet.get"""
        obj1 = Mock()
        queryset = LocalDataQuerySet([obj1])

        self.assertEqual(queryset.get(), obj1)
コード例 #25
0
    def test_contains(self):
        """Testing LocalDataQuerySet.__contains__"""
        values = [1, 2, 3]
        queryset = LocalDataQuerySet(values)

        self.assertIn(2, queryset)
コード例 #26
0
ファイル: tests.py プロジェクト: CptJason/djblets
    def test_get(self):
        """Testing LocalDataQuerySet.get"""
        obj1 = Mock()
        queryset = LocalDataQuerySet([obj1])

        self.assertEqual(queryset.get(), obj1)