Пример #1
0
    def setUp(self):
        super(ReviewRequestAllDiffFilesChoiceTests, self).setUp()

        self.choice = ReviewRequestAllDiffFilesChoice()
        self.review_request = self.create_review_request(
            create_repository=True,
            publish=True)
        diffset = self.create_diffset(self.review_request)
        self.filediff1 = self.create_filediff(diffset, source_file='file1',
                                              dest_file='file1')
        self.filediff2 = self.create_filediff(diffset, source_file='file2',
                                              dest_file='file2')
Пример #2
0
    def setUp(self):
        super(ReviewRequestAllDiffFilesChoiceTests, self).setUp()

        self.choice = ReviewRequestAllDiffFilesChoice()
        self.review_request = self.create_review_request(
            create_repository=True,
            publish=True)
        diffset = self.create_diffset(self.review_request)
        self.filediff1 = self.create_filediff(diffset, source_file='file1',
                                              dest_file='file1')
        self.filediff2 = self.create_filediff(diffset, source_file='file2',
                                              dest_file='file2')
Пример #3
0
class ReviewRequestAllDiffFilesChoiceTests(TestCase):
    """Unit tests for ReviewRequestAllDiffFilesChoice."""

    fixtures = ['test_scmtools', 'test_users']

    def setUp(self):
        super(ReviewRequestAllDiffFilesChoiceTests, self).setUp()

        self.choice = ReviewRequestAllDiffFilesChoice()
        self.review_request = self.create_review_request(
            create_repository=True, publish=True)
        diffset = self.create_diffset(self.review_request)
        self.filediff1 = self.create_filediff(diffset,
                                              source_file='file1',
                                              dest_file='file1')
        self.filediff2 = self.create_filediff(diffset,
                                              source_file='file2',
                                              dest_file='file2')

    def test_get_match_value(self):
        """Testing ReviewRequestAllDiffFilesChoice.get_match_value"""
        self.assertEqual(self.choice.get_match_value(self.review_request, {}),
                         {'file1', 'file2'})

    def test_matches_with_is_op(self):
        """Testing ReviewRequestAllDiffFilesChoice.matches with "is" operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('is'), 'file1'),
        ])
        self.assertFalse(
            condition_set.matches(review_request=self.review_request))

        self.filediff2.delete()
        self.assertTrue(
            condition_set.matches(review_request=self.review_request))

    def test_matches_with_is_not_op(self):
        """Testing ReviewRequestAllDiffFilesChoice.matches with "is-not"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('is-not'),
                      'fileX'),
        ])
        self.assertTrue(
            condition_set.matches(review_request=self.review_request))

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('is-not'),
                      'file1'),
        ])
        self.assertFalse(
            condition_set.matches(review_request=self.review_request))

    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))

    def test_matches_with_does_not_contain_op(self):
        """Testing ReviewRequestAllDiffFilesChoice.matches with
        "does-not-contain" operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice,
                      self.choice.get_operator('does-not-contain'), '3'),
        ])
        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'), 'ile1'),
        ])
        self.assertFalse(
            condition_set.matches(review_request=self.review_request))

    def test_matches_with_starts_with_op(self):
        """Testing ReviewRequestAllDiffFilesChoice.matches with "starts-with"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('starts-with'),
                      'file'),
        ])
        self.assertTrue(
            condition_set.matches(review_request=self.review_request))

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('starts-with'),
                      'file1'),
        ])
        self.assertFalse(
            condition_set.matches(review_request=self.review_request))

    def test_matches_with_ends_with_op(self):
        """Testing ReviewRequestAllDiffFilesChoice.matches with "ends-with"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('ends-with'),
                      'le1'),
        ])
        self.assertFalse(
            condition_set.matches(review_request=self.review_request))

        self.filediff2.delete()
        self.assertTrue(
            condition_set.matches(review_request=self.review_request))

    def test_matches_with_matches_regex_op(self):
        """Testing ReviewRequestAllDiffFilesChoice.matches with "matches-regex"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('matches-regex'),
                      re.compile(r'^[Ff]ile\d$')),
        ])
        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('^[Ff]ile1$')),
        ])
        self.assertFalse(
            condition_set.matches(review_request=self.review_request))

    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))
Пример #4
0
class ReviewRequestAllDiffFilesChoiceTests(TestCase):
    """Unit tests for ReviewRequestAllDiffFilesChoice."""

    fixtures = ['test_scmtools', 'test_users']

    def setUp(self):
        super(ReviewRequestAllDiffFilesChoiceTests, self).setUp()

        self.choice = ReviewRequestAllDiffFilesChoice()
        self.review_request = self.create_review_request(
            create_repository=True,
            publish=True)
        diffset = self.create_diffset(self.review_request)
        self.filediff1 = self.create_filediff(diffset, source_file='file1',
                                              dest_file='file1')
        self.filediff2 = self.create_filediff(diffset, source_file='file2',
                                              dest_file='file2')

    def test_get_match_value(self):
        """Testing ReviewRequestAllDiffFilesChoice.get_match_value"""
        self.assertEqual(self.choice.get_match_value(self.review_request, {}),
                         {'file1', 'file2'})

    def test_matches_with_is_op(self):
        """Testing ReviewRequestAllDiffFilesChoice.matches with "is" operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('is'), 'file1'),
        ])
        self.assertFalse(condition_set.matches(
            review_request=self.review_request))

        self.filediff2.delete()
        self.assertTrue(condition_set.matches(
            review_request=self.review_request))

    def test_matches_with_is_not_op(self):
        """Testing ReviewRequestAllDiffFilesChoice.matches with "is-not"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('is-not'),
                      'fileX'),
        ])
        self.assertTrue(condition_set.matches(
            review_request=self.review_request))

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('is-not'),
                      'file1'),
        ])
        self.assertFalse(condition_set.matches(
            review_request=self.review_request))

    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))

    def test_matches_with_does_not_contain_op(self):
        """Testing ReviewRequestAllDiffFilesChoice.matches with
        "does-not-contain" operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice,
                      self.choice.get_operator('does-not-contain'),
                      '3'),
        ])
        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'),
                      'ile1'),
        ])
        self.assertFalse(condition_set.matches(
            review_request=self.review_request))

    def test_matches_with_starts_with_op(self):
        """Testing ReviewRequestAllDiffFilesChoice.matches with "starts-with"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('starts-with'),
                      'file'),
        ])
        self.assertTrue(condition_set.matches(
            review_request=self.review_request))

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('starts-with'),
                      'file1'),
        ])
        self.assertFalse(condition_set.matches(
            review_request=self.review_request))

    def test_matches_with_ends_with_op(self):
        """Testing ReviewRequestAllDiffFilesChoice.matches with "ends-with"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('ends-with'),
                      'le1'),
        ])
        self.assertFalse(condition_set.matches(
            review_request=self.review_request))

        self.filediff2.delete()
        self.assertTrue(condition_set.matches(
            review_request=self.review_request))

    def test_matches_with_matches_regex_op(self):
        """Testing ReviewRequestAllDiffFilesChoice.matches with "matches-regex"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('matches-regex'),
                      re.compile(r'^[Ff]ile\d$')),
        ])
        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('^[Ff]ile1$')),
        ])
        self.assertFalse(condition_set.matches(
            review_request=self.review_request))

    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))