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()))
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)))
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()))
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_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()))
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_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()))
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))
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))
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()))
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))
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_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))
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)))
def test_matches_with_not_one_of_op(self): """Testing ReviewRequestSubmitterChoice.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)))
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_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_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_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()))
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_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_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))
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_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 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_does_not_contain_any_op(self): """Testing ReviewRequestReviewerChoice.matches with "does-not-contain-any" operator """ condition_set = ConditionSet(ConditionSet.MODE_ALL, [ Condition(self.choice, self.choice.get_operator('does-not-contain-any'), [self.user1, self.user2]), ]) review_request = self.create_review_request(target_people=[self.user1]) self.assertFalse(condition_set.matches(review_request=review_request)) review_request = self.create_review_request(target_people=[self.user2]) self.assertFalse(condition_set.matches(review_request=review_request)) review_request = self.create_review_request(target_people=[self.user3]) self.assertTrue(condition_set.matches(review_request=review_request))
def test_matches_with_does_not_contain_any_op(self): """Testing ReviewRequestParticipantChoice.matches with "does-not-contain-any" operator """ condition_set = ConditionSet(ConditionSet.MODE_ALL, [ Condition(self.choice, self.choice.get_operator('does-not-contain-any'), [self.user1, self.user2]), ]) review_request = self.create_review_request() self.assertTrue(condition_set.matches(review_request=review_request)) review_request = self.create_review_request() self.create_review(review_request, user=self.user1, public=True) self.assertFalse(condition_set.matches(review_request=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))
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))
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))
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_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))