-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_squarespace_api.py
66 lines (49 loc) · 1.84 KB
/
test_squarespace_api.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
# coding=UTF-8
# Make some live requsets with the squarespace API. To use this test you have
# to create a file called "api_key" in the current directory that contains
# your API key. You can generate a key by opening up your site's admin page
# (https://<yoursite>.squarespace.com/config/) and going to Settings ->
# Adnvarced -> API Keys.
import logging
from os.path import exists
from squarespace import Squarespace
api_key = open('api_key').read().strip() if exists('api_key') else None
def test_squarespace_api():
if not api_key:
logging.warning('Missing "api_key" file.')
return True
store = Squarespace(api_key)
orders = store.orders()
assert len(orders) > 0
return True
def test_squarespace_api_pagination():
if not api_key:
logging.warning('Missing "api_key" file.')
return True
store = Squarespace(api_key)
orders = store.orders()
assert len(orders) == 50
next = store.next_page()
assert len(next) > 0
assert orders[0]['id'] != orders[1]['id']
return True
def test_squarespace_api_fulfillment():
"""Test fulfillment. This requires both an `api_key` and an `order_info`
file.
`api_key`:
A file containing only the squarespace API key.
`order_info`:
A file containing a single line consisting of:
`order_number`,`tracking_number`
"""
open_order = open('order_info').read().strip() if exists('order_info') else None
if not api_key:
logging.warning('Missing "api_key" file.')
return True
if not open_order:
logging.warning('Missing "order_info" file.')
return True
order_number, tracking_number = open_order.split(',', 2)
store = Squarespace(api_key)
order = store.order(order_number=order_number)
return store.fulfill(order['id'], tracking_number, 'USPS', 'First Class')