Skip to content

Commit

Permalink
chore: bump to Scenario 7 (#177)
Browse files Browse the repository at this point in the history
* Remove the restriction on ops and ops-scenario for building JSON schemas.

* Fix typo.

* Bump ops-scenario and pytest-interface-tester versions.

* Remove unused import.

* Adjust to the Scenario 7 API.

* Bump the generated docs.
  • Loading branch information
tonyandrewmeyer authored Sep 26, 2024
1 parent 5d80747 commit fa0526b
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 56 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ For the time being, to see available interfaces, their statuses, and schemas, br

# Relation interface testers

In order to automatically validate whether a charm satisfies a given relation interface, the relation interface maintainer(s) need to write one or more **relation interface tests**. A relation interface test is a [scenario-based test case](https://github.com/canonical/ops-scenario) which checks that, given an intitial context, when a relation event is triggered, the charm will do what the interface specifies. For example, most interface testers will check that, on relation changed, the charm will write a certain value into its (app/unit) databag and that that value matches a certain (Pydantic) schema.
In order to automatically validate whether a charm satisfies a given relation interface, the relation interface maintainer(s) need to write one or more **relation interface tests**. A relation interface test is a [scenario-based test case](https://github.com/canonical/ops-scenario) which checks that, given an initial context, when a relation event is triggered, the charm will do what the interface specifies. For example, most interface testers will check that, on relation changed, the charm will write a certain value into its (app/unit) databag and that that value matches a certain (Pydantic) schema.

See [the tester documentation](https://github.com/canonical/interface-tester-pytest) for more.
6 changes: 1 addition & 5 deletions docs/json_schemas/dns_record/v0/provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@
"type": "string"
},
"status": {
"allOf": [
{
"$ref": "#/$defs/Status"
}
],
"$ref": "#/$defs/Status",
"description": "Status for the domain request.",
"examples": [
"approved",
Expand Down
12 changes: 2 additions & 10 deletions docs/json_schemas/dns_record/v0/requirer.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@
"type": "integer"
},
"record_class": {
"allOf": [
{
"$ref": "#/$defs/RecordClass"
}
],
"$ref": "#/$defs/RecordClass",
"default": null,
"description": "The DNS record class.",
"examples": [
Expand All @@ -114,11 +110,7 @@
"name": "Record class"
},
"record_type": {
"allOf": [
{
"$ref": "#/$defs/RecordType"
}
],
"$ref": "#/$defs/RecordType",
"default": null,
"description": "The DNS record type.",
"examples": [
Expand Down
6 changes: 1 addition & 5 deletions docs/json_schemas/kratos_external_idp/v0/provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
"type": "string"
},
"secret_backend": {
"allOf": [
{
"$ref": "#/$defs/SecretBackend"
}
],
"$ref": "#/$defs/SecretBackend",
"default": "relation"
},
"provider": {
Expand Down
12 changes: 2 additions & 10 deletions docs/json_schemas/smtp/v0/provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,15 @@
"title": "Password ID"
},
"auth_type": {
"allOf": [
{
"$ref": "#/$defs/AuthType"
}
],
"$ref": "#/$defs/AuthType",
"description": "The type used to authenticate with the SMTP relay.",
"examples": [
"none"
],
"title": "Auth type"
},
"transport_security": {
"allOf": [
{
"$ref": "#/$defs/TransportSecurity"
}
],
"$ref": "#/$defs/TransportSecurity",
"description": "The security protocol to use for the SMTP relay.",
"examples": [
"none"
Expand Down
12 changes: 2 additions & 10 deletions docs/json_schemas/tracing/v2/provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
"type": "string"
},
"type": {
"allOf": [
{
"$ref": "#/$defs/TransportProtocolType"
}
],
"$ref": "#/$defs/TransportProtocolType",
"description": "The transport protocol used by this receiver.",
"examples": [
"http",
Expand All @@ -43,11 +39,7 @@
"description": "Specification of an active receiver.",
"properties": {
"protocol": {
"allOf": [
{
"$ref": "#/$defs/ProtocolType"
}
],
"$ref": "#/$defs/ProtocolType",
"description": "Receiver protocol name and type."
},
"url": {
Expand Down
3 changes: 2 additions & 1 deletion interfaces/__template__/v0/interface_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Copy this test to `test_provider.py` and fill in the blanks however appropriate

```python
from scenario import Relation, State
from scenario.context import CharmEvents
from interface_tester import Tester

def test_data_published_on_changed_remote_valid():
Expand All @@ -25,7 +26,7 @@ def test_data_published_on_changed_remote_valid():
)

# WHEN the <provider side> receives a <endpoint-changed-event> event:
t.run(relation.changed_event)
t.run(CharmEvents.relation_changed(relation))

# THEN the <provider side> also publishes valid data to its side of the relation
# (if applicable)
Expand Down
3 changes: 2 additions & 1 deletion interfaces/cos_agent/v0/interface_tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
from interface_tester import Tester
from scenario import State, Relation
from scenario.context import CharmEvents


def test_no_data_on_created():
Expand Down Expand Up @@ -90,5 +91,5 @@ def test_on_changed_with_existing_valid_data():
local_unit_data=valid_unit_data,
)
t = Tester(State(relations=[relation]))
state_out = t.run(relation.changed_event)
state_out = t.run(CharmEvents.relation_changed(relation))
t.assert_schema_valid()
3 changes: 2 additions & 1 deletion interfaces/ingress/v1/interface_tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from interface_tester import Tester
from scenario import State, Relation
from scenario.context import CharmEvents


def test_no_data_on_created():
Expand Down Expand Up @@ -43,7 +44,7 @@ def test_data_published_on_changed_remote_valid():
remote_app_data={'host': '"0.0.0.42"', 'model': '"bar"', 'name': '"remote/0"', 'port': '42'}
)
t = Tester(State(leader=True, relations=[ingress]))
state_out = t.run(ingress.changed_event)
state_out = t.run(CharmEvents.relation_changed(ingress))
t.assert_schema_valid()


Expand Down
7 changes: 4 additions & 3 deletions interfaces/ingress/v2/interface_tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from interface_tester import Tester
from scenario import State, Relation
from scenario.context import CharmEvents


def test_no_data_on_created():
Expand Down Expand Up @@ -45,7 +46,7 @@ def test_data_published_on_changed_remote_valid():
relations=[relation]
)
)
state_out = t.run(relation.changed_event)
state_out = t.run(CharmEvents.relation_changed(relation))
t.assert_schema_valid()


Expand All @@ -59,7 +60,7 @@ def test_data_published_on_changed_remote_invalid_json():
relations=[ingress]
)
)
state_out = t.run(ingress.changed_event)
state_out = t.run(CharmEvents.relation_changed(ingress))
t.assert_relation_data_empty()


Expand All @@ -73,6 +74,6 @@ def test_data_published_on_changed_remote_invalid():
relations=[ingress]
)
)
state_out = t.run(ingress.changed_event)
state_out = t.run(CharmEvents.relation_changed(ingress))
t.assert_relation_data_empty()

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
from interface_tester import Tester
from scenario import Relation, State
from scenario.context import CharmEvents


def test_no_data_on_created():
Expand Down Expand Up @@ -80,5 +81,5 @@ def test_on_changed_with_existing_valid_data():
local_unit_data=valid_unit_data,
)
t = Tester(State(relations=[relation]))
state_out = t.run(relation.changed_event)
t.assert_schema_valid()
state_out = t.run(CharmEvents.relation_changed(relation))
t.assert_schema_valid()
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ packages = [ 'interfaces']
[project]
name = "charm-relation-interfaces"

version = "0.1"
version = "0.1.1"
authors = [
{ name = "Pietro Pasotti", email = "[email protected]" },
{ name = "Simon Aronsson", email = "[email protected]" },
Expand All @@ -23,7 +23,7 @@ keywords = ["juju", "relation interfaces"]

dependencies = [
"pydantic>2",
"pytest-interface-tester>=3.1.0",
"pytest-interface-tester>=3.1.2",
"PyGithub>=2.3.0"
]

Expand All @@ -41,7 +41,7 @@ unit_tests = [
"ops>=2.9",
"PyYAML>=6.0",
"pytest>=7.3.1",
"ops-scenario>=5",
"ops-scenario>=7.0.5",
]

json_schemas = [
Expand All @@ -51,7 +51,7 @@ json_schemas = [
interface_tests = [
"PyYAML>=6.0",
"pytest>=7.3.1",
"ops-scenario>=5",
"ops-scenario>=7.0.5",
"requests==2.28.1",
"virtualenv==20.21.0"
]
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ commands =
[testenv:build-json-schemas]
description = build json schemas in docs/
deps =
ops==2.6.0
ops-scenario<6.0.4 #schema build fails with missing 'CloudCredential' in ops module
ops
ops-scenario
.[json_schemas]
setenv =
PYTHONPATH={toxinidir}
Expand Down
2 changes: 1 addition & 1 deletion utils/interface-validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from enum import Enum
from typing import List, Optional
from pydantic import AnyHttpUrl, BaseModel, Field, ValidationError, ConfigDict
from pydantic import AnyHttpUrl, BaseModel, ValidationError, ConfigDict

class text:
BOLD = '\033[1m'
Expand Down

0 comments on commit fa0526b

Please sign in to comment.