def test_todo_add_version(self): """Check if adding a version with valid mime type succeeds""" document = Document() document.title = "Wachtmeister Studer" document.author = "Friedrich Glauser" document.source_publisher = "Diogenes" document.publisher = "Swiss Library for the Blind, Visually Impaired and Print Disabled" document.identifier = "ch-sbs-1" document.language = "de" document.save() # unfortunately document.save sets the date to today for a new # document, so we need to save, set the date and save again document.date = "2009-04-23" document.save() self.client.login(username='******', password='******') version = open(os.path.join(TEST_DATA_DIR, 'test.xml')) post_data = { 'comment': 'testing 123', 'content': version, } original_function = django.test.client.encode_file django.test.client.encode_file = get_file_encoder('text/xml') response = self.client.post( reverse('todo_add_version', args=[document.pk]), post_data) version.close() django.test.client.encode_file = original_function self.assertRedirects(response, reverse('todo_detail', args=[document.pk]))
def test_manage_update_with_existing_version(self): """Check if creation of a new document succeeds even if there is a version to update """ from django.core.files.base import File document = Document() document.title = "Wachtmeister Studer" document.author = "Friedrich Glauser" document.source_publisher = "Diogenes" document.save() user = User.objects.get(pk=1) versionFile = File(open(os.path.join(TEST_DATA_DIR, 'test.xml'))) version = Version.objects.create( comment = "testing 123", document = document, created_by = user) version.content.save("updated_version.xml", versionFile) versionFile.close() self.client.login(username='******', password='******') response = self.client.post(reverse('manage_update', args=[document.pk]), { 'title': 'testing 456', 'language': 'de' }) self.assertTemplateNotUsed(response, 'documents/manage_update.html') self.assertRedirects(response, reverse('manage_index'))
def test_todo_add_version_missing_metadata(self): """Check if adding a version with invalid meta data fails""" document = Document() document.title = "Wachtmeister Studer" document.author = "Friedrich Glauser" document.source_publisher = "Diogenes" document.save() self.client.login(username='******', password='******') version = open(os.path.join(TEST_DATA_DIR, 'test.xml')) post_data = { 'comment': 'testing 123', 'content': version, } original_function = django.test.client.encode_file django.test.client.encode_file = get_file_encoder('text/xml') response = self.client.post( reverse('todo_add_version', args=[document.pk]), post_data) version.close() django.test.client.encode_file = original_function self.assertContains(response, "The meta data 'dtb:uid' in the uploaded file does not correspond to the value in the document: 'ch-sbs-1' instead of 'ch-sbs-")