def setUp(self): # Build a fake file fake_file = get_test_document_file() self.root_collection = Collection.get_first_root_node() self.evil_plans_collection = self.root_collection.add_child( name="Evil plans") self.nice_plans_collection = self.root_collection.add_child( name="Nice plans") # Create a document to edit self.document = models.Document.objects.create( title="Test document", file=fake_file, collection=self.nice_plans_collection) # Create a user with change_document permission but not add_document user = get_user_model().objects.create_user( username='******', email='*****@*****.**', password='******') change_permission = Permission.objects.get( content_type__app_label='wagtaildocs', codename='change_document') admin_permission = Permission.objects.get( content_type__app_label='wagtailadmin', codename='access_admin') self.changers_group = Group.objects.create(name='Document changers') GroupCollectionPermission.objects.create( group=self.changers_group, collection=self.root_collection, permission=change_permission) user.groups.add(self.changers_group) user.user_permissions.add(admin_permission) self.assertTrue( self.client.login(username='******', password='******'))
def test_post_with_collections(self): root_collection = Collection.get_first_root_node() evil_plans_collection = root_collection.add_child(name="Evil plans") # Build a fake file fake_file = get_test_document_file() # Submit post_data = { 'title': "Test document", 'file': fake_file, 'collection': evil_plans_collection.id, } response = self.client.post(reverse('wagtaildocs:add'), post_data) # User should be redirected back to the index self.assertRedirects(response, reverse('wagtaildocs:index')) # Document should be created, and be placed in the Evil Plans collection self.assertTrue( models.Document.objects.filter(title="Test document").exists()) root_collection = Collection.get_first_root_node() self.assertEqual( models.Document.objects.get(title="Test document").collection, evil_plans_collection)
def test_post(self): # Build a fake file fake_file = get_test_document_file() # Submit post_data = { 'title': "Test document", 'file': fake_file, } response = self.client.post(reverse('wagtaildocs:add'), post_data) # User should be redirected back to the index self.assertRedirects(response, reverse('wagtaildocs:index')) # Document should be created, and be placed in the root collection document = models.Document.objects.get(title="Test document") root_collection = Collection.get_first_root_node() self.assertEqual( document.collection, root_collection ) # Check that the file_size/hash field was set self.assertTrue(document.file_size) self.assertTrue(document.file_hash)
def setUp(self): self.login() # Create a document for running tests on self.doc = get_document_model().objects.create( title="Test document", file=get_test_document_file(), )
def setUp(self): self.login() # Build a fake file fake_file = get_test_document_file() # Create a document to edit self.document = models.Document.objects.create(title="Test document", file=fake_file)
def setUp(self): self.login() # Create a document to edit self.document = CustomDocument.objects.create( title="Test document", file=get_test_document_file(), ) self.storage = self.document.file.storage
def test_with_missing_source_file(self): # Build a fake file fake_file = get_test_document_file() # Create a new document to delete the source for document = models.Document.objects.create(title="Test missing source document", file=fake_file) document.file.delete(False) response = self.client.get(reverse('wagtaildocs:edit', args=(document.id,)), {}) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'wagtaildocs/documents/edit.html') self.assertContains(response, 'File not found')
def test_post(self): # Build a fake file fake_file = get_test_document_file() # Submit title change post_data = { 'title': "Test document changed!", 'file': fake_file, } response = self.client.post(reverse('wagtaildocs:edit', args=(self.document.id,)), post_data) # User should be redirected back to the index self.assertRedirects(response, reverse('wagtaildocs:index')) # Document title should be changed self.assertEqual(models.Document.objects.get(id=self.document.id).title, "Test document changed!")
def test_post(self): # Build a fake file fake_file = get_test_document_file() # Submit post_data = { 'document-chooser-upload-title': "Test document", 'document-chooser-upload-file': fake_file, } response = self.client.post(reverse('wagtaildocs:chooser_upload'), post_data) # Check that the response is the 'document_chosen' step response_json = json.loads(response.content.decode()) self.assertEqual(response_json['step'], 'document_chosen') # Document should be created self.assertTrue(models.Document.objects.filter(title="Test document").exists())
def test_post(self): # Build a fake file fake_file = get_test_document_file() # Submit post_data = { 'title': "Test document", 'file': fake_file, } response = self.client.post(reverse('wagtaildocs:add'), post_data) # User should be redirected back to the index self.assertRedirects(response, reverse('wagtaildocs:index')) # Document should be created in the 'evil plans' collection, # despite there being no collection field in the form, because that's the # only one the user has access to self.assertTrue( models.Document.objects.filter(title="Test document").exists()) self.assertEqual( models.Document.objects.get(title="Test document").collection, self.evil_plans_collection)