Add two tests for file upload

This commit is contained in:
Skia 2016-12-09 15:48:09 +01:00
parent a02d5a65cb
commit 4542753812
2 changed files with 28 additions and 1 deletions

View File

@ -269,3 +269,30 @@ http://git.an
# - renaming a page # - renaming a page
# - changing a page's parent --> check that page's children's full_name # - changing a page's parent --> check that page's children's full_name
# - changing the different groups of the page # - changing the different groups of the page
class FileHandlingTest(TestCase):
def setUp(self):
try:
call_command("populate")
self.subscriber = User.objects.filter(username="subscriber").first()
self.client.login(username='subscriber', password='plop')
except Exception as e:
print(e)
def test_create_folder_home(self):
response = self.client.post(reverse("core:file_detail", kwargs={"file_id":self.subscriber.home.id}),
{"folder_name": "GUY_folder_test"})
self.assertTrue(response.status_code == 302)
response = self.client.get(reverse("core:file_detail", kwargs={"file_id":self.subscriber.home.id}))
self.assertTrue(response.status_code == 200)
self.assertTrue("GUY_folder_test</a>" in str(response.content))
def test_upload_file_home(self):
with open("/bin/ls", "rb") as f:
response = self.client.post(reverse("core:file_detail", kwargs={"file_id":self.subscriber.home.id}),
{"file_field": f})
self.assertTrue(response.status_code == 302)
response = self.client.get(reverse("core:file_detail", kwargs={"file_id":self.subscriber.home.id}))
self.assertTrue(response.status_code == 200)
self.assertTrue("ls</a>" in str(response.content))

View File

@ -194,7 +194,7 @@ class FileModerationView(TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
kwargs = super(FileModerationView, self).get_context_data(**kwargs) kwargs = super(FileModerationView, self).get_context_data(**kwargs)
kwargs['files'] = SithFile.objects.filter(is_moderated=False).all() kwargs['files'] = SithFile.objects.filter(is_moderated=False)[:100]
return kwargs return kwargs
class FileModerateView(CanEditPropMixin, SingleObjectMixin): class FileModerateView(CanEditPropMixin, SingleObjectMixin):