Skip to content

Commit

Permalink
Split tests & adapt them to the new forms
Browse files Browse the repository at this point in the history
  • Loading branch information
Anaethelion committed Jul 23, 2015
1 parent 093e4d1 commit 7f6296e
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions geotrek/common/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- encoding: utf-8 -*-

import io
from zipfile import ZipFile

from django.core.files.uploadedfile import SimpleUploadedFile

from django.test import TestCase
Expand All @@ -9,7 +12,6 @@


class ViewsTest(TestCase):

def setUp(self):
self.user = UserFactory.create(username='homer', password='dooh')
success = self.client.login(
Expand All @@ -30,6 +32,15 @@ def test_admin_check_extents(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)


class ViewsImportTest(TestCase):

def setUp(self):
self.user = UserFactory.create(username='homer', password='dooh')
success = self.client.login(
username=self.user.username, password='dooh')
self.assertTrue(success)

def test_import_form_access(self):
url = reverse('common:import_dataset')
response = self.client.get(url)
Expand All @@ -48,23 +59,36 @@ def test_import_update_access(self):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

def test_import_form_file_content_type_handling(self):
def test_import_form_file_good_file(self):
self.user.is_superuser = True
self.user.save()

good_archive = SimpleUploadedFile(
"file.zip", "file_content", content_type="application/zip")
bad_archive = SimpleUploadedFile(
"file.doc", "file_content", content_type="application/msword")

real_archive = open('geotrek/common/tests/data/test.txt.gz', 'r+')
url = reverse('common:import_dataset')

response = self.client.post(
url, {'parser': 'CityParser', 'zipfile': good_archive})
self.assertEqual(response.status_code, 200)
response_real = self.client.post(
url, {
'upload-file': 'Upload',
'with-file-parser': '7',
'with-file-zipfile': real_archive
}
)
self.assertEqual(response_real.status_code, 200)

response = self.client.post(
url, {'parser': 'CityParser', 'zipfile': bad_archive})
self.assertEqual(response.status_code, 200)
self.assertFormError(
response, 'form', 'zipfile', ["File must be of ZIP type.", ])
def test_import_form_file_bad_file(self):
self.user.is_superuser = True
self.user.save()

fake_archive = SimpleUploadedFile(
"file.doc", "file_content", content_type="application/msword")
url = reverse('common:import_dataset')

response_fake = self.client.post(
url, {
'upload-file': 'Upload',
'with-file-parser': '7',
'with-file-zipfile': fake_archive
}
)
self.assertEqual(response_fake.status_code, 200)
self.assertContains(response_fake, "File must be of ZIP type.", 1)

0 comments on commit 7f6296e

Please sign in to comment.