aboutsummaryrefslogtreecommitdiff
path: root/test/requests/test_login_local.py
blob: bced1ee9d13122c5e9c7570f1e672538cd4908e3 (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
import requests
from wqflask import user_manager
from parametrized_test import ParametrizedTest

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)

    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)
        print("THE COOKIES? ", result.cookies)
        self.assertEqual(
            result.url
            , self.gn2_url+"/?import_collections=false"
            , "Login should have been successful")
        


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])