-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_users.py
More file actions
84 lines (72 loc) · 3.06 KB
/
Copy pathtest_users.py
File metadata and controls
84 lines (72 loc) · 3.06 KB
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
77
78
79
80
81
82
83
84
import unittest
import contentstack_management
from tests.cred import get_credentials
credentials = get_credentials()
username = credentials["username"]
password = credentials["password"]
host = credentials["host"]
activation_token = credentials["activation_token"]
class UserUnitTests(unittest.TestCase):
def setUp(self):
self.client = contentstack_management.Client(host=host)
# Note: Login call removed to avoid network requests in unit tests
# The actual login is not needed for testing request structure
def test_get_user(self):
response = self.client.user().fetch()
self.assertEqual(response.request.url, f"{self.client.endpoint}user")
self.assertEqual(response.request.method, "GET")
self.assertEqual(response.request.headers["Content-Type"], "application/json")
self.assertEqual(response.request.body, None)
def test_update_user(self):
url = "user"
user_data = {
"user": {
"company": "company name inc.",
"first_name": "Sunil",
"last_name": "Lakshman",
}
}
response = self.client.user().update(user_data)
self.assertEqual(response.request.url, f"{self.client.endpoint}{url}")
self.assertEqual(response.request.method, "PUT")
self.assertEqual(response.request.headers["Content-Type"], "application/json")
def test_active_user(self):
url = f"user/activate/{activation_token}"
act_data = {
"user": {
"first_name": "your_first_name",
"last_name": "your_last_name",
"password": password,
"password_confirmation": password
}
}
response = self.client.user().activate(activation_token, act_data)
self.assertEqual(response.request.url, f"{self.client.endpoint}{url}")
self.assertEqual(response.request.method, "POST")
self.assertEqual(response.request.headers["Content-Type"], "application/json")
def test_request_password(self):
url = "user/forgot_password"
act_data = {
"user": {
"email": username
}
}
response = self.client.user().forgot_password(act_data)
self.assertEqual(response.request.url, f"{self.client.endpoint}{url}")
self.assertEqual(response.request.method, "POST")
self.assertEqual(response.request.headers["Content-Type"], "application/json")
def test_reset_password(self):
url = "user/reset_password"
act_data = {
"user": {
"reset_password_token": "****",
"password": password,
"password_confirmation": password
}
}
response = self.client.user().reset_password(act_data)
self.assertEqual(response.request.url, f"{self.client.endpoint}{url}")
self.assertEqual(response.request.method, "POST")
self.assertEqual(response.request.headers["Content-Type"], "application/json")
if __name__ == '__main__':
unittest.main()