def test_clean_parent_diff_path(self): """Testing UploadCommitForm.clean() for a subsequent commit with a parent diff """ diff = SimpleUploadedFile('diff', self.DEFAULT_GIT_FILEDIFF_DATA, content_type='text/x-patch') parent_diff = SimpleUploadedFile('parent_diff', self.DEFAULT_GIT_FILEDIFF_DATA, content_type='text/x-patch') form = UploadCommitForm(diffset=self.diffset, data=self._default_form_data.copy(), files={ 'diff': diff, 'parent_diff': parent_diff, }) self.assertTrue(form.is_valid()) form.create() form = UploadCommitForm(diffset=self.diffset, data=dict( self._default_form_data, **{ 'parent_id': 'r1', 'commit_id': 'r2', }), files={ 'diff': diff, 'parent_diff': parent_diff, }) self.assertTrue(form.is_valid()) self.assertNotIn('parent_diff', form.errors)
def test_clean_parent_diff_path(self): """Testing UploadCommitForm.clean() for a subsequent commit with a parent diff """ diff = SimpleUploadedFile('diff', self.DEFAULT_GIT_FILEDIFF_DATA_DIFF, content_type='text/x-patch') parent_diff = SimpleUploadedFile('parent_diff', self.DEFAULT_GIT_FILEDIFF_DATA_DIFF, content_type='text/x-patch') form = UploadCommitForm( diffset=self.diffset, data=self._default_form_data.copy(), files={ 'diff': diff, 'parent_diff': parent_diff, }) self.assertTrue(form.is_valid()) form.create() form = UploadCommitForm( diffset=self.diffset, data=dict( self._default_form_data, **{ 'parent_id': 'r1', 'commit_id': 'r2', } ), files={ 'diff': diff, 'parent_diff': parent_diff, }) self.assertTrue(form.is_valid()) self.assertNotIn('parent_diff', form.errors)
def test_clean_published_diff(self): """Testing UploadCommitForm.clean() for a DiffSet that has already been published """ diff = SimpleUploadedFile('diff', self.DEFAULT_GIT_FILEDIFF_DATA_DIFF, content_type='text/x-patch') form = UploadCommitForm( diffset=self.diffset, data=self._default_form_data, files={ 'diff': diff, }) self.assertTrue(form.is_valid()) form.create() self.diffset.history = DiffSetHistory.objects.create() self.diffset.save(update_fields=('history_id',)) form = UploadCommitForm( diffset=self.diffset, data=dict( self._default_form_data, parent_id='r1', commit_id='r0', ), files={ 'diff_path': SimpleUploadedFile( 'diff', self.DEFAULT_GIT_FILEDIFF_DATA_DIFF, content_type='text/x-patch'), }) self.assertFalse(form.is_valid()) self.assertNotEqual(form.non_field_errors, [])
def test_clean_published_diff(self): """Testing UploadCommitForm.clean() for a DiffSet that has already been published """ diff = SimpleUploadedFile('diff', self.DEFAULT_GIT_FILEDIFF_DATA_DIFF, content_type='text/x-patch') form = UploadCommitForm( diffset=self.diffset, data=self._default_form_data, files={ 'diff': diff, }) self.assertTrue(form.is_valid()) form.create() self.diffset.history = DiffSetHistory.objects.create() self.diffset.save(update_fields=('history_id',)) form = UploadCommitForm( diffset=self.diffset, data=dict( self._default_form_data, parent_id='r1', commit_id='r0', ), files={ 'diff_path': SimpleUploadedFile( 'diff', self.DEFAULT_GIT_FILEDIFF_DATA_DIFF, content_type='text/x-patch'), }) self.assertFalse(form.is_valid()) self.assertNotEqual(form.non_field_errors, [])
def test_create(self): """Testing UploadCommitForm.create""" diff = SimpleUploadedFile('diff', self.DEFAULT_GIT_FILEDIFF_DATA, content_type='text/x-patch') form = UploadCommitForm(diffset=self.diffset, data=self._default_form_data.copy(), files={ 'diff': diff, }) self.assertTrue(form.is_valid()) commit = form.create() self.assertEqual(self.diffset.files.count(), 1) self.assertEqual(self.diffset.commits.count(), 1) self.assertEqual(commit.files.count(), 1) self.assertEqual(set(self.diffset.files.all()), set(commit.files.all()))
def test_create(self): """Testing UploadCommitForm.create""" diff = SimpleUploadedFile('diff', self.DEFAULT_GIT_FILEDIFF_DATA_DIFF, content_type='text/x-patch') form = UploadCommitForm( diffset=self.diffset, data=self._default_form_data.copy(), files={ 'diff': diff, }) self.assertTrue(form.is_valid()) commit = form.create() self.assertEqual(self.diffset.files.count(), 1) self.assertEqual(self.diffset.commits.count(), 1) self.assertEqual(commit.files.count(), 1) self.assertEqual(set(self.diffset.files.all()), set(commit.files.all()))