Skip to content

Commit

Permalink
HDX-9927 fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ccataalin committed Jun 29, 2024
1 parent 3e7d444 commit c97c5f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -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',
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c97c5f1

Please sign in to comment.