Skip to content

Commit f922071

Browse files
author
Jonathan Wenger
committed
Add integration tests coverage
1 parent 8f3dfe3 commit f922071

File tree

6 files changed

+115
-8
lines changed

6 files changed

+115
-8
lines changed

.github/workflows/python-publish.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,25 @@ jobs:
1414
uses: actions/setup-python@v2
1515
with:
1616
python-version: "3.x"
17-
- name: Retrieve bearer token
18-
id: get_bearer_token
17+
18+
- name: Retrieve bearer token for EInvoicing
19+
id: get_bearer_token_einvoicing
1920
run: |
2021
response=$(curl -X POST ${{secrets.OKTA_ACCESS_TOKEN_URL}}/connect/token \
2122
-H "Content-Type: application/x-www-form-urlencoded" \
2223
-d "grant_type=client_credentials&client_id=${{secrets.OKTA_CLIENT_ID}}&client_secret=${{secrets.OKTA_CLIENT_SECRET}}")
2324
token=$(echo $response | jq -r '.access_token')
24-
echo "BEARER_TOKEN=${token}" >> $GITHUB_ENV
25+
echo "BEARER_TOKEN_EINVOICING=${token}" >> $GITHUB_ENV
26+
27+
- name: Retrieve bearer token for A1099
28+
id: get_bearer_token_a1099
29+
run: |
30+
response=$(curl -X POST ${{secrets.AI_SBX_URL}}/connect/token \
31+
-H "Content-Type: application/x-www-form-urlencoded" \
32+
-d "grant_type=client_credentials&client_id=${{secrets.AI_CLIENT_ID_A1099}}&client_secret=${{secrets.AI_CLIENT_SECRET_A1099}}")
33+
token=$(echo $response | jq -r '.access_token')
34+
echo "BEARER_TOKEN_A1099=${token}" >> $GITHUB_ENV
35+
2536
- name: Install dependencies
2637
run: |
2738
python -m pip install --upgrade pip

.github/workflows/test.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,25 @@ jobs:
2222
pip install build
2323
pip install -r ./requirements.txt
2424
pip install -r ./test-requirements.txt
25-
- name: Retrieve bearer token
26-
id: get_bearer_token
25+
26+
- name: Retrieve bearer token for EInvoicing
27+
id: get_bearer_token_einvoicing
2728
run: |
2829
response=$(curl -X POST ${{secrets.OKTA_ACCESS_TOKEN_URL}}/connect/token \
2930
-H "Content-Type: application/x-www-form-urlencoded" \
3031
-d "grant_type=client_credentials&client_id=${{secrets.OKTA_CLIENT_ID}}&client_secret=${{secrets.OKTA_CLIENT_SECRET}}")
3132
token=$(echo $response | jq -r '.access_token')
32-
echo "BEARER_TOKEN=${token}" >> $GITHUB_ENV
33+
echo "BEARER_TOKEN_EINVOICING=${token}" >> $GITHUB_ENV
34+
35+
- name: Retrieve bearer token for A1099
36+
id: get_bearer_token_a1099
37+
run: |
38+
response=$(curl -X POST ${{secrets.AI_SBX_URL}}/connect/token \
39+
-H "Content-Type: application/x-www-form-urlencoded" \
40+
-d "grant_type=client_credentials&client_id=${{secrets.AI_CLIENT_ID_A1099}}&client_secret=${{secrets.AI_CLIENT_SECRET_A1099}}")
41+
token=$(echo $response | jq -r '.access_token')
42+
echo "BEARER_TOKEN_A1099=${token}" >> $GITHUB_ENV
43+
3344
- name: Build package
3445
run: python -m build
3546
- name: Pip Package

Avalara/SDK/configuration.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,12 @@ def auth_settings(self, required_scopes):
574574
'key': 'Authorization',
575575
'value': f'Bearer {self.access_token}',
576576
}
577+
auth['bearer'] = {
578+
'type': 'api_key',
579+
'in': 'header',
580+
'key': 'Authorization',
581+
'value': f'Bearer {self.access_token}',
582+
}
577583
elif self.client_id is not None and not self.is_null_or_empty(
578584
self.client_secret
579585
):

test/integration/test_a1099api.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from math import fabs
2+
import unittest
3+
import pytest
4+
import ssl
5+
import time
6+
import os
7+
from dotenv import load_dotenv
8+
import uuid
9+
10+
# Import Configuration, ApiClient, and exceptions
11+
from Avalara.SDK.configuration import Configuration
12+
from Avalara.SDK.api_client import ApiClient
13+
from Avalara.SDK.exceptions import ApiException
14+
15+
# Import the specific A1099 APIs
16+
from Avalara.SDK.api.A1099.V2.issuers1099_api import Issuers1099Api
17+
from Avalara.SDK.api.A1099.V2.companies_w9_api import CompaniesW9Api
18+
from Avalara.SDK.api.A1099.V2.forms1099_api import Forms1099Api
19+
20+
class TestA1099Api(unittest.TestCase):
21+
"""A1099Api unit test stubs"""
22+
23+
def setUp(self):
24+
load_dotenv()
25+
26+
bearer_token = os.getenv('BEARER_TOKEN_A1099')
27+
# Configure with the A1099 bearer token
28+
configuration = Configuration(
29+
environment="sandbox",
30+
access_token=bearer_token
31+
)
32+
33+
# Create an API client for all tests
34+
self.api_client = ApiClient(configuration)
35+
self.issuers_api = Issuers1099Api(self.api_client)
36+
self.companies_api = CompaniesW9Api(self.api_client)
37+
self.forms_api = Forms1099Api(self.api_client)
38+
39+
def tearDown(self):
40+
pass
41+
42+
def test_get_issuers(self):
43+
"""Test the GetIssuers endpoint returns data"""
44+
try:
45+
correlation_id = str(uuid.uuid4())
46+
result = self.issuers_api.get_issuers("2.0", correlation_id)
47+
print(result)
48+
assert result is not None, "Expected non-null issuers list"
49+
except ApiException as e:
50+
print(f"Exception when calling Issuers1099Api->get_issuers: {e}\n")
51+
assert False
52+
print("Completed get_issuers test")
53+
54+
def test_get_companies(self):
55+
"""Test the GetCompanies endpoint returns data"""
56+
try:
57+
correlation_id = str(uuid.uuid4())
58+
result = self.companies_api.get_companies("2.0", correlation_id)
59+
print(result)
60+
assert result is not None, "Expected non-null companies list"
61+
except ApiException as e:
62+
print(f"Exception when calling CompaniesW9Api->get_companies: {e}\n")
63+
assert False
64+
print("Completed get_companies test")
65+
66+
def test_list_1099_forms(self):
67+
"""Test the List1099Forms endpoint returns data"""
68+
try:
69+
correlation_id = str(uuid.uuid4())
70+
result = self.forms_api.list1099_forms("2.0", correlation_id)
71+
print(result)
72+
assert result is not None, "Expected non-null 1099 forms list"
73+
except ApiException as e:
74+
print(f"Exception when calling Forms1099Api->list_1099_forms: {e}\n")
75+
assert False
76+
print("Completed list_1099_forms test")
77+
78+
if __name__ == '__main__':
79+
unittest.main()

test/integration/test_documentsapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def setUp(self):
2525
# Use the Configuration from Avalara.SDK
2626
configuration = Configuration(
2727
environment="sandbox",
28-
access_token=os.getenv('BEARER_TOKEN')
28+
access_token=os.getenv('BEARER_TOKEN_EINVOICING')
2929
)
3030

3131
# Create an API client using that configuration

test/integration/test_mandatesapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def setUp(self):
2727
# ssl.SSLContext.verify_mode = ssl.VerifyMode.CERT_OPTIONAL
2828
configuration = Configuration(
2929
environment="sandbox",
30-
access_token=os.getenv('BEARER_TOKEN')
30+
access_token=os.getenv('BEARER_TOKEN_EINVOICING')
3131
)
3232
with ApiClient(configuration) as api_client:
3333
self.api = MandatesApi(api_client)

0 commit comments

Comments
 (0)