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

        self.choice = ReviewRequestAnyDiffFileChoice()
        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(ReviewRequestAnyDiffFileChoiceTests, self).setUp()

        self.choice = ReviewRequestAnyDiffFileChoice()
        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 ReviewRequestAnyDiffFileChoiceTests(TestCase):
    """Unit tests for ReviewRequestAnyDiffFileChoice."""

    fixtures = ['test_scmtools', 'test_users']

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

        self.choice = ReviewRequestAnyDiffFileChoice()
        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 ReviewRequestAnyDiffFileChoice.get_match_value"""
        self.assertEqual(self.choice.get_match_value(self.review_request, {}),
                         {'file1', 'file2'})

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

    def test_matches_with_is_not_op(self):
        """Testing ReviewRequestAnyDiffFileChoice.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.assertTrue(
            condition_set.matches(review_request=self.review_request))

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

    def test_matches_with_contains_op(self):
        """Testing ReviewRequestAnyDiffFileChoice.matches with "contains"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('contains'), '1'),
        ])
        self.assertTrue(
            condition_set.matches(review_request=self.review_request))

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('contains'), '3'),
        ])
        self.assertFalse(
            condition_set.matches(review_request=self.review_request))

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

    def test_matches_with_starts_with_op(self):
        """Testing ReviewRequestAnyDiffFileChoice.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'),
                      'ile'),
        ])
        self.assertFalse(
            condition_set.matches(review_request=self.review_request))

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

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

    def test_matches_with_does_not_match_regex_op(self):
        """Testing ReviewRequestAnyDiffFileChoice.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'^\d')),
        ])
        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]ile\d')),
        ])
        self.assertFalse(
            condition_set.matches(review_request=self.review_request))
Пример #4
0
class ReviewRequestAnyDiffFileChoiceTests(TestCase):
    """Unit tests for ReviewRequestAnyDiffFileChoice."""

    fixtures = ['test_scmtools', 'test_users']

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

        self.choice = ReviewRequestAnyDiffFileChoice()
        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 ReviewRequestAnyDiffFileChoice.get_match_value"""
        self.assertEqual(self.choice.get_match_value(self.review_request, {}),
                         {'file1', 'file2'})

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

    def test_matches_with_is_not_op(self):
        """Testing ReviewRequestAnyDiffFileChoice.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.assertTrue(condition_set.matches(
            review_request=self.review_request))

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

    def test_matches_with_contains_op(self):
        """Testing ReviewRequestAnyDiffFileChoice.matches with "contains"
        operator
        """
        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('contains'),
                      '1'),
        ])
        self.assertTrue(condition_set.matches(
            review_request=self.review_request))

        condition_set = ConditionSet(ConditionSet.MODE_ALL, [
            Condition(self.choice, self.choice.get_operator('contains'),
                      '3'),
        ])
        self.assertFalse(condition_set.matches(
            review_request=self.review_request))

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

    def test_matches_with_starts_with_op(self):
        """Testing ReviewRequestAnyDiffFileChoice.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'),
                      'ile'),
        ])
        self.assertFalse(condition_set.matches(
            review_request=self.review_request))

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

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

    def test_matches_with_does_not_match_regex_op(self):
        """Testing ReviewRequestAnyDiffFileChoice.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'^\d')),
        ])
        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]ile\d')),
        ])
        self.assertFalse(condition_set.matches(
            review_request=self.review_request))