upcdatabase 0.1.0__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {upcdatabase-0.1.0/src/upcdatabase.egg-info → upcdatabase-0.1.2}/PKG-INFO +4 -2
- {upcdatabase-0.1.0 → upcdatabase-0.1.2}/pyproject.toml +4 -2
- {upcdatabase-0.1.0 → upcdatabase-0.1.2}/src/upcdatabase/client.py +4 -3
- {upcdatabase-0.1.0 → upcdatabase-0.1.2/src/upcdatabase.egg-info}/PKG-INFO +4 -2
- {upcdatabase-0.1.0 → upcdatabase-0.1.2}/src/upcdatabase.egg-info/SOURCES.txt +2 -1
- {upcdatabase-0.1.0 → upcdatabase-0.1.2}/src/upcdatabase.egg-info/requires.txt +2 -0
- {upcdatabase-0.1.0 → upcdatabase-0.1.2}/tests/test_client.py +5 -5
- upcdatabase-0.1.2/tests/test_upc_lookup.py +118 -0
- {upcdatabase-0.1.0 → upcdatabase-0.1.2}/LICENSE +0 -0
- {upcdatabase-0.1.0 → upcdatabase-0.1.2}/MANIFEST.in +0 -0
- {upcdatabase-0.1.0 → upcdatabase-0.1.2}/README.md +0 -0
- {upcdatabase-0.1.0 → upcdatabase-0.1.2}/setup.cfg +0 -0
- {upcdatabase-0.1.0 → upcdatabase-0.1.2}/setup.py +0 -0
- {upcdatabase-0.1.0 → upcdatabase-0.1.2}/src/upcdatabase/__init__.py +0 -0
- {upcdatabase-0.1.0 → upcdatabase-0.1.2}/src/upcdatabase.egg-info/dependency_links.txt +0 -0
- {upcdatabase-0.1.0 → upcdatabase-0.1.2}/src/upcdatabase.egg-info/top_level.txt +0 -0
- {upcdatabase-0.1.0 → upcdatabase-0.1.2}/tests/__init__.py +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: upcdatabase
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Python library for accessing the UPC Database API
|
|
5
|
-
Author-email:
|
|
5
|
+
Author-email: Nick Tak <nickle87@gmail.com>
|
|
6
6
|
License: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/Nickatak/upcdatabase
|
|
8
8
|
Project-URL: Repository, https://github.com/Nickatak/upcdatabase.git
|
|
@@ -30,6 +30,8 @@ Requires-Dist: black>=21.0; extra == "dev"
|
|
|
30
30
|
Requires-Dist: isort>=5.0.0; extra == "dev"
|
|
31
31
|
Requires-Dist: mypy>=0.900; extra == "dev"
|
|
32
32
|
Requires-Dist: pre-commit>=2.20.0; extra == "dev"
|
|
33
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
33
35
|
Dynamic: license-file
|
|
34
36
|
|
|
35
37
|
# upcdatabase
|
|
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "upcdatabase"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.2"
|
|
8
8
|
description = "Python library for accessing the UPC Database API"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.7"
|
|
11
11
|
license = {text = "MIT"}
|
|
12
12
|
authors = [
|
|
13
|
-
{name = "
|
|
13
|
+
{name = "Nick Tak", email = "nickle87@gmail.com"}
|
|
14
14
|
]
|
|
15
15
|
classifiers = [
|
|
16
16
|
"Development Status :: 3 - Alpha",
|
|
@@ -43,6 +43,8 @@ dev = [
|
|
|
43
43
|
"isort>=5.0.0",
|
|
44
44
|
"mypy>=0.900",
|
|
45
45
|
"pre-commit>=2.20.0",
|
|
46
|
+
"build>=1.0.0",
|
|
47
|
+
"twine>=4.0.0",
|
|
46
48
|
]
|
|
47
49
|
|
|
48
50
|
[tool.setuptools.packages.find]
|
|
@@ -62,13 +62,14 @@ class UPCDatabase:
|
|
|
62
62
|
"""
|
|
63
63
|
url = f"{self.BASE_URL}{endpoint}"
|
|
64
64
|
|
|
65
|
-
# Add
|
|
65
|
+
# Add bearer token to headers
|
|
66
|
+
headers = {"Authorization": f"Bearer {self.api_key}"}
|
|
67
|
+
|
|
66
68
|
if params is None:
|
|
67
69
|
params = {}
|
|
68
|
-
params["key"] = self.api_key
|
|
69
70
|
|
|
70
71
|
try:
|
|
71
|
-
response = self.session.get(url, params=params, timeout=10)
|
|
72
|
+
response = self.session.get(url, params=params, headers=headers, timeout=10)
|
|
72
73
|
response.raise_for_status()
|
|
73
74
|
return response.json()
|
|
74
75
|
except requests.exceptions.HTTPError as e:
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: upcdatabase
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Python library for accessing the UPC Database API
|
|
5
|
-
Author-email:
|
|
5
|
+
Author-email: Nick Tak <nickle87@gmail.com>
|
|
6
6
|
License: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/Nickatak/upcdatabase
|
|
8
8
|
Project-URL: Repository, https://github.com/Nickatak/upcdatabase.git
|
|
@@ -30,6 +30,8 @@ Requires-Dist: black>=21.0; extra == "dev"
|
|
|
30
30
|
Requires-Dist: isort>=5.0.0; extra == "dev"
|
|
31
31
|
Requires-Dist: mypy>=0.900; extra == "dev"
|
|
32
32
|
Requires-Dist: pre-commit>=2.20.0; extra == "dev"
|
|
33
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
33
35
|
Dynamic: license-file
|
|
34
36
|
|
|
35
37
|
# upcdatabase
|
|
@@ -75,8 +75,8 @@ class TestUPCDatabase(unittest.TestCase):
|
|
|
75
75
|
with UPCDatabase(api_key="test_key") as client:
|
|
76
76
|
self.assertEqual(client.api_key, "test_key")
|
|
77
77
|
|
|
78
|
-
def
|
|
79
|
-
"""Test that API key is added
|
|
78
|
+
def test_api_key_in_bearer_token(self):
|
|
79
|
+
"""Test that API key is added as bearer token in Authorization header"""
|
|
80
80
|
with patch("upcdatabase.client.requests.Session.get") as mock_get:
|
|
81
81
|
mock_response = Mock()
|
|
82
82
|
mock_response.json.return_value = {}
|
|
@@ -84,10 +84,10 @@ class TestUPCDatabase(unittest.TestCase):
|
|
|
84
84
|
|
|
85
85
|
self.client.lookup("123")
|
|
86
86
|
|
|
87
|
-
# Check that the get call includes the
|
|
87
|
+
# Check that the get call includes the bearer token
|
|
88
88
|
call_args = mock_get.call_args
|
|
89
|
-
self.assertIn("
|
|
90
|
-
self.assertEqual(call_args[1]["
|
|
89
|
+
self.assertIn("headers", call_args[1])
|
|
90
|
+
self.assertEqual(call_args[1]["headers"]["Authorization"], f"Bearer {self.api_key}")
|
|
91
91
|
|
|
92
92
|
|
|
93
93
|
class TestUPCDatabaseError(unittest.TestCase):
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""Test UPC lookup for testing code UPC"""
|
|
2
|
+
|
|
3
|
+
import unittest
|
|
4
|
+
from unittest.mock import Mock, patch
|
|
5
|
+
|
|
6
|
+
from upcdatabase import UPCDatabase
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class TestUPCLookup(unittest.TestCase):
|
|
10
|
+
"""Test cases for UPC lookup functionality.
|
|
11
|
+
|
|
12
|
+
This test suite validates the UPC lookup endpoint for the specific test UPC code
|
|
13
|
+
0111222333446, which is a special testing code provided by the UPC Database API.
|
|
14
|
+
|
|
15
|
+
The tests verify:
|
|
16
|
+
- Successful product lookup by UPC code
|
|
17
|
+
- Correct parsing of API response data
|
|
18
|
+
- Bearer token authentication is properly sent
|
|
19
|
+
- API endpoint is called with the correct URL format
|
|
20
|
+
- Response data matches expected structure and values for the testing code
|
|
21
|
+
|
|
22
|
+
Test UPC: 0111222333446
|
|
23
|
+
Product: UPC Database Testing Code (used for testing API integration)
|
|
24
|
+
MSRP: $123.45
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def setUp(self):
|
|
28
|
+
"""Set up test fixtures"""
|
|
29
|
+
self.api_key = "test_api_key"
|
|
30
|
+
self.client = UPCDatabase(api_key=self.api_key)
|
|
31
|
+
self.test_upc = "0111222333446"
|
|
32
|
+
self.expected_response = {
|
|
33
|
+
"added_time": "2011-06-03 19:45:37",
|
|
34
|
+
"modified_time": "2020-03-17 14:59:12",
|
|
35
|
+
"title": "UPC Database Testing Code",
|
|
36
|
+
"alias": "Testing Code",
|
|
37
|
+
"description": "http://upcdatabase.org/code/0111222333446",
|
|
38
|
+
"brand": "",
|
|
39
|
+
"manufacturer": "",
|
|
40
|
+
"msrp": "123.45",
|
|
41
|
+
"ASIN": "",
|
|
42
|
+
"category": "",
|
|
43
|
+
"categories": "",
|
|
44
|
+
"stores": [],
|
|
45
|
+
"barcode": "0111222333446",
|
|
46
|
+
"success": True,
|
|
47
|
+
"timestamp": 1770332489,
|
|
48
|
+
"images": [],
|
|
49
|
+
"metadata": {"msrp": "123.45", "unit": "1 code"},
|
|
50
|
+
"metanutrition": None,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@patch("upcdatabase.client.requests.Session.get")
|
|
54
|
+
def test_lookup_testing_upc(self, mock_get):
|
|
55
|
+
"""Test lookup of UPC 0111222333446 returns expected data"""
|
|
56
|
+
mock_response = Mock()
|
|
57
|
+
mock_response.json.return_value = self.expected_response
|
|
58
|
+
mock_get.return_value = mock_response
|
|
59
|
+
|
|
60
|
+
result = self.client.lookup(self.test_upc)
|
|
61
|
+
|
|
62
|
+
# Verify the response matches expected
|
|
63
|
+
self.assertEqual(result["barcode"], "0111222333446")
|
|
64
|
+
self.assertEqual(result["title"], "UPC Database Testing Code")
|
|
65
|
+
self.assertEqual(result["alias"], "Testing Code")
|
|
66
|
+
self.assertEqual(result["msrp"], "123.45")
|
|
67
|
+
self.assertTrue(result["success"])
|
|
68
|
+
self.assertEqual(result, self.expected_response)
|
|
69
|
+
|
|
70
|
+
# Verify API was called with correct endpoint
|
|
71
|
+
mock_get.assert_called_once()
|
|
72
|
+
call_args = mock_get.call_args
|
|
73
|
+
self.assertIn("/product/0111222333446", call_args[0][0])
|
|
74
|
+
# Verify bearer token was used
|
|
75
|
+
self.assertIn("Authorization", call_args[1]["headers"])
|
|
76
|
+
self.assertEqual(call_args[1]["headers"]["Authorization"], f"Bearer {self.api_key}")
|
|
77
|
+
|
|
78
|
+
@patch("upcdatabase.client.requests.Session.get")
|
|
79
|
+
def test_bearer_token_in_request(self, mock_get):
|
|
80
|
+
"""Test that bearer token is sent in Authorization header.
|
|
81
|
+
|
|
82
|
+
Validates that API requests include the bearer token authentication
|
|
83
|
+
in the Authorization header with the format 'Bearer <api_key>'.
|
|
84
|
+
"""
|
|
85
|
+
mock_response = Mock()
|
|
86
|
+
mock_response.json.return_value = {"success": True}
|
|
87
|
+
mock_get.return_value = mock_response
|
|
88
|
+
|
|
89
|
+
self.client.lookup(self.test_upc)
|
|
90
|
+
|
|
91
|
+
# Verify the request was made with Authorization header
|
|
92
|
+
mock_get.assert_called_once()
|
|
93
|
+
call_args = mock_get.call_args
|
|
94
|
+
|
|
95
|
+
# Check that headers were passed
|
|
96
|
+
self.assertIn("headers", call_args[1])
|
|
97
|
+
headers = call_args[1]["headers"]
|
|
98
|
+
|
|
99
|
+
# Check that Authorization header exists
|
|
100
|
+
self.assertIn("Authorization", headers)
|
|
101
|
+
|
|
102
|
+
# Check that bearer token format is correct
|
|
103
|
+
auth_header = headers["Authorization"]
|
|
104
|
+
self.assertTrue(
|
|
105
|
+
auth_header.startswith("Bearer "),
|
|
106
|
+
f"Authorization header should start with 'Bearer ', got: {auth_header}",
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
# Check that API key is included in bearer token
|
|
110
|
+
self.assertEqual(
|
|
111
|
+
auth_header,
|
|
112
|
+
f"Bearer {self.api_key}",
|
|
113
|
+
f"Bearer token should contain API key: {self.api_key}",
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
if __name__ == "__main__":
|
|
118
|
+
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|