aboutsummaryrefslogtreecommitdiff
path: root/test/requests/test_login_local.py
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2018-02-21 12:51:34 +0300
committerMuriithi Frederick Muriuki2018-02-21 12:51:34 +0300
commita8e328a105dac1d137c3d08653c9164d489332b3 (patch)
treefdcc2a615b6278bc5798528cea52c43c0431e475 /test/requests/test_login_local.py
parentf8970931932ed9b32c078cf3f2a1203f50f73ab0 (diff)
downloadgenenetwork2-a8e328a105dac1d137c3d08653c9164d489332b3.tar.gz
Simplify test. Check for content, rather than url
* The test functions were very similar, so this commit refactors out the common test code to a single method, and passes in the data to the test using the parameterized package. * Check that the page content after a login attempt is the expected content, rather than checking the url.
Diffstat (limited to 'test/requests/test_login_local.py')
-rw-r--r--test/requests/test_login_local.py93
1 files changed, 39 insertions, 54 deletions
diff --git a/test/requests/test_login_local.py b/test/requests/test_login_local.py
index acad45c9..8e2dec4e 100644
--- a/test/requests/test_login_local.py
+++ b/test/requests/test_login_local.py
@@ -1,7 +1,11 @@
import requests
from wqflask import user_manager
+from parameterized import parameterized
from parametrized_test import ParametrizedTest
+login_link_text = '<a id="login_in" href="/n/login">Sign in</a>'
+logout_link_text = '<a id="login_out" title="Signed in as ." href="/n/logout">Sign out</a>'
+
class TestLoginLocal(ParametrizedTest):
def setUp(self):
@@ -18,61 +22,42 @@ class TestLoginLocal(ParametrizedTest):
user_manager.basic_info = lambda : { "basic_info": "basic" }
user_manager.RegisterUser(data)
- def testLoginNonRegisteredUser(self):
- data = {
- "email_address": "non@existent.email",
- "password": "doesitmatter?"
- }
- result = requests.post(self.login_url, data=data)
- self.assertEqual(result.url, self.login_url, "")
-
- def testLoginWithRegisteredUserBothRememberMeAndImportCollectionsFalse(self):
- data = {
- "email_address": "test@user.com",
- "password": "test_password"
- }
- result = requests.post(self.login_url, data=data)
- self.assertEqual(
- result.url
- , self.gn2_url+"/?import_collections=false"
- , "Login should have been successful")
-
- def testLoginWithRegisteredUserImportCollectionsTrueAndRememberMeFalse(self):
- data = {
- "email_address": "test@user.com",
- "password": "test_password",
- "import_collections": "y"
- }
- result = requests.post(self.login_url, data=data)
- self.assertEqual(
- result.url
- , self.gn2_url+"/?import_collections=true"
- , "Login should have been successful")
-
- def testLoginWithRegisteredUserImportCollectionsFalseAndRememberMeTrue(self):
- data = {
- "email_address": "test@user.com",
- "password": "test_password",
- "remember_me": "y"
- }
- result = requests.post(self.login_url, data=data)
- self.assertEqual(
- result.url
- , self.gn2_url+"/?import_collections=false"
- , "Login should have been successful")
-
- def testLoginWithRegisteredUserBothImportCollectionsAndRememberMeTrue(self):
- data = {
- "email_address": "test@user.com",
- "password": "test_password",
- "remember_me": "y",
- "import_collections": "y"
- }
+
+ @parameterized.expand([
+ (
+ {
+ "email_address": "non@existent.email",
+ "password": "doesitmatter?"
+ }, login_link_text, "Login should have failed with the wrong user details."),
+ (
+ {
+ "email_address": "test@user.com",
+ "password": "test_password"
+ }, logout_link_text, "Login should have been successful with correct user details and neither import_collections nor remember_me set"),
+ (
+ {
+ "email_address": "test@user.com",
+ "password": "test_password",
+ "import_collections": "y"
+ }, logout_link_text, "Login should have been successful with correct user details and only import_collections set"),
+ (
+ {
+ "email_address": "test@user.com",
+ "password": "test_password",
+ "remember_me": "y"
+ }, logout_link_text, "Login should have been successful with correct user details and only remember_me set"),
+ (
+ {
+ "email_address": "test@user.com",
+ "password": "test_password",
+ "remember_me": "y",
+ "import_collections": "y"
+ }, logout_link_text, "Login should have been successful with correct user details, and both remember_me, and import_collections set")
+ ])
+ def testLogin(self, data, expected, message):
result = requests.post(self.login_url, data=data)
- self.assertEqual(
- result.url
- , self.gn2_url+"/?import_collections=true"
- , "Login should have been successful")
+ index = result.content.find(expected)
+ self.assertTrue(index >= 0, message)
def main(gn2, es):