Skip to content

Commit

Permalink
Correct tests that verify the client version to allow release candida…
Browse files Browse the repository at this point in the history
…tes and such.
  • Loading branch information
Tom Hendrikx committed Nov 8, 2022
1 parent 1471932 commit 6974113
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mollie/api/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

# Don't change the syntax of the definition unless you know what you're doing, because this file is
# processed by python imports and by regular expressions. The version is defined as a string in the
# regular semantic versioning scheme (major,minor,patch).
# regular semantic versioning scheme (major, minor, patch) as defined by PEP 440.

VERSION = "3.0.0rc1"
13 changes: 11 additions & 2 deletions tests/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,17 @@ def test_client_will_propagate_retry_setting(response):
assert adapter.max_retries.connect == 3


def test_client_version_is_pep440_compatible(client):
# PEP 440 specifies how python package versioning needs to look: https://peps.python.org/pep-0440
# Below is the regular expression from PEP 440, Appendix B, for canonical versions.
regex = r"^([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*((a|b|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev(0|[1-9][0-9]*))?$" # noqa: E501
assert re.match(regex, client.CLIENT_VERSION), "Client version does not match PEP 440 specification"


def test_client_default_user_agent(client, response):
"""Default user-agent should contain some known values."""
regex = re.compile(r"^Mollie/[\d\.]+ Python/[\w\.\+]+ OpenSSL/[\w\.]+$")
version = re.escape(client.CLIENT_VERSION)
regex = re.compile(rf"^Mollie/{version} Python/[\w\.\+]+ OpenSSL/[\w\.]+$")
assert re.match(regex, client.user_agent)

# perform a request and inpect the actual used headers
Expand All @@ -279,7 +287,8 @@ def test_client_default_user_agent(client, response):

def test_oauth_client_default_user_agent(oauth_client, response):
"""Default user-agent should contain some known values."""
regex = re.compile(r"^Mollie/[\d\.]+ Python/[\w\.\+]+ OpenSSL/[\w\.]+ OAuth/2\.0$")
version = re.escape(oauth_client.CLIENT_VERSION)
regex = re.compile(rf"^Mollie/{version} Python/[\w\.\+]+ OpenSSL/[\w\.]+ OAuth/2\.0$")
assert re.match(regex, oauth_client.user_agent)

# perform a request and inpect the actual used headers
Expand Down

0 comments on commit 6974113

Please sign in to comment.