Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Refactor mock_post setup
Browse files Browse the repository at this point in the history
  • Loading branch information
timmow committed Jul 4, 2014
1 parent 6f06002 commit 33c2df2
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions tests/admin/test_file_upload_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,7 @@ def test_data_hits_the_backdrop_client_when_uploading_csv(
""" This seems to be testing things the write api tests should... """
self._sign_in("test@example.com")
self._drop_collection('test_upload_integration')

mock_post = Mock()
client_instance = Mock()
client_instance.post = mock_post
mock_construction_helper = Mock()
mock_construction_helper.return_value = client_instance
mock_client_class.from_group_and_type = mock_construction_helper

mock_post = get_mock_post(mock_client_class)
response = self.client.post(
'test_upload_integration/upload',
data = {
Expand Down Expand Up @@ -100,12 +93,7 @@ def test_data_hits_the_backdrop_client_when_uploading_xlsx(self, mock_client_cla
self._drop_collection('integration_test_excel_data_set')
self._sign_in("test@example.com")

mock_post = Mock()
client_instance = Mock()
client_instance.post = mock_post
mock_construction_helper = Mock()
mock_construction_helper.return_value = client_instance
mock_client_class.from_group_and_type = mock_construction_helper
mock_post = get_mock_post(mock_client_class)

fixture_path = os.path.join('features', 'fixtures', 'data.xlsx')
response = self.client.post(
Expand Down Expand Up @@ -154,12 +142,7 @@ def test_upload_applies_filters(self, mock_client_class):
self._drop_collection("evl_ceg_data")
self._sign_in("test@example.com")

mock_post = Mock()
client_instance = Mock()
client_instance.post = mock_post
mock_construction_helper = Mock()
mock_construction_helper.return_value = client_instance
mock_client_class.from_group_and_type = mock_construction_helper
mock_post = get_mock_post(mock_client_class)

fixture_path = os.path.join('features', 'fixtures', 'contrib',
'CEG Transaction Tracker.xlsx')
Expand Down Expand Up @@ -225,3 +208,12 @@ def do_simple_file_post(self):
'file': (StringIO('foo, bar'), 'a_big_csv.csv')
}
)

def get_mock_post(mock_client_class):
mock_post = Mock()
client_instance = Mock()
client_instance.post = mock_post
mock_construction_helper = Mock()
mock_construction_helper.return_value = client_instance
mock_client_class.from_group_and_type = mock_construction_helper
return mock_post

0 comments on commit 33c2df2

Please sign in to comment.