Example #1
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)
Example #2
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)
Example #3
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)
Example #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)
Example #5
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)
Example #6
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)