<commit_before>from django.contrib.auth.models import User
from django.test import TestCase

from mrbelvedereci.repository.models import Repository
from mrbelvedereci.plan.models import Plan


class PlanTestCase(TestCase):

    def setUp(self):
        self.repo = Repository(
            name = 'TestRepo',
            owner = 'TestOwner',
            url = 'https://github.com/TestOwner/TestRepo'
        )
        self.commit_plan = Plan(
            name = 'Test Plan',
            repo = self.repo, 
            type = 'commit',
            regex = 'test/.*',
            flows = 'test_flow',
            org = 'test_org',
            context = 'test case'
        )
        self.tag_plan = Plan(
            name = 'Test Plan',
            repo = self.repo, 
            type = 'tag',
            regex = 'test/.*',
            flows = 'test_flow',
            org = 'test_org',
            context = 'test case'
        )

    def test_check_push_commit_matches(self):
        push = {
            'ref': 'refs/heads/test/matches',
            'after': '0123456789',
        }
        run_build, commit = self.commit_plan.check_push(push)
        self.assertTrue(run_build)
        self.assertEquals(commit, push['after'])

    def test_check_push_commit_does_not_match(self):
        push = {
            'ref': 'refs/heads/no-match',
        }
        run_build, commit = self.commit_plan.check_push(push)
        self.assertFalse(run_build)
        self.assertEquals(commit, None)

    def test_check_push_commit_tag_event(self):
        push = {
            'ref': 'refs/tags/test/matches',
            'head_commit': None,
        }
        run_build, commit = self.commit_plan.check_push(push)
        self.assertFalse(run_build)
        self.assertEquals(commit, None)

    def test_check_push_tag_matches(self):
        push = {
            'ref': 'refs/tags/test/matches',
            'before': '0123456789',
            'head_commit': None,
        }
        run_build, commit = self.tag_plan.check_push(push)
        self.assertTrue(run_build)
        self.assertEquals(commit, push['before'])

    def test_check_push_tag_does_not_match(self):
        push = {
            'ref': 'refs/tags/no-match',
            'head_commit': None,
        }
        run_build, commit = self.tag_plan.check_push(push)
        self.assertFalse(run_build)
        self.assertEquals(commit, None)

    def test_check_push_tag_commit_event(self):
        push = {
            'ref': 'refs/heads/test/matches',
            'head_commit': None,
        }
        run_build, commit = self.tag_plan.check_push(push)
        self.assertFalse(run_build)
        self.assertEquals(commit, None)
<commit_msg>fix tests broken by f122fbfd12dc9d19972c711c972378eaa3f52e10<commit_after>from django.contrib.auth.models import User
from django.test import TestCase

from mrbelvedereci.repository.models import Repository
from mrbelvedereci.plan.models import Plan


class PlanTestCase(TestCase):

    def setUp(self):
        self.repo = Repository(
            name = 'TestRepo',
            owner = 'TestOwner',
            url = 'https://github.com/TestOwner/TestRepo'
        )
        self.commit_plan = Plan(
            name = 'Test Plan',
            repo = self.repo, 
            type = 'commit',
            regex = 'test/.*',
            flows = 'test_flow',
            org = 'test_org',
            context = 'test case'
        )
        self.tag_plan = Plan(
            name = 'Test Plan',
            repo = self.repo, 
            type = 'tag',
            regex = 'test/.*',
            flows = 'test_flow',
            org = 'test_org',
            context = 'test case'
        )

    def test_check_push_commit_matches(self):
        push = {
            'ref': 'refs/heads/test/matches',
            'after': '0123456789',
        }
        run_build, commit, commit_message = self.commit_plan.check_push(push)
        self.assertTrue(run_build)
        self.assertEquals(commit, push['after'])

    def test_check_push_commit_does_not_match(self):
        push = {
            'ref': 'refs/heads/no-match',
        }
        run_build, commit, commit_message = self.commit_plan.check_push(push)
        self.assertFalse(run_build)
        self.assertEquals(commit, None)

    def test_check_push_commit_tag_event(self):
        push = {
            'ref': 'refs/tags/test/matches',
            'head_commit': None,
        }
        run_build, commit, commit_message = self.commit_plan.check_push(push)
        self.assertFalse(run_build)
        self.assertEquals(commit, None)

    def test_check_push_tag_matches(self):
        push = {
            'ref': 'refs/tags/test/matches',
            'before': '0123456789',
            'head_commit': None,
        }
        run_build, commit, commit_message = self.tag_plan.check_push(push)
        self.assertTrue(run_build)
        self.assertEquals(commit, push['before'])

    def test_check_push_tag_does_not_match(self):
        push = {
            'ref': 'refs/tags/no-match',
            'head_commit': None,
        }
        run_build, commit, commit_message = self.tag_plan.check_push(push)
        self.assertFalse(run_build)
        self.assertEquals(commit, None)

    def test_check_push_tag_commit_event(self):
        push = {
            'ref': 'refs/heads/test/matches',
            'head_commit': None,
        }
        run_build, commit, commit_message = self.tag_plan.check_push(push)
        self.assertFalse(run_build)
        self.assertEquals(commit, None)

{'fraction_non_alphanumeric': 0.1121731289449955, 'fraction_numerical': 0.011722272317403066, 'mean_word_length': 1.967362225789192, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4809688', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1663, 'n_words': 294}