|
|
@ -12,6 +12,8 @@ class TestUpload(TestCase): |
|
|
|
self.username, self.password = 'user', 'pass' |
|
|
|
self.client = Client() |
|
|
|
self.filepath = os.path.join(os.path.dirname(__file__), 'data/test.csv') |
|
|
|
self.jsonpath = os.path.join(os.path.dirname(__file__), 'data/test.jsonl') |
|
|
|
|
|
|
|
|
|
|
|
def create_user(self): |
|
|
|
user = User.objects.create_user(username=self.username, password=self.password) |
|
|
@ -40,7 +42,7 @@ class TestUpload(TestCase): |
|
|
|
with open(self.filepath) as f: |
|
|
|
url = reverse('upload', args=[project.id]) |
|
|
|
self.client.login(username=self.username, password=self.password) |
|
|
|
response = self.client.post(url, {'csv_file': f}) |
|
|
|
response = self.client.post(url, {'file': f, 'format': 'csv'}) |
|
|
|
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_302_FOUND) |
|
|
|
self.assertEqual(Document.objects.count(), 3) |
|
|
@ -56,7 +58,24 @@ class TestUpload(TestCase): |
|
|
|
with open(self.filepath) as f: |
|
|
|
url = reverse('upload', args=[project.id]) |
|
|
|
self.client.login(username=self.username, password=self.password) |
|
|
|
response = self.client.post(url, {'csv_file': f}) |
|
|
|
response = self.client.post(url, {'file': f, 'format': 'csv'}) |
|
|
|
|
|
|
|
self.assertEqual(response.status_code, status.HTTP_302_FOUND) |
|
|
|
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) |
|
|
|
self.assertEqual(Document.objects.count(), 0) |
|
|
|
|
|
|
|
def test_upload_json_by_admin(self): |
|
|
|
""" |
|
|
|
Ensure we can create a new document object from json by admin. |
|
|
|
""" |
|
|
|
user = self.create_superuser() |
|
|
|
project = self.create_project() |
|
|
|
project.users.add(user) |
|
|
|
|
|
|
|
with open(self.jsonpath, 'r') as f: |
|
|
|
url = reverse('upload', args=[project.id]) |
|
|
|
self.client.login(username=self.username, password=self.password) |
|
|
|
response = self.client.post(url, {'file': f, 'format': 'json'}) |
|
|
|
|
|
|
|
print(self.jsonpath) |
|
|
|
self.assertEqual(response.status_code, status.HTTP_302_FOUND) |
|
|
|
self.assertEqual(Document.objects.count(), 18) |