-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathtest_user.py
More file actions
110 lines (74 loc) · 2.97 KB
/
test_user.py
File metadata and controls
110 lines (74 loc) · 2.97 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import pytest
from easypost.constant import (
_TEST_FAILED_INTENTIONALLY_ERROR,
NO_MORE_PAGES_ERROR,
)
from easypost.models import (
Brand,
User,
)
@pytest.mark.vcr()
def test_user_create(prod_client):
user = prod_client.user.create(name="Test User")
assert isinstance(user, User)
assert str.startswith(user.id, "user_")
assert user.name == "Test User"
# Delete the user so we don't clutter up the test environment
prod_client.user.delete(user.id)
@pytest.mark.vcr()
def test_user_retrieve(prod_client):
authenticated_user = prod_client.user.retrieve_me()
user = prod_client.user.retrieve(authenticated_user["id"])
assert isinstance(user, User)
assert str.startswith(user.id, "user_")
@pytest.mark.vcr()
def test_user_retrieve_no_id(prod_client):
"""If no ID is specified when retrieving a user, we'll retrieve the authenticated user."""
user = prod_client.user.retrieve()
assert isinstance(user, User)
assert str.startswith(user.id, "user_")
@pytest.mark.vcr()
def test_user_retrieve_me(prod_client):
user = prod_client.user.retrieve_me()
assert isinstance(user, User)
assert str.startswith(user.id, "user_")
@pytest.mark.vcr()
def test_user_update(prod_client):
user = prod_client.user.retrieve_me()
test_name = "New Name"
updated_user = prod_client.user.update(user.id, name=test_name)
assert isinstance(updated_user, User)
assert str.startswith(updated_user.id, "user_")
assert updated_user.name == test_name
@pytest.mark.vcr()
def test_user_delete(prod_client):
user = prod_client.user.create(name="Test User")
# Nothing gets returned here, simply ensure no error gets raised
prod_client.user.delete(user.id)
@pytest.mark.vcr()
def test_user_update_brand(prod_client):
user = prod_client.user.retrieve_me()
color = "#123456"
brand = prod_client.user.update_brand(user.id, color=color)
assert isinstance(brand, Brand)
assert str.startswith(brand.id, "brd_")
assert brand.color == color
@pytest.mark.vcr()
def test_user_all_children(prod_client, page_size):
children_data = prod_client.user.all_children(page_size=page_size)
children_array = children_data["children"]
assert len(children_array) <= page_size
assert all(isinstance(child, User) for child in children_array)
has_more = children_data["has_more"]
assert isinstance(has_more, bool)
@pytest.mark.vcr()
def test_user_children_get_next_page(prod_client, page_size):
try:
first_page = prod_client.user.all_children(page_size=page_size)
next_page = prod_client.user.get_next_page_of_children(children=first_page, page_size=page_size)
first_id_of_first_page = first_page["children"][0].id
first_id_of_second_page = next_page["children"][0].id
assert first_id_of_first_page != first_id_of_second_page
except Exception as e:
if e.message != NO_MORE_PAGES_ERROR:
raise Exception(_TEST_FAILED_INTENTIONALLY_ERROR)