-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1180] Bulk download column check tests
- Loading branch information
1 parent
700d97f
commit 20654d1
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django.core.management import call_command | ||
from django.test import TestCase | ||
from django.test.utils import override_settings | ||
from api.v1.v1_forms.models import Questions | ||
from api.v1.v1_data.models import FormData | ||
from api.v1.v1_jobs.job import download | ||
|
||
|
||
@override_settings(USE_TZ=False) | ||
class BulkUnitTestCase(TestCase): | ||
def setUp(self): | ||
call_command("form_seeder", "--test") | ||
call_command("administration_seeder", "--test") | ||
user = {"email": "[email protected]", "password": "Test105*"} | ||
user = self.client.post('/api/v1/login', | ||
user, | ||
content_type='application/json') | ||
call_command("fake_data_seeder", "-r", 2, "--test", True) | ||
|
||
def test_data_download_list_of_columns(self): | ||
form_data = FormData.objects.count() | ||
self.assertTrue(form_data) | ||
form_data = FormData.objects.first() | ||
administration = form_data.administration | ||
download_response = download(form_data.form, [administration.id]) | ||
self.assertTrue(download_response) | ||
download_columns = list(download_response[0].keys()) | ||
questions = Questions.objects.filter(form=form_data.form).values_list( | ||
"variable", flat=True) | ||
meta_columns = ["id", "created_at", "created_by", "updated_at", | ||
"updated_by", "datapoint_name", "administration", | ||
"geolocation"] | ||
columns = list( | ||
filter(lambda x: x not in meta_columns, download_columns) | ||
) | ||
self.assertEqual(list(columns).sort(), list(questions).sort()) |