aboutsummaryrefslogtreecommitdiff
path: root/test/requests/test_login_local.py
blob: 8e2dec4eb1303a4b61973d2947c98500e2828e30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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):
        super(TestLoginLocal, self).setUp()
        self.login_url = self.gn2_url +"/n/login"
        data = {
            "es_connection": self.es,
            "email_address": "test@user.com",
            "full_name": "Test User",
            "organization": "Test Organisation",
            "password": "test_password",
            "password_confirm": "test_password"
        }
        user_manager.basic_info = lambda : { "basic_info": "basic" }
        user_manager.RegisterUser(data)

    
    @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)
        index = result.content.find(expected)
        self.assertTrue(index >= 0, message)


def main(gn2, es):
    import unittest
    suite = unittest.TestSuite()
    suite.addTest(TestLoginLocal(methodName="testLoginNonRegisteredUser", gn2_url=gn2, es_url=es))
    suite.addTest(TestLoginLocal(methodName="testLoginWithRegisteredUserBothRememberMeAndImportCollectionsFalse", gn2_url=gn2, es_url=es))
    runner = unittest.TextTestRunner()
    runner.run(suite)

if __name__ == "__main__":
    import sys
    if len(sys.argv) < 3:
        raise Exception("Required arguments missing")
    else:
        main(sys.argv[1], sys.argv[2])