Exemplo n.º 1
0
 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 = view_helpers.SvnRepository(self.request.user.username)
         new_data.update({
             'repository_exists': repo.exists(),
             'svn_checkout_done': view_helpers.mission_completed(person, 'svn_checkout'),
             'svn_diff_done': view_helpers.mission_completed(person, 'svn_diff'),
             'svn_commit_done': view_helpers.mission_completed(person, 'svn_commit'),
         })
         if new_data['repository_exists']:
             new_data.update({
                 'checkout_url': repo.public_trunk_url(),
                 'secret_word_file': forms.CheckoutForm.SECRET_WORD_FILE,
                 'file_for_svn_diff': forms.DiffForm.FILE_TO_BE_PATCHED,
                 'new_secret_word': view_helpers.SvnCommitMission.NEW_SECRET_WORD,
                 'commit_username': self.request.user.username,
                 'commit_password': repo.get_password()})
     data.update(new_data)
     return data
Exemplo n.º 2
0
 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 = view_helpers.SvnRepository(self.request.user.username)
         new_data.update({
             'repository_exists': repo.exists(),
             'svn_checkout_done': view_helpers.mission_completed(person, 'svn_checkout'),
             'svn_diff_done': view_helpers.mission_completed(person, 'svn_diff'),
             'svn_commit_done': view_helpers.mission_completed(person, 'svn_commit'),
         })
         if new_data['repository_exists']:
             new_data.update({
                 'checkout_url': repo.public_trunk_url(),
                 'secret_word_file': forms.CheckoutForm.SECRET_WORD_FILE,
                 'file_for_svn_diff': forms.DiffForm.FILE_TO_BE_PATCHED,
                 'new_secret_word': view_helpers.SvnCommitMission.NEW_SECRET_WORD,
                 'commit_username': self.request.user.username,
                 'commit_password': repo.get_password()})
     data.update(new_data)
     return data
Exemplo n.º 3
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(view_helpers.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_(
                view_helpers.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)
Exemplo n.º 4
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(view_helpers.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_(
                view_helpers.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)
Exemplo n.º 5
0
 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(
         view_helpers.mission_completed(paulproteus, 'svn_diff'))
Exemplo n.º 6
0
    def test_do_diff_mission_with_invalid_form(self):
        self.client.post(reverse(views.resetrepo))
        response = self.client.get(reverse('svn_checkout'))
        checkoutdirpath = tempfile.mkdtemp()
        try:
            # Check the repository out and make the required change.
            subprocess.check_call([
                'svn', 'checkout', response.context['checkout_url'],
                checkoutdirpath
            ])
            new_contents = open(
                os.path.join(view_helpers.get_mission_data_path('svn'),
                             DiffForm.NEW_CONTENT)).read()
            open(os.path.join(checkoutdirpath, DiffForm.FILE_TO_BE_PATCHED),
                 'w').write(new_contents)

            # Make the diff invalid
            diff = 'invalid'

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

        finally:
            shutil.rmtree(checkoutdirpath)
Exemplo n.º 7
0
    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(view_helpers.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)

            # 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_(view_helpers.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)
Exemplo n.º 8
0
    def test_do_diff_mission_with_invalid_form(self):
        self.client.post(reverse(views.resetrepo))
        response = self.client.get(reverse('svn_checkout'))
        checkoutdirpath = tempfile.mkdtemp()
        try:
            # Check the repository out and make the required change.
            subprocess.check_call(
                ['svn', 'checkout', response.context['checkout_url'],
                 checkoutdirpath])
            new_contents = open(
                os.path.join(view_helpers.get_mission_data_path('svn'),
                             DiffForm.NEW_CONTENT)).read()
            open(os.path.join(checkoutdirpath, DiffForm.FILE_TO_BE_PATCHED),
                 'w').write(new_contents)

            # Make the diff invalid
            diff = 'invalid'

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

        finally:
            shutil.rmtree(checkoutdirpath)
Exemplo n.º 9
0
 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(
         view_helpers.mission_completed(paulproteus, 'svn_diff'))
Exemplo n.º 10
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(
         view_helpers.mission_completed(paulproteus, 'svn_checkout'))
     self.assertTrue('incorrect' in text)
Exemplo n.º 11
0
 def assert_commit_not_allowed(self):
     try:
         view_helpers.SvnCommitMission.pre_commit_hook('/fake/repository/path', 'fake-transaction-id')
         self.fail('No exception was raised.')
     except view_helpers.IncorrectPatch:
         pass
     paulproteus = Person.objects.get(user__username='******')
     self.assertFalse(view_helpers.mission_completed(paulproteus, 'svn_commit'))
Exemplo n.º 12
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_(view_helpers.mission_completed(paulproteus, 'svn_diff'))
Exemplo n.º 13
0
 def assert_commit_not_allowed(self):
     try:
         view_helpers.SvnCommitMission.pre_commit_hook(
             '/fake/repository/path', 'fake-transaction-id')
         self.fail('No exception was raised.')
     except view_helpers.IncorrectPatch:
         pass
     paulproteus = Person.objects.get(user__username='******')
     self.assertFalse(
         view_helpers.mission_completed(paulproteus, 'svn_commit'))
Exemplo n.º 14
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_(view_helpers.mission_completed(paulproteus, 'svn_diff'))
Exemplo n.º 15
0
 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_(view_helpers.mission_completed(paulproteus, 'svn_checkout'))
     finally:
         shutil.rmtree(checkoutdir)
Exemplo n.º 16
0
 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_(
             view_helpers.mission_completed(paulproteus, 'svn_checkout'))
     finally:
         shutil.rmtree(checkoutdir)
Exemplo n.º 17
0
    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(view_helpers.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)

            # 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_(
                view_helpers.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)
Exemplo n.º 18
0
 def assert_commit_allowed(self):
     view_helpers.SvnCommitMission.pre_commit_hook('/fake/repository/path',
                                                   'fake-transaction-id')
     paulproteus = Person.objects.get(user__username='******')
     self.assert_(view_helpers.mission_completed(paulproteus, 'svn_commit'))
Exemplo n.º 19
0
def commit_poll(request):
    """ Determines if entire mission is completed """
    return HttpResponse(json.dumps(view_helpers.mission_completed(request.user.get_profile(), 'svn_commit')))
Exemplo n.º 20
0
def commit_poll(request):
    return HttpResponse(json.dumps(view_helpers.mission_completed(request.user.get_profile(), 'svn_commit')))
Exemplo n.º 21
0
def commit_poll(request):
    return HttpResponse(
        simplejson.dumps(
            view_helpers.mission_completed(request.user.get_profile(),
                                           'svn_commit')))
Exemplo n.º 22
0
 def assert_commit_allowed(self):
     view_helpers.SvnCommitMission.pre_commit_hook(
         '/fake/repository/path', 'fake-transaction-id')
     paulproteus = Person.objects.get(user__username='******')
     self.assert_(
         view_helpers.mission_completed(paulproteus, 'svn_commit'))