nacwrap 1.2__tar.gz → 1.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nacwrap
3
- Version: 1.2
3
+ Version: 1.4
4
4
  Summary: Python package that acts as a wrapper for the Nintex Automation Cloud system.
5
5
  Author: Jordan Maynor
6
6
  Author-email: Jordan Maynor <jmaynor@pepsimidamerica.com>
@@ -32,3 +32,18 @@ Several environment variables are required for nacwrap to function.
32
32
  | Yes | NINTEX_CLIENT_SECRET | Client secret for connecting to Nintex API. Created in Apps and Tokens page in NAC. |
33
33
  | Yes | NINTEX_GRANT_TYPE | Value should be 'client_credentials'. |
34
34
  | Yes | NINTEX_BASE_URL | Value depends on which Nintex region you are in. US is, for example 'us.nintex.io'. <https://developer.nintex.com/docs/nc-api-docs/d2924cfeea6e8-welcome-to-the-nintex-automation-cloud-api#choose-your-region> |
35
+
36
+ ## Running tests
37
+
38
+ Install the dev dependencies and run pytest:
39
+
40
+ ```sh
41
+ uv sync
42
+ uv run pytest
43
+ ```
44
+
45
+ Unit tests mock the Nintex API and need no credentials. Live tests, which call the real API, are skipped by default. To run them, put real credentials in `.env` (see `.env.example`), plus a current `NTX_BEARER_TOKEN`, and set `RUN_LIVE_API_TESTS=1`:
46
+
47
+ ```sh
48
+ RUN_LIVE_API_TESTS=1 uv run pytest -m live_api
49
+ ```
@@ -16,3 +16,18 @@ Several environment variables are required for nacwrap to function.
16
16
  | Yes | NINTEX_CLIENT_SECRET | Client secret for connecting to Nintex API. Created in Apps and Tokens page in NAC. |
17
17
  | Yes | NINTEX_GRANT_TYPE | Value should be 'client_credentials'. |
18
18
  | Yes | NINTEX_BASE_URL | Value depends on which Nintex region you are in. US is, for example 'us.nintex.io'. <https://developer.nintex.com/docs/nc-api-docs/d2924cfeea6e8-welcome-to-the-nintex-automation-cloud-api#choose-your-region> |
19
+
20
+ ## Running tests
21
+
22
+ Install the dev dependencies and run pytest:
23
+
24
+ ```sh
25
+ uv sync
26
+ uv run pytest
27
+ ```
28
+
29
+ Unit tests mock the Nintex API and need no credentials. Live tests, which call the real API, are skipped by default. To run them, put real credentials in `.env` (see `.env.example`), plus a current `NTX_BEARER_TOKEN`, and set `RUN_LIVE_API_TESTS=1`:
30
+
31
+ ```sh
32
+ RUN_LIVE_API_TESTS=1 uv run pytest -m live_api
33
+ ```
@@ -20,6 +20,12 @@ _P = ParamSpec("_P")
20
20
  _R = TypeVar("_R")
21
21
 
22
22
 
23
+ class NintexAuthError(Exception):
24
+ """
25
+ Raised when a Nintex bearer token cannot be obtained.
26
+ """
27
+
28
+
23
29
  class Decorators:
24
30
  """
25
31
  The Decorators class is used to define functionality for getting
@@ -44,14 +50,17 @@ class Decorators:
44
50
  A wrapper function used to check if the bearer token env vars
45
51
  need to be refreshed.
46
52
  """
47
- if "NTX_BEARER_TOKEN_EXPIRES_AT" not in os.environ:
48
- expires_at = "01/01/1901 00:00:00"
49
- else:
50
- expires_at = os.environ["NTX_BEARER_TOKEN_EXPIRES_AT"]
51
- if (
52
- "NTX_BEARER_TOKEN" not in os.environ
53
- or datetime.strptime(expires_at, "%m/%d/%Y %H:%M:%S") < datetime.now()
54
- ):
53
+ expires_at = os.environ.get(
54
+ "NTX_BEARER_TOKEN_EXPIRES_AT", "01/01/1901 00:00:00"
55
+ )
56
+ try:
57
+ expired = (
58
+ datetime.strptime(expires_at, "%m/%d/%Y %H:%M:%S") < datetime.now()
59
+ )
60
+ except ValueError:
61
+ logger.warning(f"Unparseable token expiry {expires_at!r}, refreshing")
62
+ expired = True
63
+ if "NTX_BEARER_TOKEN" not in os.environ or expired:
55
64
  Decorators.get_token()
56
65
  return decorated(*args, **kwargs)
57
66
 
@@ -63,13 +72,13 @@ class Decorators:
63
72
  Get a new Nintex bearer token and set the corresponding environment variables.
64
73
  """
65
74
  if "NINTEX_BASE_URL" not in os.environ:
66
- raise Exception("NINTEX_BASE_URL not set in environment")
75
+ raise NintexAuthError("NINTEX_BASE_URL not set in environment")
67
76
  if "NINTEX_CLIENT_ID" not in os.environ:
68
- raise Exception("NINTEX_CLIENT_ID not set in environment")
77
+ raise NintexAuthError("NINTEX_CLIENT_ID not set in environment")
69
78
  if "NINTEX_CLIENT_SECRET" not in os.environ:
70
- raise Exception("NINTEX_CLIENT_SECRET not set in environment")
79
+ raise NintexAuthError("NINTEX_CLIENT_SECRET not set in environment")
71
80
  if "NINTEX_GRANT_TYPE" not in os.environ:
72
- raise Exception("NINTEX_GRANT_TYPE not set in environment")
81
+ raise NintexAuthError("NINTEX_GRANT_TYPE not set in environment")
73
82
 
74
83
  response = requests.post(
75
84
  os.environ["NINTEX_BASE_URL"] + "/authentication/v1/token",
@@ -84,13 +93,21 @@ class Decorators:
84
93
  },
85
94
  timeout=30,
86
95
  )
96
+ if not response.ok:
97
+ msg = (
98
+ f"Nintex token request failed ({response.status_code}): {response.text}"
99
+ )
100
+ logger.error(msg)
101
+ raise NintexAuthError(msg)
87
102
  try:
88
103
  os.environ["NTX_BEARER_TOKEN"] = response.json()["access_token"]
89
104
  except Exception as e:
90
105
  logger.error(f"Error, could not set OS env bearer token: {e}")
91
- raise Exception(f"Error, could not set OS env bearer token: {e}") from e
106
+ raise NintexAuthError(
107
+ f"Error, could not set OS env bearer token: {e}"
108
+ ) from e
92
109
  try:
93
- os.environ["NTX_EXPIRES_AT"] = response.json()["expires_at"]
110
+ os.environ["NTX_BEARER_TOKEN_EXPIRES_AT"] = response.json()["expires_at"]
94
111
  except Exception as e:
95
112
  logger.error(f"Error, could not set os env expires at: {e}")
96
- raise Exception(f"Error, could not set os env expires at: {e}") from e
113
+ raise NintexAuthError(f"Error, could not set os env expires at: {e}") from e
@@ -73,8 +73,8 @@ def _make_request(
73
73
  )
74
74
  response.raise_for_status()
75
75
  except requests.exceptions.HTTPError as e:
76
- logger.error(f"HTTP {e.response.status_code} error, {context}: {e}")
77
- raise Exception(f"HTTP {e.response.status_code} error, {context}: {e}") from e
76
+ logger.error(f"HTTP {response.status_code} error, {context}: {e}")
77
+ raise Exception(f"HTTP {response.status_code} error, {context}: {e}") from e
78
78
  except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as e:
79
79
  logger.error(f"Connection error during {context}: {e}")
80
80
  raise
@@ -167,7 +167,10 @@ def task_complete(task_id: str, assignment_id: str, outcome: str) -> None:
167
167
  headers=_get_ntx_headers(),
168
168
  context="complete task",
169
169
  json={"outcome": outcome},
170
- success_status_codes=[204], # TODO Verify code once I get a task I can complete
170
+ success_status_codes=[
171
+ 200,
172
+ 204,
173
+ ],
171
174
  )
172
175
 
173
176
  logger.info(f"Response Status: {response.status_code}")
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "nacwrap"
3
- version = "1.2"
3
+ version = "1.4"
4
4
  description = "Python package that acts as a wrapper for the Nintex Automation Cloud system."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -24,7 +24,7 @@ email = "jmaynor@pepsimidamerica.com"
24
24
  Homepage = "https://github.com/pepsimidamerica/nacwrap"
25
25
 
26
26
  [build-system]
27
- requires = ["uv_build>=0.9.4,<0.12.0"]
27
+ requires = ["uv_build>=0.9.4,<0.14.0"]
28
28
  build-backend = "uv_build"
29
29
 
30
30
  [tool.uv.build-backend]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "nacwrap"
3
- version = "1.2"
3
+ version = "1.4"
4
4
  description = "Python package that acts as a wrapper for the Nintex Automation Cloud system."
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Jordan Maynor", email = "jmaynor@pepsimidamerica.com" }]
@@ -17,7 +17,7 @@ license-file = "LICENSE"
17
17
  Homepage = "https://github.com/pepsimidamerica/nacwrap"
18
18
 
19
19
  [build-system]
20
- requires = ["uv_build>=0.9.4,<0.12.0"]
20
+ requires = ["uv_build>=0.9.4,<0.14.0"]
21
21
  build-backend = "uv_build"
22
22
 
23
23
  [tool.uv.build-backend]
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