|
1 | 1 | import pytest |
| 2 | +from easypost.constant import ( |
| 3 | + _FILTERS_KEY, |
| 4 | + _TEST_FAILED_INTENTIONALLY_ERROR, |
| 5 | + NO_MORE_PAGES_ERROR, |
| 6 | +) |
2 | 7 | from easypost.models import ( |
3 | 8 | Brand, |
4 | 9 | User, |
@@ -76,3 +81,33 @@ def test_user_update_brand(prod_client): |
76 | 81 | assert isinstance(brand, Brand) |
77 | 82 | assert str.startswith(brand.id, "brd_") |
78 | 83 | assert brand.color == color |
| 84 | + |
| 85 | + |
| 86 | +@pytest.mark.vcr() |
| 87 | +def test_user_all_children(prod_client, page_size): |
| 88 | + children_data = prod_client.user.all_children(page_size=page_size) |
| 89 | + |
| 90 | + children_array = children_data["children"] |
| 91 | + assert len(children_array) <= page_size |
| 92 | + assert all(isinstance(child, User) for child in children_array) |
| 93 | + |
| 94 | + has_more = children_data["has_more"] |
| 95 | + assert isinstance(has_more, bool) |
| 96 | + |
| 97 | + |
| 98 | +@pytest.mark.vcr() |
| 99 | +def test_user_children_get_next_page(prod_client, page_size): |
| 100 | + try: |
| 101 | + first_page = prod_client.user.all_children(page_size=page_size) |
| 102 | + next_page = prod_client.user.get_next_page_of_children(children=first_page, page_size=page_size) |
| 103 | + |
| 104 | + first_id_of_first_page = first_page["children"][0].id |
| 105 | + first_id_of_second_page = next_page["children"][0].id |
| 106 | + |
| 107 | + assert first_id_of_first_page != first_id_of_second_page |
| 108 | + |
| 109 | + # Verify that the filters are being passed along for behind-the-scenes reference |
| 110 | + assert first_page[_FILTERS_KEY] == next_page[_FILTERS_KEY] |
| 111 | + except Exception as e: |
| 112 | + if e.message != NO_MORE_PAGES_ERROR: |
| 113 | + raise Exception(_TEST_FAILED_INTENTIONALLY_ERROR) |
0 commit comments