Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rajpatel24 committed Jan 8, 2025
1 parent dde80a5 commit 578b2be
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 92 deletions.
18 changes: 0 additions & 18 deletions kobo/apps/openrosa/apps/api/tests/fixtures/users.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,74 @@ def test_submission_blocking_flag(self):
response = self.view(request, username=username)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)

def test_submission_customizable_confirmation_message(self):
s = 'transport_with_custom_attribute'
media_file = '1335783522563.jpg'
xml_files = [
'transport_with_custom_attribute_01',
'transport_with_custom_attribute_02',
'transport_with_no_custom_attribute'
]

path = os.path.join(
self.main_directory,
'fixtures',
'transportation',
'instances',
s,
media_file,
)
with open(path, 'rb') as f:
f = InMemoryUploadedFile(
f,
'media_file',
media_file,
'image/jpg',
os.path.getsize(path),
None,
)
for xml_file in xml_files:
submission_path = os.path.join(
self.main_directory,
'fixtures',
'transportation',
'instances',
s,
xml_file + '.xml',
)
with open(submission_path) as sf:
data = {'xml_submission_file': sf, 'media_file': f}
request = self.factory.post('/submission', data)
response = self.view(request)
self.assertEqual(response.status_code, 401)

# rewind the file and redo the request since they were
# consumed
sf.seek(0)
f.seek(0)
request = self.factory.post('/submission', data)
auth = DigestAuth('bob', 'bobbob')
request.META.update(auth(request.META, response))
response = self.view(request, username=self.user.username)
if xml_file == 'transport_with_custom_attribute_01':
self.assertContains(
response, 'Custom submit message', status_code=201
)
elif xml_file == 'transport_with_custom_attribute_02':
self.assertContains(
response, 'Successful submission.', status_code=201
)
elif xml_file == (
'transport_with_custom_attribute_and_different_root'
):
self.assertContains(
response, 'Custom submit message', status_code=201
)
else:
self.assertContains(
response, 'Successful submission.', status_code=201
)


class ConcurrentSubmissionTestCase(RequestMixin, LiveServerTestCase):
"""
Expand All @@ -492,10 +560,11 @@ class ConcurrentSubmissionTestCase(RequestMixin, LiveServerTestCase):
Otherwise, DB is populated only on the first request but still empty on
subsequent ones.
"""
fixtures = ['kobo/apps/openrosa/apps/api/tests/fixtures/users']

def setUp(self):
self.user = User.objects.get(username='bob')
self.user = User.objects.create_user(
username='bob', password='bob', email='[email protected]'
)
self.token, _ = Token.objects.get_or_create(user=self.user)
UserProfile.objects.get_or_create(user=self.user)

Expand Down Expand Up @@ -587,72 +656,3 @@ def submit_data(identifier, survey_, username_, live_server_url, token_):
headers=headers
)
return response.status_code
=======
def test_submission_customizable_confirmation_message(self):
s = 'transport_with_custom_attribute'
media_file = '1335783522563.jpg'
xml_files = [
'transport_with_custom_attribute_01',
'transport_with_custom_attribute_02',
'transport_with_no_custom_attribute'
]

path = os.path.join(
self.main_directory,
'fixtures',
'transportation',
'instances',
s,
media_file,
)
with open(path, 'rb') as f:
f = InMemoryUploadedFile(
f,
'media_file',
media_file,
'image/jpg',
os.path.getsize(path),
None,
)
for xml_file in xml_files:
submission_path = os.path.join(
self.main_directory,
'fixtures',
'transportation',
'instances',
s,
xml_file + '.xml',
)
with open(submission_path) as sf:
data = {'xml_submission_file': sf, 'media_file': f}
request = self.factory.post('/submission', data)
response = self.view(request)
self.assertEqual(response.status_code, 401)

# rewind the file and redo the request since they were
# consumed
sf.seek(0)
f.seek(0)
request = self.factory.post('/submission', data)
auth = DigestAuth('bob', 'bobbob')
request.META.update(auth(request.META, response))
response = self.view(request, username=self.user.username)
if xml_file == 'transport_with_custom_attribute_01':
self.assertContains(
response, 'Custom submit message', status_code=201
)
elif xml_file == 'transport_with_custom_attribute_02':
self.assertContains(
response, 'Successful submission.', status_code=201
)
elif xml_file == (
'transport_with_custom_attribute_and_different_root'
):
self.assertContains(
response, 'Custom submit message', status_code=201
)
else:
self.assertContains(
response, 'Successful submission.', status_code=201
)
>>>>>>> @{-1}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.15 on 2024-09-29 18:31
# Generated by Django 4.2.15 on 2025-01-07 16:10

from django.conf import settings
from django.db import migrations, models
Expand All @@ -8,7 +8,7 @@ class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('logger', '0037_remove_xform_has_kpi_hooks_and_instance_posted_to_kpi'),
('logger', '0040_increase_file_fields_max_length'),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version='1.0' ?><transportation id="transportation_2011_07_25" xmlns:kobo="http://kobotoolbox.org/xforms"><transport><loop_over_transport_types_frequency><ambulance /><bicycle /><boat_canoe /><bus /><donkey_mule_cart /><keke_pepe /><lorry /><motorbike /><taxi></taxi><other></other></loop_over_transport_types_frequency></transport><meta><instanceID>uuid:7g0a1508-c3b7-4c99-be00-9b237c26bcfb</instanceID></meta></transportation>
<?xml version='1.0' ?><transportation id="transportation_2011_07_25" xmlns:kobo="http://kobotoolbox.org/xforms"><transport><loop_over_transport_types_frequency><ambulance /><bicycle /><boat_canoe /><bus /><donkey_mule_cart /><keke_pepe /><lorry /><motorbike /><taxi></taxi><other></other></loop_over_transport_types_frequency></transport><meta><instanceID>uuid:8g0a1508-c3b7-4c99-be00-9b237c26aaa</instanceID></meta></transportation>
1 change: 1 addition & 0 deletions kobo/apps/openrosa/libs/utils/logger_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ def get_soft_deleted_attachments(instance: Instance) -> list[Attachment]:

return soft_deleted_attachments


def _get_instance(
request: 'rest_framework.request.Request',
xml: str,
Expand Down

0 comments on commit 578b2be

Please sign in to comment.