Ejemplo n.º 1
0
    def test_matches_with_is_op(self):
        """Testing ReviewRequestAnyDiffFileChoice.matches with "is" operator"""
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('is'), 'file2'),
        ])
        self.assertTrue(
            condition_set.matches(review_request=self.review_request))

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('is'), 'fileX'),
        ])
        self.assertFalse(
            condition_set.matches(review_request=self.review_request))
Ejemplo n.º 2
0
    def test_matches_with_contains_op(self):
        """Testing ReviewRequestAllDiffFilesChoice.matches with "contains"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('contains'),
                      'file'),
        ])
        self.assertTrue(
            condition_set.matches(review_request=self.review_request))

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('contains'), '1'),
        ])
        self.assertFalse(
            condition_set.matches(review_request=self.review_request))
Ejemplo n.º 3
0
    def _create_config(self, with_local_site=False):
        """Create an integration config.

        Args:
            with_local_site (bool):
                Whether to limit the config to a local site.
        """
        choice = ReviewRequestRepositoriesChoice()

        condition_set = ConditionSet(conditions=[
            Condition(choice=choice,
                      operator=choice.get_operator('any'))
        ])

        if with_local_site:
            local_site = self.get_local_site(name=self.local_site_name)
        else:
            local_site = None

        config = self.integration.create_config(name='Config 1',
                                                enabled=True,
                                                local_site=local_site)
        config.set('conditions', condition_set.serialize())
        config.set('branch_name', 'review-requests')
        config.save()

        return config
Ejemplo n.º 4
0
    def test_matches_with_does_not_contain_op(self):
        """Testing ReviewRequestAnyDiffFileChoice.matches with
        "does-not-contain" operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice,
                      self.choice.get_operator('does-not-contain'), 'xyz'),
        ])
        self.assertTrue(
            condition_set.matches(review_request=self.review_request))

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice,
                      self.choice.get_operator('does-not-contain'), 'file'),
        ])
        self.assertFalse(
            condition_set.matches(review_request=self.review_request))
Ejemplo n.º 5
0
    def test_matches_with_ends_with_op(self):
        """Testing ReviewRequestAnyDiffFileChoice.matches with "ends-with"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('ends-with'),
                      'le1'),
        ])
        self.assertTrue(
            condition_set.matches(review_request=self.review_request))

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('ends-with'),
                      'xyz'),
        ])
        self.assertFalse(
            condition_set.matches(review_request=self.review_request))
Ejemplo n.º 6
0
    def test_matches_with_matches_regex_op(self):
        """Testing ReviewRequestAnyDiffFileChoice.matches with "matches-regex"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('matches-regex'),
                      re.compile(r'^[Ff]ile1$')),
        ])
        self.assertTrue(
            condition_set.matches(review_request=self.review_request))

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('matches-regex'),
                      re.compile('^\d')),
        ])
        self.assertFalse(
            condition_set.matches(review_request=self.review_request))
Ejemplo n.º 7
0
    def test_matches_with_none_op(self):
        """Testing RepositoriesChoice.matches with "none" operator"""
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('none')),
        ])

        self.assertTrue(condition_set.matches(repository=None))
        self.assertFalse(condition_set.matches(
            repository=self.create_repository()))
Ejemplo n.º 8
0
    def test_matches_with_does_not_match_regex_op(self):
        """Testing ReviewRequestAllDiffFilesChoice.matches with
        "does-not-match-regex" operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice,
                      self.choice.get_operator('does-not-match-regex'),
                      re.compile(r'^[Ff]ile3$')),
        ])
        self.assertTrue(
            condition_set.matches(review_request=self.review_request))

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice,
                      self.choice.get_operator('does-not-match-regex'),
                      re.compile('[Ff]ile1')),
        ])
        self.assertFalse(
            condition_set.matches(review_request=self.review_request))
Ejemplo n.º 9
0
    def test_matches_with_is_private_op(self):
        """Testing RepositoriesChoice.matches with "is-private" operator"""
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('is-private')),
        ])

        self.assertTrue(condition_set.matches(
            repository=self.create_repository(name='repo1', public=False)))
        self.assertFalse(condition_set.matches(
            repository=self.create_repository(name='repo2', public=True)))
Ejemplo n.º 10
0
    def test_matches_with_any_op(self):
        """Testing ReviewRequestRepositoriesChoice.matches with "any" operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('any')),
        ])

        self.assertTrue(condition_set.matches(
            review_request=self.create_review_request(create_repository=True)))
        self.assertFalse(condition_set.matches(
            review_request=self.create_review_request()))
Ejemplo n.º 11
0
    def test_matches_with_none_op(self):
        """Testing ReviewGroupsChoice.matches with "none" operator"""
        self.create_review_group(name='group1')

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('none')),
        ])

        self.assertTrue(
            condition_set.matches(review_groups=Group.objects.none()))
        self.assertFalse(
            condition_set.matches(review_groups=Group.objects.all()))
Ejemplo n.º 12
0
    def test_matches_with_not_one_of_op(self):
        """Testing RepositoriesChoice.matches with "not-one-of" operator"""
        repository1 = self.create_repository(name='repo1')
        repository2 = self.create_repository(name='repo2')
        repository3 = self.create_repository(name='repo3')

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('not-one-of'),
                      [repository1, repository2])
        ])

        self.assertFalse(condition_set.matches(repository=repository1))
        self.assertFalse(condition_set.matches(repository=repository2))
        self.assertTrue(condition_set.matches(repository=repository3))
Ejemplo n.º 13
0
    def test_matches_with_none_op(self):
        """Testing ReviewRequestReviewGroupsChoice.matches with "none" operator
        """
        group = self.create_review_group(name='group1')

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('none')),
        ])

        review_request = self.create_review_request()
        self.assertTrue(condition_set.matches(review_request=review_request))

        review_request.target_groups = [group]
        self.assertFalse(condition_set.matches(review_request=review_request))
Ejemplo n.º 14
0
    def test_matches_with_any_public_op(self):
        """Testing ReviewGroupsChoice.matches with "any-public" operator"""
        group1 = self.create_review_group(name='group1', invite_only=False)
        group2 = self.create_review_group(name='group2', invite_only=True)

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('any-public')),
        ])

        self.assertTrue(condition_set.matches(
            review_groups=Group.objects.filter(pk=group1.pk)))
        self.assertFalse(condition_set.matches(
            review_groups=Group.objects.filter(pk=group2.pk)))
        self.assertFalse(condition_set.matches(
            review_groups=Group.objects.none()))
Ejemplo n.º 15
0
    def test_matches_with_contains_any_op(self):
        """Testing ReviewRequestParticipantChoice.matches with "contains-any"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('contains-any'),
                      [self.user1, self.user2]),
        ])

        review_request = self.create_review_request()
        self.assertFalse(condition_set.matches(review_request=review_request))

        review_request = self.create_review_request()
        self.create_review(review_request, user=self.user1, public=True)
        self.assertTrue(condition_set.matches(review_request=review_request))
Ejemplo n.º 16
0
    def test_matches_with_not_one_of_op(self):
        """Testing RepositoryTypeChoice.matches with "not-one-of" operator"""
        repository1 = self.create_repository(name='repo1', tool_name='Git')
        repository2 = self.create_repository(name='repo2',
                                             tool_name='Subversion')
        repository3 = self.create_repository(name='repo3', tool_name='CVS')

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('not-one-of'),
                      [repository1.tool, repository2.tool])
        ])

        self.assertFalse(condition_set.matches(repository=repository1))
        self.assertFalse(condition_set.matches(repository=repository2))
        self.assertTrue(condition_set.matches(repository=repository3))
Ejemplo n.º 17
0
    def test_matches_with_not_one_of_op(self):
        """Testing ReviewRequestOwnerChoice.matches with "not-one-of"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice,
                      self.choice.get_operator('not-one-of'),
                      [self.user1, self.user2]),
        ])

        self.assertFalse(condition_set.matches(
            review_request=self.create_review_request(submitter=self.user1)))
        self.assertFalse(condition_set.matches(
            review_request=self.create_review_request(submitter=self.user2)))
        self.assertTrue(condition_set.matches(
            review_request=self.create_review_request(submitter=self.user3)))
Ejemplo n.º 18
0
    def test_matches_with_contains_any_op(self):
        """Testing ReviewGroupsChoice.matches with "contains-any" operator"""
        group1 = self.create_review_group(name='group1')
        group2 = self.create_review_group(name='group2')
        group3 = self.create_review_group(name='group3')

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('contains-any'),
                      [group1, group2])
        ])

        self.assertTrue(condition_set.matches(
            review_groups=Group.objects.filter(pk=group1.pk)))
        self.assertFalse(condition_set.matches(
            review_groups=Group.objects.filter(pk=group3.pk)))
        self.assertFalse(condition_set.matches(
            review_groups=Group.objects.none()))
Ejemplo n.º 19
0
    def test_matches_with_contains_any_op(self):
        """Testing ReviewRequestReviewerChoice.matches with
        "contains-any" operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('contains-any'),
                      [self.user1, self.user2]),
        ])

        review_request = self.create_review_request(target_people=[self.user1])
        self.assertTrue(condition_set.matches(review_request=review_request))

        review_request = self.create_review_request(target_people=[self.user2])
        self.assertTrue(condition_set.matches(review_request=review_request))

        review_request = self.create_review_request(target_people=[self.user3])
        self.assertFalse(condition_set.matches(review_request=review_request))
Ejemplo n.º 20
0
    def test_matches_with_any_public_op(self):
        """Testing ReviewRequestReviewGroupsChoice.matches with "any-public"
        operator"""
        group1 = self.create_review_group(name='group1', invite_only=False)
        group2 = self.create_review_group(name='group2', invite_only=True)

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('any-public')),
        ])

        review_request = self.create_review_request()
        review_request.target_groups = [group1]
        self.assertTrue(condition_set.matches(review_request=review_request))

        review_request.target_groups = [group2]
        self.assertFalse(condition_set.matches(review_request=review_request))

        review_request.target_groups = []
        self.assertFalse(condition_set.matches(review_request=review_request))
Ejemplo n.º 21
0
    def test_matches_with_does_not_contain_any_op(self):
        """Testing ReviewRequestReviewGroupsChoice.matches with
        "does-not-contain-any" operator
        """
        group1 = self.create_review_group(name='group1')
        group2 = self.create_review_group(name='group2')
        group3 = self.create_review_group(name='group3')

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice,
                      self.choice.get_operator('does-not-contain-any'),
                      [group1, group2])
        ])

        review_request = self.create_review_request()
        self.assertTrue(condition_set.matches(review_request=review_request))

        review_request.target_groups = [group3]
        self.assertTrue(condition_set.matches(review_request=review_request))

        review_request.target_groups = [group1]
        self.assertFalse(condition_set.matches(review_request=review_request))
Ejemplo n.º 22
0
    def _create_config(self, enterprise=False, with_local_site=False):
        """Create an integration config.

        Args:
            enterprise (bool, optional):
                Whether to use an enterprise endpoint or the default
                open-source endpoint.

            with_local_site (bool, optional):
                Whether to limit the config to a local site.
        """
        choice = ReviewRequestRepositoriesChoice()

        condition_set = ConditionSet(conditions=[
            Condition(choice=choice,
                      operator=choice.get_operator('any'))
        ])

        if with_local_site:
            local_site = self.get_local_site(name=self.local_site_name)
        else:
            local_site = None

        config = self.integration.create_config(name='Config 1',
                                                enabled=True,
                                                local_site=local_site)
        config.set('conditions', condition_set.serialize())
        config.set('travis_yml', 'script:\n    python ./tests/runtests.py')
        config.set('branch_name', 'review-requests')

        if enterprise:
            config.set('travis_endpoint', TravisAPI.ENTERPRISE_ENDPOINT)
            config.set('travis_custom_endpoint', 'https://travis.example.com/')
        else:
            config.set('travis_endpoint', TravisAPI.OPEN_SOURCE_ENDPOINT)

        config.save()

        return config