Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use built-in testing from ops #396

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/unit/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from unittest.mock import patch

import pytest
import scenario
ghislainbourgeois marked this conversation as resolved.
Show resolved Hide resolved
from ops import testing

from charm import UPFOperatorCharm
from dpdk import DPDK
Expand Down Expand Up @@ -52,6 +52,6 @@ def teardown() -> None:

@pytest.fixture(autouse=True)
def context(self):
self.ctx = scenario.Context(
self.ctx = testing.Context(
charm_type=UPFOperatorCharm,
)
16 changes: 8 additions & 8 deletions tests/unit/lib/charms/sdcore_upf/v0/test_fiveg_n3_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


import pytest
import scenario
from charms.sdcore_upf_k8s.v0.fiveg_n3 import FiveGN3RequestEvent, N3Provides
from ops import testing
from ops.charm import ActionEvent, CharmBase


Expand All @@ -31,7 +31,7 @@ def _on_publish_upf_information_action(self, event: ActionEvent):
class TestN3Provides:
@pytest.fixture(autouse=True)
def context(self):
self.ctx = scenario.Context(
self.ctx = testing.Context(
charm_type=N3Provider,
meta={
"name": "n3-provider",
Expand All @@ -50,11 +50,11 @@ def context(self):
def test_given_fiveg_n3_relation_when_set_upf_information_then_info_added_to_relation_data( # noqa: E501
self,
):
fiveg_n3_relation = scenario.Relation(
fiveg_n3_relation = testing.Relation(
endpoint="fiveg_n3",
interface="fiveg_n3",
)
state_in = scenario.State(
state_in = testing.State(
leader=True,
relations=[fiveg_n3_relation],
)
Expand All @@ -74,11 +74,11 @@ def test_given_fiveg_n3_relation_when_set_upf_information_then_info_added_to_rel
def test_given_invalid_upf_information_when_set_upf_information_then_error_raised(
self,
):
fiveg_n3_relation = scenario.Relation(
fiveg_n3_relation = testing.Relation(
endpoint="fiveg_n3",
interface="fiveg_n3",
)
state_in = scenario.State(
state_in = testing.State(
leader=True,
relations=[fiveg_n3_relation],
)
Expand All @@ -96,11 +96,11 @@ def test_given_invalid_upf_information_when_set_upf_information_then_error_raise
def test_given_when_relation_joined_then_fiveg_n3_request_event_emitted(
self,
):
fiveg_n3_relation = scenario.Relation(
fiveg_n3_relation = testing.Relation(
endpoint="fiveg_n3",
interface="fiveg_n3",
)
state_in = scenario.State(
state_in = testing.State(
leader=True,
relations=[fiveg_n3_relation],
)
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/lib/charms/sdcore_upf/v0/test_fiveg_n3_requirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


import pytest
import scenario
from charms.sdcore_upf_k8s.v0.fiveg_n3 import N3AvailableEvent, N3Requires
from ops import testing
from ops.charm import CharmBase


Expand All @@ -17,7 +17,7 @@ def __init__(self, *args):
class TestN3Provides:
@pytest.fixture(autouse=True)
def context(self):
self.ctx = scenario.Context(
self.ctx = testing.Context(
charm_type=N3Requirer,
meta={
"name": "n3-requirer",
Expand All @@ -28,12 +28,12 @@ def context(self):
def test_given_upf_ip_address_in_relation_data_when_relation_changed_then_fiveg_n3_request_event_emitted( # noqa: E501
self,
):
fiveg_n3_relation = scenario.Relation(
fiveg_n3_relation = testing.Relation(
endpoint="fiveg_n3",
interface="fiveg_n3",
remote_app_data={"upf_ip_address": "1.2.3.4"},
)
state_in = scenario.State(
state_in = testing.State(
leader=True,
relations=[fiveg_n3_relation],
)
Expand All @@ -46,12 +46,12 @@ def test_given_upf_ip_address_in_relation_data_when_relation_changed_then_fiveg_
def test_given_upf_ip_address_not_in_relation_data_when_relation_changed_then_fiveg_n3_request_event_emitted( # noqa: E501
self,
):
fiveg_n3_relation = scenario.Relation(
fiveg_n3_relation = testing.Relation(
endpoint="fiveg_n3",
interface="fiveg_n3",
remote_app_data={},
)
state_in = scenario.State(
state_in = testing.State(
leader=True,
relations=[fiveg_n3_relation],
)
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/lib/charms/sdcore_upf/v0/test_fiveg_n4_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


import pytest
import scenario
from charms.sdcore_upf_k8s.v0.fiveg_n4 import FiveGN4RequestEvent, N4Provides
from ops import testing
from ops.charm import ActionEvent, CharmBase


Expand Down Expand Up @@ -34,7 +34,7 @@ def _on_publish_upf_information_action(self, event: ActionEvent):
class TestN4Provides:
@pytest.fixture(autouse=True)
def context(self):
self.ctx = scenario.Context(
self.ctx = testing.Context(
charm_type=N4Provider,
meta={
"name": "n4-provider",
Expand All @@ -54,11 +54,11 @@ def context(self):
def test_given_fiveg_n4_relation_when_set_upf_information_then_info_added_to_relation_data( # noqa: E501
self,
):
fiveg_n4_relation = scenario.Relation(
fiveg_n4_relation = testing.Relation(
endpoint="fiveg_n4",
interface="fiveg_n4",
)
state_in = scenario.State(
state_in = testing.State(
leader=True,
relations=[fiveg_n4_relation],
)
Expand All @@ -80,11 +80,11 @@ def test_given_fiveg_n4_relation_when_set_upf_information_then_info_added_to_rel
def test_given_when_relation_joined_then_fiveg_n4_request_event_emitted(
self,
):
fiveg_n4_relation = scenario.Relation(
fiveg_n4_relation = testing.Relation(
endpoint="fiveg_n4",
interface="fiveg_n4",
)
state_in = scenario.State(
state_in = testing.State(
leader=True,
relations=[fiveg_n4_relation],
)
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/lib/charms/sdcore_upf/v0/test_fiveg_n4_requirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


import pytest
import scenario
from charms.sdcore_upf_k8s.v0.fiveg_n4 import N4AvailableEvent, N4Requires
from ops import testing
from ops.charm import CharmBase


Expand All @@ -17,7 +17,7 @@ def __init__(self, *args):
class TestN4Provides:
@pytest.fixture(autouse=True)
def context(self):
self.ctx = scenario.Context(
self.ctx = testing.Context(
charm_type=N4Requirer,
meta={
"name": "n4-requirer",
Expand All @@ -28,15 +28,15 @@ def context(self):
def test_given_upf_hostname_in_relation_data_when_relation_changed_then_fiveg_n4_request_event_emitted( # noqa: E501
self,
):
fiveg_n4_relation = scenario.Relation(
fiveg_n4_relation = testing.Relation(
endpoint="fiveg_n4",
interface="fiveg_n4",
remote_app_data={
"upf_hostname": "1.2.3.4",
"upf_port": "1234",
},
)
state_in = scenario.State(
state_in = testing.State(
leader=True,
relations=[fiveg_n4_relation],
)
Expand All @@ -49,12 +49,12 @@ def test_given_upf_hostname_in_relation_data_when_relation_changed_then_fiveg_n4
def test_given_upf_hostname_not_in_relation_data_when_relation_changed_then_fiveg_n4_request_event_emitted( # noqa: E501
self,
):
fiveg_n4_relation = scenario.Relation(
fiveg_n4_relation = testing.Relation(
endpoint="fiveg_n4",
interface="fiveg_n4",
remote_app_data={},
)
state_in = scenario.State(
state_in = testing.State(
leader=True,
relations=[fiveg_n4_relation],
)
Expand Down
Loading
Loading