Skip to content

Commit

Permalink
Merge branch 'add-relation-adds-binding' of github.com:PietroPasotti/…
Browse files Browse the repository at this point in the history
…operator into add-relation-adds-binding
  • Loading branch information
PietroPasotti committed Mar 4, 2024
2 parents 702cc3f + 77cc8aa commit 57e5a15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions ops/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,9 +799,9 @@ def add_relation(self, relation_name: str, remote_app: str, *,
This function creates a relation with an application and triggers a
:class:`RelationCreatedEvent <ops.RelationCreatedEvent>`.
This function also creates a defaulted network binding on this endpoint. If you wish
It also creates a default network binding on this endpoint. If you want
to associate a custom network to this binding, provide one using
`add_network` before calling `add_relation`.
:meth:`add_network` before calling this function.
If `app_data` or `unit_data` are provided, also add a new unit
(``<remote_app>/0``) to the relation and trigger
Expand Down Expand Up @@ -838,7 +838,7 @@ def add_relation(self, relation_name: str, remote_app: str, *,
if not (relation_name in self._meta.provides
or relation_name in self._meta.requires
or relation_name in self._meta.peers):
raise RelationNotFoundError("relation %s not declared in metadata" % relation_name)
raise RelationNotFoundError(f'relation {relation_name!r} not declared in metadata')

relation_id = self._next_relation_id()
self._backend._relation_ids_map.setdefault(
Expand Down Expand Up @@ -867,12 +867,12 @@ def add_relation(self, relation_name: str, remote_app: str, *,
if unit_data is not None:
self.update_relation_data(relation_id, remote_unit, unit_data)

# if we don't already have a network binding for this relation id, create one
# If we don't already have a network binding for this relation id, create one.
if not self._backend._networks.get((relation_name, relation_id)):
self.add_network("10.0.0.10", endpoint=relation_name, relation_id=relation_id)
# if we don't already have a default network binding for this endpoint, create one
# If we don't already have a default network binding for this endpoint, create one.
if not self._backend._networks.get((relation_name, None)):
self.add_network("10.0.0.10", endpoint=relation_name)
self.add_network("192.0.2.0", endpoint=relation_name)

return relation_id

Expand Down
20 changes: 10 additions & 10 deletions test/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3054,7 +3054,7 @@ def test_network_get_relation_not_found(self):
binding.network

def test_add_relation_network_get(self):
self.harness.add_relation("db", "remote")
self.harness.add_relation('db', 'remote')
binding = self.harness.model.get_binding('db')
assert binding is not None
assert binding.network
Expand Down Expand Up @@ -4753,7 +4753,7 @@ def test_storage_mount(self):
class TestSecrets(unittest.TestCase):
def test_add_model_secret_by_app_name_str(self):
harness = ops.testing.Harness(ops.CharmBase, meta=yaml.safe_dump(
{"name": "webapp", "requires": {"db": {"interface": "pgsql"}}}
{'name': 'webapp', 'requires': {'db': {'interface': 'pgsql'}}}
))
self.addCleanup(harness.cleanup)
relation_id = harness.add_relation('db', 'database')
Expand All @@ -4767,7 +4767,7 @@ def test_add_model_secret_by_app_name_str(self):

def test_add_model_secret_by_app_instance(self):
harness = ops.testing.Harness(ops.CharmBase, meta=yaml.safe_dump(
{"name": "webapp", "requires": {"db": {"interface": "pgsql"}}}
{'name': 'webapp', 'requires': {'db': {'interface': 'pgsql'}}}
))
self.addCleanup(harness.cleanup)
relation_id = harness.add_relation('db', 'database')
Expand All @@ -4782,7 +4782,7 @@ def test_add_model_secret_by_app_instance(self):

def test_add_model_secret_by_unit_instance(self):
harness = ops.testing.Harness(ops.CharmBase, meta=yaml.safe_dump(
{"name": "webapp", "requires": {"db": {"interface": "pgsql"}}}
{'name': 'webapp', 'requires': {'db': {'interface': 'pgsql'}}}
))
self.addCleanup(harness.cleanup)
relation_id = harness.add_relation('db', 'database')
Expand All @@ -4797,7 +4797,7 @@ def test_add_model_secret_by_unit_instance(self):

def test_get_secret_as_owner(self):
harness = ops.testing.Harness(ops.CharmBase, meta=yaml.safe_dump(
{"name": "webapp", "requires": {"db": {"interface": "pgsql"}}}
{'name': 'webapp', 'requires': {'db': {'interface': 'pgsql'}}}
))
self.addCleanup(harness.cleanup)
harness.begin()
Expand Down Expand Up @@ -4859,7 +4859,7 @@ def test_add_model_secret_invalid_content(self):

def test_set_secret_content(self):
harness = ops.testing.Harness(EventRecorder, meta=yaml.safe_dump(
{"name": "webapp", "requires": {"db": {"interface": "pgsql"}}}
{'name': 'webapp', 'requires': {'db': {'interface': 'pgsql'}}}
))
self.addCleanup(harness.cleanup)
relation_id = harness.add_relation('db', 'database')
Expand Down Expand Up @@ -4907,7 +4907,7 @@ def test_set_secret_content_invalid_content(self):

def test_grant_secret_and_revoke_secret(self):
harness = ops.testing.Harness(ops.CharmBase, meta=yaml.safe_dump(
{"name": "webapp", "requires": {"db": {"interface": "pgsql"}}}
{'name': 'webapp', 'requires': {'db': {'interface': 'pgsql'}}}
))
self.addCleanup(harness.cleanup)
relation_id = harness.add_relation('db', 'database')
Expand All @@ -4925,7 +4925,7 @@ def test_grant_secret_and_revoke_secret(self):

def test_grant_secret_wrong_app(self):
harness = ops.testing.Harness(ops.CharmBase, meta=yaml.safe_dump(
{"name": "webapp", "requires": {"db": {"interface": "pgsql"}}}
{'name': 'webapp', 'requires': {'db': {'interface': 'pgsql'}}}
))
self.addCleanup(harness.cleanup)
relation_id = harness.add_relation('db', 'database')
Expand All @@ -4938,7 +4938,7 @@ def test_grant_secret_wrong_app(self):

def test_grant_secret_wrong_unit(self):
harness = ops.testing.Harness(ops.CharmBase, meta=yaml.safe_dump(
{"name": "webapp", "requires": {"db": {"interface": "pgsql"}}}
{'name': 'webapp', 'requires': {'db': {'interface': 'pgsql'}}}
))
self.addCleanup(harness.cleanup)
relation_id = harness.add_relation('db', 'database')
Expand All @@ -4959,7 +4959,7 @@ def test_grant_secret_no_relation(self):

def test_get_secret_grants(self):
harness = ops.testing.Harness(ops.CharmBase, meta=yaml.safe_dump(
{"name": "database", "provides": {"db": {"interface": "pgsql"}}}
{'name': 'database', 'provides': {'db': {'interface': 'pgsql'}}}
))
self.addCleanup(harness.cleanup)

Expand Down

0 comments on commit 57e5a15

Please # to comment.