Skip to content

Commit

Permalink
Include mock tests
Browse files Browse the repository at this point in the history
Fix failing Tests
  • Loading branch information
WinnyTroy committed Apr 6, 2020
1 parent 4d989e4 commit 45561d9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions onadata/apps/viewer/tests/test_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,37 @@ def test_create_external_export_url(self):
self.assertEqual(response.status_code, 302)
self.assertEqual(Export.objects.count(), num_exports + 1)

def test_external_export_metadata_retrieved_from_master_db(self):
# first publish a form and make a submission
self._publish_transportation_form()
self._submit_transport_instance()

server = 'http://localhost:8080/xls/23fa4c38c0054748a984ffd89021a295'
data_value = 'template 1 |{0}'.format(server)

with patch('onadata.libs.utils.export_tools._get_server_from_metadata'
) as mock:
def _side_effect(*args):
"""
We want to raise a DoesNotExist exception
only on the first call of our mock
"""
raise MetaData.DoesNotExist()

with self.assertRaises(MetaData.DoesNotExist):
mock.side_effect = _side_effect()
mock(self.xform, data_value)

def __second_side_effect(*args):
"""
Change the side effect so that on the second round we do not
raise a DoesNotExist exception
"""
return None

mock.side_effect = __second_side_effect
mock(self.xform, data_value)

@patch('onadata.apps.viewer.tasks.get_object_or_404')
def test_create_external_export_url_with_non_existing_export_id(
self, mock_404):
Expand Down

0 comments on commit 45561d9

Please sign in to comment.