Skip to content

Commit

Permalink
test: use scenario for unit testing (#220)
Browse files Browse the repository at this point in the history
Signed-off-by: guillaume <[email protected]>
  • Loading branch information
gruyaume authored Aug 16, 2024
1 parent 648d87e commit 97ef4f8
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 207 deletions.
13 changes: 7 additions & 6 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
import logging
from typing import Optional, cast

from certificates import (
certificate_has_common_name,
generate_ca,
generate_certificate,
generate_private_key,
)
from charms.certificate_transfer_interface.v0.certificate_transfer import (
CertificateTransferProvides,
)
Expand All @@ -30,6 +24,13 @@
from ops.main import main
from ops.model import ActiveStatus, BlockedStatus, SecretNotFoundError

from certificates import (
certificate_has_common_name,
generate_ca,
generate_certificate,
generate_private_key,
)

logger = logging.getLogger(__name__)


Expand Down
1 change: 1 addition & 0 deletions test-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pytest
pytest-operator
pytest-asyncio==0.21.2
ruff
ops-scenario
75 changes: 49 additions & 26 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,56 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --constraint=requirements.txt test-requirements.in
#
asttokens==2.4.1
# via stack-data
bcrypt==4.1.2
bcrypt==4.2.0
# via paramiko
cachetools==5.3.3
cachetools==5.4.0
# via google-auth
certifi==2024.7.4
# via
# -c requirements.txt
# kubernetes
# requests
cffi==1.16.0
# via
# -c requirements.txt
# cryptography
# pynacl
charset-normalizer==3.3.2
# via requests
# via
# -c requirements.txt
# requests
codespell==2.3.0
# via -r test-requirements.in
coverage[toml]==7.6.1
# via -r test-requirements.in
cryptography==43.0.0
# via paramiko
# via
# -c requirements.txt
# paramiko
decorator==5.1.1
# via
# ipdb
# ipython
executing==2.0.1
# via stack-data
google-auth==2.29.0
google-auth==2.33.0
# via kubernetes
hvac==2.1.0
hvac==2.3.0
# via juju
idna==3.7
# via requests
# via
# -c requirements.txt
# requests
iniconfig==2.0.0
# via pytest
ipdb==0.13.13
# via pytest-operator
ipython==8.23.0
ipython==8.26.0
# via ipdb
jedi==0.19.1
# via ipython
Expand All @@ -52,7 +60,7 @@ juju==3.5.2.0
# via
# -r test-requirements.in
# pytest-operator
kubernetes==29.0.0
kubernetes==30.1.0
# via juju
macaroonbakery==1.3.4
# via juju
Expand All @@ -62,31 +70,39 @@ matplotlib-inline==0.1.7
# via ipython
mypy-extensions==1.0.0
# via typing-inspect
nodeenv==1.8.0
nodeenv==1.9.1
# via pyright
oauthlib==3.2.2
# via
# kubernetes
# requests-oauthlib
packaging==24.0
ops==2.15.0
# via
# -c requirements.txt
# ops-scenario
ops-scenario==6.1.5
# via -r test-requirements.in
packaging==24.1
# via
# juju
# pytest
paramiko==3.4.0
paramiko==3.4.1
# via juju
parso==0.8.4
# via jedi
pexpect==4.9.0
# via ipython
pluggy==1.5.0
# via pytest
prompt-toolkit==3.0.43
prompt-toolkit==3.0.47
# via ipython
protobuf==4.25.3
# via macaroonbakery
# via
# -c requirements.txt
# macaroonbakery
ptyprocess==0.7.0
# via pexpect
pure-eval==0.2.2
pure-eval==0.2.3
# via stack-data
pyasn1==0.6.0
# via
Expand All @@ -96,8 +112,10 @@ pyasn1==0.6.0
pyasn1-modules==0.4.0
# via google-auth
pycparser==2.22
# via cffi
pygments==2.17.2
# via
# -c requirements.txt
# cffi
pygments==2.18.0
# via ipython
pymacaroons==0.13.0
# via macaroonbakery
Expand All @@ -110,7 +128,7 @@ pyrfc3339==1.1
# via
# juju
# macaroonbakery
pyright==1.1.375
pyright==1.1.376
# via -r test-requirements.in
pytest==8.3.2
# via
Expand All @@ -129,11 +147,15 @@ pytz==2024.1
# via pyrfc3339
pyyaml==6.0.1
# via
# -c requirements.txt
# juju
# kubernetes
# ops
# ops-scenario
# pytest-operator
requests==2.32.0
# via
# -c requirements.txt
# hvac
# kubernetes
# macaroonbakery
Expand All @@ -142,7 +164,7 @@ requests-oauthlib==2.0.0
# via kubernetes
rsa==4.9
# via google-auth
ruff==0.5.7
ruff==0.6.0
# via -r test-requirements.in
six==1.16.0
# via
Expand All @@ -155,26 +177,27 @@ stack-data==0.6.3
# via ipython
toposort==1.10
# via juju
traitlets==5.14.2
traitlets==5.14.3
# via
# ipython
# matplotlib-inline
typing-extensions==4.11.0
# via
# ipython
# -c requirements.txt
# typing-inspect
typing-inspect==0.9.0
# via juju
urllib3==2.2.2
# via
# -c requirements.txt
# kubernetes
# requests
wcwidth==0.2.13
# via prompt-toolkit
websocket-client==1.7.0
# via kubernetes
# via
# -c requirements.txt
# kubernetes
# ops
websockets==12.0
# via juju

# The following packages are considered to be unsafe in a requirements file:
# setuptools
10 changes: 5 additions & 5 deletions tests/unit/test_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# See LICENSE file for licensing details.


from charm import (
generate_ca,
generate_certificate,
generate_private_key,
)
from cryptography import x509
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import padding, rsa
from cryptography.hazmat.primitives.serialization import load_pem_private_key

from charm import (
generate_ca,
generate_certificate,
generate_private_key,
)
from tests.unit.certificates_helpers import (
generate_ca as generate_ca_helper,
)
Expand Down
Loading

0 comments on commit 97ef4f8

Please sign in to comment.