def test_uploaded_file_path(self): uploadedfile_instance = mock.Mock() uploadedfile_instance.owner = mock.Mock(spec=User) uploadedfile_instance.owner.username = '******' uploadedfile_instance.owner.upload_path = 'foo/uploads/myuploads' filename = 'file1.txt' file_path = uploaded_file_path(uploadedfile_instance, filename) self.assertEqual(file_path, 'foo/uploads/myuploads')
def test_uploadedfile_delete_success(self): self.client.login(username=self.username, password=self.password) swift_path = uploaded_file_path(self.uploadedfile, '') mocked_method = 'uploadedfiles.views.swiftclient.Connection.delete_object' with mock.patch(mocked_method) as delete_object_mock: response = self.client.delete(self.read_update_delete_url) delete_object_mock.assert_called_with(settings.SWIFT_CONTAINER_NAME, swift_path) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertEqual(UploadedFile.objects.count(), 0)
def test_uploaded_file_path(self): uploadedfile_instance = mock.Mock() uploadedfile_instance.owner = mock.Mock(spec=User) uploadedfile_instance.owner.username = '******' uploadedfile_instance.upload_path = '/myuploads' filename = 'file1.txt' file_path = uploaded_file_path(uploadedfile_instance, filename) expected_file_path = '{0}/{1}/{2}'.format(uploadedfile_instance.owner.username, 'uploads', uploadedfile_instance.upload_path.strip('/')) self.assertEqual(file_path, expected_file_path)
def test_uploaded_file_path(self): uploadedfile_instance = mock.Mock() uploadedfile_instance.owner = mock.Mock(spec=User) uploadedfile_instance.owner.username = '******' uploadedfile_instance.upload_path = '/myuploads' filename = 'file1.txt' file_path = uploaded_file_path(uploadedfile_instance, filename) expected_file_path = '{0}/{1}/{2}'.format( uploadedfile_instance.owner.username, 'uploads', uploadedfile_instance.upload_path.strip('/')) self.assertEquals(file_path, expected_file_path)