-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathciperpus_test_logic.py
74 lines (57 loc) · 1.82 KB
/
ciperpus_test_logic.py
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
from ciperpus_exception import *
from ciperpus_test_exception import *
from ciperpus_test_context import *
from ciperpus_client import *
import unittest
class ciperpus_test_logic:
def __init__(self, client=None):
if client is None:
self.client = get_client()
else:
self.client = client
def login(self, case, data):
username = data["username"]
password = data["password"]
valid_login = data["valid_login"]
expect_error = None
if username == "":
if password == "":
expect_error = login_error_code.username_password_kosong
else:
expect_error = login_error_code.username_kosong
elif password == "":
expect_error = login_error_code.password_kosong
elif username not in valid_login:
expect_error = login_error_code.username_password_salah
elif valid_login[username] != password:
expect_error = login_error_code.username_password_salah
with ciperpus_test_context_case(case, expect_error) as context:
self.client.login(username, password, data["use_button"])
def logout(self, expect_error=None):
with ciperpus_test_context(expect_error) as context:
self.client.logout()
def dashboard(self, expect_error=None):
with ciperpus_test_context(expect_error) as context:
self.client.logout()
@property
def url(self):
return self.client.url
def check_url(self, endpoint):
return self.client.check_url(endpoint)
def close(self):
return self.client.close()
def quit(self):
return self.client.quit()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.quit()
logic_instance = None
def create_logic(client=None):
global logic_instance
logic_instance = ciperpus_test_logic(client)
return logic_instance
def get_logic(client=None):
global logic_instance
logic_instance = logic_instance or create_logic(client)
return logic_instance