예제 #1
0
파일: views.py 프로젝트: armooo/oh-mainline
 def get_context_data(self, *args, **kwargs):
     ### For now, we use the MissionPageState object to track a few things.
     ### Eventually, the missions base will stop using the PageState object,
     ### and all the work that class does will get merged into MissionBaseView.
     data = super(SvnBaseView, self).get_context_data(*args, **kwargs)
     state = MissionPageState(self.request, passed_data=None, mission_name=self.mission_name)
     new_data, person = state.get_base_data_dict_and_person()
     if person:
         repo = controllers.SvnRepository(self.request.user.username)
         new_data.update({
             'repository_exists': repo.exists(),
             'svn_checkout_done': controllers.mission_completed(person, 'svn_checkout'),
             'svn_diff_done': controllers.mission_completed(person, 'svn_diff'),
             'svn_commit_done': controllers.mission_completed(person, 'svn_commit'),
         })
         if new_data['repository_exists']:
             new_data.update({
                     'checkout_url': repo.public_trunk_url(),
                     'secret_word_file': controllers.SvnCheckoutMission.SECRET_WORD_FILE,
                     'file_for_svn_diff': controllers.SvnDiffMission.FILE_TO_BE_PATCHED,
                     'new_secret_word': controllers.SvnCommitMission.NEW_SECRET_WORD,
                     'commit_username': self.request.user.username,
                     'commit_password': repo.get_password()})
     data.update(new_data)
     return data
예제 #2
0
 def as_dict_for_template_context(self):
     (data, person) = self.get_base_data_dict_and_person()
     if person:
         repo = controllers.SvnRepository(self.request.user.username)
         data.update({
             'repository_exists':
             repo.exists(),
             'svn_checkout_done':
             controllers.mission_completed(person, 'svn_checkout'),
             'svn_diff_done':
             controllers.mission_completed(person, 'svn_diff'),
             'svn_commit_done':
             controllers.mission_completed(person, 'svn_commit'),
         })
         if data['repository_exists']:
             data.update({
                 'checkout_url':
                 repo.public_trunk_url(),
                 'secret_word_file':
                 controllers.SvnCheckoutMission.SECRET_WORD_FILE,
                 'file_for_svn_diff':
                 controllers.SvnDiffMission.FILE_TO_BE_PATCHED,
                 'new_secret_word':
                 controllers.SvnCommitMission.NEW_SECRET_WORD,
                 'commit_username':
                 self.request.user.username,
                 'commit_password':
                 repo.get_password()
             })
     return data
예제 #3
0
    def test_do_diff_mission_correctly(self):
        self.client.post(reverse(views.resetrepo))
        response = self.client.get(reverse(views.checkout))
        checkoutdir = tempfile.mkdtemp()
        try:
            # Check the repository out and make the required change.
            subprocess.check_call([
                'svn', 'checkout', response.context['checkout_url'],
                checkoutdir
            ])
            new_contents = open(
                os.path.join(controllers.get_mission_data_path('svn'),
                             controllers.SvnDiffMission.NEW_CONTENT)).read()
            open(
                os.path.join(checkoutdir,
                             controllers.SvnDiffMission.FILE_TO_BE_PATCHED),
                'w').write(new_contents)

            # Make the diff.
            diff = subproc_check_output(['svn', 'diff'], cwd=checkoutdir)

            # Submit the diff.
            response = self.client.post(reverse(views.diff_submit),
                                        {'diff': diff})
            paulproteus = Person.objects.get(user__username='******')
            self.assert_(controllers.mission_completed(paulproteus,
                                                       'svn_diff'))

            # Check that there is a new commit that applies to the working copy cleanly.
            update_output = subproc_check_output(['svn', 'update'],
                                                 cwd=checkoutdir)
            self.assert_('Updated to revision ' in update_output)
        finally:
            shutil.rmtree(checkoutdir)
예제 #4
0
파일: tests.py 프로젝트: armooo/oh-mainline
    def test_do_diff_mission_correctly_except_omit_the_final_whitespace(self):
        self.client.post(reverse(views.resetrepo))
        response = self.client.get(reverse('svn_checkout'))
        checkoutdir = tempfile.mkdtemp()
        try:
            # Check the repository out and make the required change.
            subprocess.check_call(['svn', 'checkout', response.context['checkout_url'], checkoutdir])
            new_contents = open(os.path.join(controllers.get_mission_data_path('svn'), controllers.SvnDiffMission.NEW_CONTENT)).read()
            open(os.path.join(checkoutdir, controllers.SvnDiffMission.FILE_TO_BE_PATCHED), 'w').write(new_contents)

            # Make the diff.
            diff = subproc_check_output(['svn', 'diff'], cwd=checkoutdir)

            # Many users fail to copy-paste the diff properly. In particular,
            # they omit trailing whitespace characters. Let's remove the last line.
            self.assertEqual(' \n', diff[-2:])
            diff = diff[:-2]

            # Submit the diff.
            response = self.client.post(reverse(views.diff_submit), {'diff': diff})
            paulproteus = Person.objects.get(user__username='******')
            self.assert_(controllers.mission_completed(paulproteus, 'svn_diff'))

            # Check that there is a new commit that applies to the working copy cleanly.
            update_output = subproc_check_output(['svn', 'update'], cwd=checkoutdir)
            self.assert_('Updated to revision ' in update_output)
        finally:
            shutil.rmtree(checkoutdir)
예제 #5
0
 def test_do_checkout_mission_incorrectly(self):
     self.client.post(reverse(views.resetrepo))
     response = self.client.post(reverse(views.checkout_submit),
                                 {'secret_word': 'not_the_secret_word'})
     paulproteus = Person.objects.get(user__username='******')
     self.assertFalse(
         controllers.mission_completed(paulproteus, 'svn_checkout'))
예제 #6
0
 def assert_commit_not_allowed(self):
     try:
         controllers.SvnCommitMission.pre_commit_hook("/fake/repository/path", "fake-transaction-id")
         self.fail("No exception was raised.")
     except controllers.IncorrectPatch:
         pass
     paulproteus = Person.objects.get(user__username="******")
     self.assertFalse(controllers.mission_completed(paulproteus, "svn_commit"))
예제 #7
0
파일: tests.py 프로젝트: armooo/oh-mainline
 def assert_commit_not_allowed(self):
     try:
         controllers.SvnCommitMission.pre_commit_hook('/fake/repository/path', 'fake-transaction-id')
         self.fail('No exception was raised.')
     except controllers.IncorrectPatch:
         pass
     paulproteus = Person.objects.get(user__username='******')
     self.assertFalse(controllers.mission_completed(paulproteus, 'svn_commit'))
예제 #8
0
 def as_dict_for_template_context(self):
     (data, person) = self.get_base_data_dict_and_person()
     if person:
         repo = controllers.SvnRepository(self.request.user.username)
         data.update({
             'repository_exists': repo.exists(),
             'svn_checkout_done': controllers.mission_completed(person, 'svn_checkout'),
             'svn_diff_done': controllers.mission_completed(person, 'svn_diff'),
             'svn_commit_done': controllers.mission_completed(person, 'svn_commit'),
         })
         if data['repository_exists']:
           data.update({
             'checkout_url': repo.public_trunk_url(),
             'secret_word_file': controllers.SvnCheckoutMission.SECRET_WORD_FILE,
             'file_for_svn_diff': controllers.SvnDiffMission.FILE_TO_BE_PATCHED,
             'new_secret_word': controllers.SvnCommitMission.NEW_SECRET_WORD,
             'commit_username': self.request.user.username,
             'commit_password': repo.get_password()
           })
     return data
예제 #9
0
파일: tests.py 프로젝트: armooo/oh-mainline
 def test_do_checkout_mission_correctly(self):
     self.client.post(reverse(views.resetrepo))
     response = self.client.get(reverse('svn_checkout'))
     checkoutdir = tempfile.mkdtemp()
     try:
         subprocess.check_call(['svn', 'checkout', response.context['checkout_url'], checkoutdir])
         word = open(os.path.join(checkoutdir, response.context['secret_word_file'])).read().strip()
         response = self.client.post(reverse(views.checkout_submit), {'secret_word': word})
         paulproteus = Person.objects.get(user__username='******')
         self.assert_(controllers.mission_completed(paulproteus, 'svn_checkout'))
     finally:
         shutil.rmtree(checkoutdir)
예제 #10
0
 def test_diff_without_spaces_works(self):
     self.client.post(reverse(views.resetrepo))
     self.client.post(
         reverse(views.diff_submit),
         {
             "diff": open(
                 make_testdata_filename("svn", "svn-diff-without-spaces-on-blank-context-lines.patch")
             ).read()
         },
     )
     paulproteus = Person.objects.get(user__username="******")
     self.assert_(controllers.mission_completed(paulproteus, "svn_diff"))
예제 #11
0
 def test_diff_without_spaces_works(self):
     self.client.post(reverse(views.resetrepo))
     self.client.post(
         reverse(views.diff_submit), {
             'diff':
             open(
                 make_testdata_filename(
                     'svn',
                     'svn-diff-without-spaces-on-blank-context-lines.patch')
             ).read()
         })
     paulproteus = Person.objects.get(user__username='******')
     self.assert_(controllers.mission_completed(paulproteus, 'svn_diff'))
예제 #12
0
 def test_do_checkout_mission_correctly(self):
     self.client.post(reverse(views.resetrepo))
     response = self.client.get(reverse(views.checkout))
     checkoutdir = tempfile.mkdtemp()
     try:
         subprocess.check_call([
             'svn', 'checkout', response.context['checkout_url'],
             checkoutdir
         ])
         word = open(
             os.path.join(
                 checkoutdir,
                 response.context['secret_word_file'])).read().strip()
         response = self.client.post(reverse(views.checkout_submit),
                                     {'secret_word': word})
         paulproteus = Person.objects.get(user__username='******')
         self.assert_(
             controllers.mission_completed(paulproteus, 'svn_checkout'))
     finally:
         shutil.rmtree(checkoutdir)
예제 #13
0
    def test_do_diff_mission_correctly(self):
        self.client.post(reverse(views.resetrepo))
        response = self.client.get(reverse("svn_checkout"))
        checkoutdir = tempfile.mkdtemp()
        try:
            # Check the repository out and make the required change.
            subprocess.check_call(["svn", "checkout", response.context["checkout_url"], checkoutdir])
            new_contents = open(os.path.join(controllers.get_mission_data_path("svn"), DiffForm.NEW_CONTENT)).read()
            open(os.path.join(checkoutdir, DiffForm.FILE_TO_BE_PATCHED), "w").write(new_contents)

            # Make the diff.
            diff = subproc_check_output(["svn", "diff"], cwd=checkoutdir)

            # Submit the diff.
            response = self.client.post(reverse(views.diff_submit), {"diff": diff})
            paulproteus = Person.objects.get(user__username="******")
            self.assert_(controllers.mission_completed(paulproteus, "svn_diff"))

            # Check that there is a new commit that applies to the working copy cleanly.
            update_output = subproc_check_output(["svn", "update"], cwd=checkoutdir)
            self.assert_("Updated to revision " in update_output)
        finally:
            shutil.rmtree(checkoutdir)
예제 #14
0
    def test_do_diff_mission_correctly(self):
        self.client.post(reverse(views.resetrepo))
        response = self.client.get(reverse(views.checkout))
        checkoutdir = tempfile.mkdtemp()
        try:
            # Check the repository out and make the required change.
            subprocess.check_call(['svn', 'checkout', response.context['checkout_url'], checkoutdir])
            new_contents = open(os.path.join(controllers.get_mission_data_path('svn'), controllers.SvnDiffMission.NEW_CONTENT)).read()
            open(os.path.join(checkoutdir, controllers.SvnDiffMission.FILE_TO_BE_PATCHED), 'w').write(new_contents)

            # Make the diff.
            diff = subproc_check_output(['svn', 'diff'], cwd=checkoutdir)

            # Submit the diff.
            response = self.client.post(reverse(views.diff_submit), {'diff': diff})
            paulproteus = Person.objects.get(user__username='******')
            self.assert_(controllers.mission_completed(paulproteus, 'svn_diff'))

            # Check that there is a new commit that applies to the working copy cleanly.
            update_output = subproc_check_output(['svn', 'update'], cwd=checkoutdir)
            self.assert_('Updated to revision ' in update_output)
        finally:
            shutil.rmtree(checkoutdir)
예제 #15
0
class SvnCommitHookTests(DjangoTestCase):
    fixtures = ['user-paulproteus', 'person-paulproteus']

    def setUp(self):
        # We fully mock the svnlook output, so the hook doesn't try to inspect a repository at all during the tests.
        controllers.set_mission_completed(
            Person.objects.get(user__username='******'), 'svn_diff')

    def assert_commit_allowed(self):
        controllers.SvnCommitMission.pre_commit_hook('/fake/repository/path',
                                                     'fake-transaction-id')
        paulproteus = Person.objects.get(user__username='******')
        self.assert_(controllers.mission_completed(paulproteus, 'svn_commit'))

    def assert_commit_not_allowed(self):
        try:
            controllers.SvnCommitMission.pre_commit_hook(
                '/fake/repository/path', 'fake-transaction-id')
            self.fail('No exception was raised.')
        except controllers.IncorrectPatch, e:
            pass
        paulproteus = Person.objects.get(user__username='******')
        self.assertFalse(
            controllers.mission_completed(paulproteus, 'svn_commit'))
예제 #16
0
파일: tests.py 프로젝트: armooo/oh-mainline
 def test_do_checkout_mission_incorrectly(self):
     self.client.post(reverse(views.resetrepo))
     text = self.client.post(reverse(views.checkout_submit), {'secret_word': 'not_the_secret_word'}).content
     paulproteus = Person.objects.get(user__username='******')
     self.assertFalse(controllers.mission_completed(paulproteus, 'svn_checkout'))
     self.assertTrue('incorrect' in text)
예제 #17
0
 def assert_commit_allowed(self):
     controllers.SvnCommitMission.pre_commit_hook("/fake/repository/path", "fake-transaction-id")
     paulproteus = Person.objects.get(user__username="******")
     self.assert_(controllers.mission_completed(paulproteus, "svn_commit"))
예제 #18
0
파일: views.py 프로젝트: armooo/oh-mainline
def commit_poll(request):
    return HttpResponse(simplejson.dumps(controllers.mission_completed(request.user.get_profile(), 'svn_commit')))
예제 #19
0
파일: tests.py 프로젝트: armooo/oh-mainline
 def assert_commit_allowed(self):
     controllers.SvnCommitMission.pre_commit_hook('/fake/repository/path', 'fake-transaction-id')
     paulproteus = Person.objects.get(user__username='******')
     self.assert_(controllers.mission_completed(paulproteus, 'svn_commit'))
예제 #20
0
파일: tests.py 프로젝트: armooo/oh-mainline
 def test_submit_empty_diff_does_not_crash(self):
     self.client.post(reverse(views.resetrepo))
     response = self.client.post(reverse(views.diff_submit), {'diff': ''})
     self.assertEqual(200, response.status_code)
     paulproteus = Person.objects.get(user__username='******')
     self.assertFalse(controllers.mission_completed(paulproteus, 'svn_diff'))
예제 #21
0
 def assert_commit_allowed(self):
     controllers.SvnCommitMission.pre_commit_hook('/fake/repository/path',
                                                  'fake-transaction-id')
     paulproteus = Person.objects.get(user__username='******')
     self.assert_(controllers.mission_completed(paulproteus, 'svn_commit'))
예제 #22
0
def commit_poll(request):
    return HttpResponse(
        simplejson.dumps(
            controllers.mission_completed(request.user.get_profile(),
                                          'svn_commit')))
예제 #23
0
 def test_do_checkout_mission_incorrectly(self):
     self.client.post(reverse(views.resetrepo))
     text = self.client.post(reverse(views.checkout_submit), {"secret_word": "not_the_secret_word"}).content
     paulproteus = Person.objects.get(user__username="******")
     self.assertFalse(controllers.mission_completed(paulproteus, "svn_checkout"))
     self.assertTrue("incorrect" in text)