Ejemplo n.º 1
0
 def test_repo_reset(self):
     repo_path = tempfile.mkdtemp(dir=settings.SVN_REPO_PATH)
     random_name = os.path.basename(repo_path)
     os.rmdir(repo_path)
     try:
         # Check that we can run "svn info" on the created repository to get the UUID.
         view_helpers.SvnRepository(random_name).reset()
         old_uuid = self.get_info(repo_path)['Repository UUID']
         # Check that resetting the repository changes its UUID.
         view_helpers.SvnRepository(random_name).reset()
         new_uuid = self.get_info(repo_path)['Repository UUID']
         self.assertNotEqual(old_uuid, new_uuid)
     finally:
         if os.path.isdir(repo_path):
             shutil.rmtree(repo_path)
Ejemplo 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
Ejemplo n.º 3
0
    def clean_diff(self):
        """
        Validate the diff form.
        This function will be invoked by django.form.Forms.is_valid(), and
        will raise the exception ValidationError
        """
        self.the_patch = patch.fromstring(self.cleaned_data['diff'])
        # Check that the submitted diff patches the correct number of files
        if len(self.the_patch.hunks) != 1:
            raise ValidationError, 'The patch affects more than one file.'

        # Check that the filename it patches is correct.
        if self.FILE_TO_BE_PATCHED not in self.cleaned_data['diff']:
            raise ValidationError, 'The patch affects the wrong file.'

        # Now we need to generate a working copy to apply the patch to.
        # We can also use this working copy to commit the patch if it's OK.
        repo = view_helpers.SvnRepository(self.username)
        view_helpers.subproc_check_output(
            ['svn', 'co', repo.file_trunk_url(), self.wcdir])

        # Check that it will apply correctly to the working copy.
        if not self.the_patch._match_file_hunks(self.file_to_patch,
                                                self.the_patch.hunks[0]):
            raise ValidationError, 'The patch will not apply correctly to the lastest revision.'

        # Check that the resulting file matches what is expected.
        self.new_content = ''.join(
            self.the_patch.patch_stream(open(self.file_to_patch),
                                        self.the_patch.hunks[0]))
        if self.new_content != open(self.NEW_CONTENT).read():
            raise ValidationError, 'The file resulting from patching does not have the correct contents.'
Ejemplo n.º 4
0
def resetrepo(request):
    if request.method != 'POST':
        return HttpResponseNotAllowed(['POST'])
    view_helpers.SvnRepository(request.user.username).reset()
    view_helpers.unset_mission_completed(request.user.get_profile(),
                                         'svn_checkout')
    view_helpers.unset_mission_completed(request.user.get_profile(),
                                         'svn_diff')
    view_helpers.unset_mission_completed(request.user.get_profile(),
                                         'svn_commit')
    if 'stay_on_this_page' in request.GET:
        return HttpResponseRedirect(reverse('svn_main_page'))
    else:
        return HttpResponseRedirect(reverse('svn_checkout'))
Ejemplo n.º 5
0
 def clean_secret_word(self):
     cat_trunk = view_helpers.SvnRepository(
         self.username).cat('/trunk/' + self.SECRET_WORD_FILE).strip()
     if self.cleaned_data['secret_word'] != cat_trunk:
         raise ValidationError, 'The secret word is incorrect.'
Ejemplo n.º 6
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError, 'Exactly one argument expected.'
        username, = args

        view_helpers.SvnRepository(username).reset()