-
Notifications
You must be signed in to change notification settings - Fork 388
Expand file tree
/
Copy pathapi_version_test.py
More file actions
61 lines (47 loc) · 2.26 KB
/
Copy pathapi_version_test.py
File metadata and controls
61 lines (47 loc) · 2.26 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
import shopify
from test.test_helper import TestCase
class ApiVersionTest(TestCase):
"""
Api Version Tests
"""
def tearDown(self):
shopify.ApiVersion.clear_defined_versions()
shopify.ApiVersion.define_known_versions()
def test_unstable_api_path_returns_correct_url(self):
self.assertEqual(
"https://fakeshop.myshopify.com/admin/api/unstable",
shopify.Unstable().api_path("https://fakeshop.myshopify.com"),
)
def test_coerce_to_version_returns_known_versions(self):
v1 = shopify.Unstable()
v2 = shopify.ApiVersion.define_version(shopify.Release("2019-01"))
self.assertNotEqual(v1, None)
self.assertEqual(v1, shopify.ApiVersion.coerce_to_version("unstable"))
self.assertEqual(v2, shopify.ApiVersion.coerce_to_version("2019-01"))
def test_coerce_to_version_raises_with_string_that_does_not_match_known_version(self):
with self.assertRaises(shopify.VersionNotFoundError):
shopify.ApiVersion.coerce_to_version("crazy-name")
def test_coerce_to_version_creates_new_release_on_the_fly(self):
new_version = "2025-01"
coerced_version = shopify.ApiVersion.coerce_to_version(new_version)
self.assertIsInstance(coerced_version, shopify.Release)
self.assertEqual(coerced_version.name, new_version)
self.assertEqual(
coerced_version.api_path("https://test.myshopify.com"),
f"https://test.myshopify.com/admin/api/{new_version}",
)
# Verify that the new version is not added to the known versions
self.assertNotIn(new_version, shopify.ApiVersion.versions)
class ReleaseTest(TestCase):
def test_raises_if_format_invalid(self):
with self.assertRaises(shopify.InvalidVersionError):
shopify.Release("crazy-name")
def test_release_api_path_returns_correct_url(self):
self.assertEqual(
"https://fakeshop.myshopify.com/admin/api/2019-04",
shopify.Release("2019-04").api_path("https://fakeshop.myshopify.com"),
)
def test_two_release_versions_with_same_number_are_equal(self):
version1 = shopify.Release("2019-01")
version2 = shopify.Release("2019-01")
self.assertEqual(version1, version2)