diff --git a/ckanext-hdx_org_group/ckanext/hdx_org_group/tests/test_controller/test_member_controller.py b/ckanext-hdx_org_group/ckanext/hdx_org_group/tests/test_controller/test_member_controller.py index 5e58a487f5..e1bfdcdae6 100644 --- a/ckanext-hdx_org_group/ckanext/hdx_org_group/tests/test_controller/test_member_controller.py +++ b/ckanext-hdx_org_group/ckanext/hdx_org_group/tests/test_controller/test_member_controller.py @@ -138,7 +138,6 @@ def test_members(self, render, app): context = {'model': model, 'session': model.Session, 'user': orgadmin} orgadmin_token = factories.APIToken(user='orgadmin', expires_in=2, unit=60 * 60)['token'] auth = {'Authorization': orgadmin_token} - # test_client = self.get_backwards_compatible_test_client() member_with_name_list = _get_action('member_list')(context, { 'id': 'hdx-test-org', @@ -236,16 +235,17 @@ def _populate_member_names(self, members, member_with_name_list): ret = [next(u[4] for u in member_with_name_list if u[0] == member[0]) for member in members] return ret + @pytest.mark.usefixtures('with_request_context') @mock.patch('ckanext.hdx_users.helpers.mailer._mail_recipient_html') - def test_request_membership(self, _mail_recipient_html): + def test_request_membership(self, _mail_recipient_html, app): test_sysadmin = 'testsysadmin' test_username = 'johndoe1' - test_client = self.get_backwards_compatible_test_client() + test_username_token = factories.APIToken(user=test_username, expires_in=2, unit=60 * 60)['token'] context = {'model': model, 'session': model.Session, 'user': test_sysadmin} # removing one member from organization url = h.url_for('hdx_members.member_delete', id='hdx-test-org') - test_client.post(url, params={'user': 'johndoe1'}, extra_environ={"REMOTE_USER": test_sysadmin}) + app.post(url, params={'user': 'johndoe1'}, extra_environ={"REMOTE_USER": test_sysadmin}) member_list = self._get_action('member_list')(context, { 'id': 'hdx-test-org', @@ -262,9 +262,9 @@ def test_request_membership(self, _mail_recipient_html): # send a membership request url = h.url_for('ytp_request.new') - ret_page = test_client.post(url, params={'organization': 'hdx-test-org', 'role': 'member', 'save': 'save', - 'message': 'add me to your organization'}, - extra_environ={"REMOTE_USER": test_username}) + ret_page = app.post(url, params={'organization': 'hdx-test-org', 'role': 'member', 'save': 'save', + 'message': 'add me to your organization'}, + headers={'Authorization': test_username_token}) member_requests = self._get_action('member_request_list')(context, {'group': 'hdx-test-org'}) assert len(member_requests) == 1, 'Exactly one member request should exist for this org' assert member_requests[0].get('user_name') == test_username @@ -280,16 +280,17 @@ def _populate_member_names(self, members, member_with_name_list): ret = [next(u[4] for u in member_with_name_list if u[0] == member[0]) for member in members] return ret + @pytest.mark.usefixtures('with_request_context') @mock.patch('ckanext.hdx_users.helpers.mailer._mail_recipient_html') - def test_request_membership(self, _mail_recipient_html): + def test_request_membership(self, _mail_recipient_html, app): test_sysadmin = 'testsysadmin' test_username = 'johndoe1' - test_client = self.get_backwards_compatible_test_client() + test_username_token = factories.APIToken(user=test_username, expires_in=2, unit=60 * 60)['token'] context = {'model': model, 'session': model.Session, 'user': test_sysadmin} # removing one member from organization url = h.url_for('hdx_members.member_delete', id='hdx-test-org') - test_client.post(url, params={'user': 'johndoe1'}, extra_environ={"REMOTE_USER": test_sysadmin}) + app.post(url, params={'user': 'johndoe1'}, extra_environ={"REMOTE_USER": test_sysadmin}) member_list = self._get_action('member_list')(context, { 'id': 'hdx-test-org', @@ -306,9 +307,9 @@ def test_request_membership(self, _mail_recipient_html): # send a membership request url = h.url_for('ytp_request.new') - ret_page = test_client.post(url, params={'organization': 'hdx-test-org', 'role': 'editor', 'save': 'save', - 'message': 'add me to your organization'}, - extra_environ={"REMOTE_USER": test_username}) + ret_page = app.post(url, params={'organization': 'hdx-test-org', 'role': 'editor', 'save': 'save', + 'message': 'add me to your organization'}, + headers={'Authorization': test_username_token}) member_requests = self._get_action('member_request_list')(context, {'group': 'hdx-test-org'}) assert len(member_requests) == 1, 'Exactly one member request should exist for this org' assert member_requests[0].get('user_name') == test_username diff --git a/ckanext-hdx_pages/ckanext/hdx_pages/tests/test_controller.py b/ckanext-hdx_pages/ckanext/hdx_pages/tests/test_controller.py index 8fb7cabe80..fcee3f0691 100644 --- a/ckanext-hdx_pages/ckanext/hdx_pages/tests/test_controller.py +++ b/ckanext-hdx_pages/ckanext/hdx_pages/tests/test_controller.py @@ -244,7 +244,7 @@ def test_page_delete(self, app): eldeleted_page = _get_action('page_show')(context_sysadmin, {'id': page_eldeleted.get('name')}) try: url = h.url_for(u'hdx_custom_page.delete_page', id=eldeleted_page.get('id')) - page_delete = app.post(url, extra_environ={"REMOTE_USER": USER}) + page_delete = app.post(url, headers={'Authorization': self._get_token_for_user(USER)}) assert 'Page not found' in page_delete.body, 'page doesn\'t exist' assert '404 Not Found'.lower() in page_delete.status.lower() except logic.NotAuthorized: