summaryrefslogtreecommitdiff
path: root/wrappers/python/tests.py
blob: f7b8117265602a71164f270dd50486ca075d274c (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
#!/usr/bin/env python3

import unittest
import eduvpn_common.main as eduvpn
from eduvpn_common.state import State, StateType
import webbrowser
import sys
import os
import json

# Import project root directory where the selenium python utility is
sys.path.append(
    os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
)

from selenium_eduvpn import login_eduvpn


class ConfigTests(unittest.TestCase):
    def testConfig(self):
        _eduvpn = eduvpn.EduVPN(
            "org.letsconnect-vpn.app.linux", "0.1.0", "testconfigs", "en"
        )
        # This can throw an exception
        _eduvpn.register()

        @_eduvpn.event.on(State.OAUTH_STARTED, StateType.ENTER)
        def oauth_initialized(old_state, url_json):
            login_eduvpn(url_json)

        server_uri = os.getenv("SERVER_URI")
        if not server_uri:
            print("No SERVER_URI environment variable given, skipping...")
            _eduvpn.deregister()
            return

        # This can throw an exception
        _eduvpn.add_custom_server(server_uri)
        _eduvpn.get_config_custom_server(server_uri)

        # Deregister
        _eduvpn.deregister()

    def testDoubleRegister(self):
        _eduvpn = eduvpn.EduVPN(
            "org.letsconnect-vpn.app.linux", "0.1.0", "testconfigs", "en"
        )
        # This can throw an exception
        _eduvpn.register()
        # This should throw
        try:
            _eduvpn.register()
        except Exception as e:
            return
        self.fail("No exception thrown on second register")


if __name__ == "__main__":
    unittest.main()