From f0f6a8cd175e7507b3dddd6b1d93be5f24a8730d Mon Sep 17 00:00:00 2001 From: longze chen Date: Wed, 5 Apr 2017 16:34:47 -0400 Subject: [PATCH] Add tests. --- tests/test_views.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/test_views.py b/tests/test_views.py index 4e3a29c279ed..1c05ede9e8e9 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -3488,6 +3488,7 @@ def setUp(self): self.user_auth = AuthUserFactory() self.auth = Auth(user=self.user_auth) self.next_url = web_url_for('my_projects', _absolute=True) + self.invalid_campaign = 'invalid_campaign' def test_osf_login_with_auth(self): # login: user with auth @@ -3600,7 +3601,7 @@ def test_campaign_register_with_auth(self): assert_equal(data.get('status_code'), http.FOUND) assert_equal(data.get('next_url'), campaign_url_for(campaign)) - def test_campaign_register_without_campaign(self): + def test_campaign_register_without_auth(self): for campaign in get_campaigns(): if is_institution_login(campaign): continue @@ -3668,6 +3669,31 @@ def test_campaign_next_url_register_without_auth(self): web_url_for('auth_login', next= next_url, _absolute=True) ) + def test_invalid_campaign_login_without_auth(self): + data = login_and_register_handler( + self.no_auth, + login=True, + campaign=self.invalid_campaign, + next_url=self.next_url + ) + redirect_url = web_url_for('auth_login', campaigns=None, next=self.next_url) + assert_equal(data['status_code'], http.FOUND) + assert_equal(data['next_url'], redirect_url) + assert_equal(data['campaign'], None) + + def test_invalid_campaign_register_without_auth(self): + data = login_and_register_handler( + self.no_auth, + login=False, + campaign=self.invalid_campaign, + next_url=self.next_url + ) + redirect_url = web_url_for('auth_register', campaigns=None, next=self.next_url) + assert_equal(data['status_code'], http.FOUND) + assert_equal(data['next_url'], redirect_url) + assert_equal(data['campaign'], None) + + # The following two tests handles the special case for `claim_user_registered` # When an authenticated user clicks the claim confirmation clink, there are two ways to trigger this flow: # 1. If the authenticated user is already a contributor to the project, OSF will ask the user to sign out