1 # Copyright 2022 Canonical Ltd.
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
17 from pathlib
import Path
21 from pytest_operator
.plugin
import OpsTest
23 logger
= logging
.getLogger(__name__
)
25 METADATA
= yaml
.safe_load(Path("./metadata.yaml").read_text())
28 @pytest.mark
.abort_on_fail
29 async def test_build_and_deploy(ops_test
: OpsTest
):
30 """Build the charm-under-test and deploy it together with related charms.
32 Assert on the unit status before any relations/configurations take place.
34 await ops_test
.model
.set_config({"update-status-hook-interval": "10s"})
35 # build and deploy charm from local source folder
36 charm
= await ops_test
.build_charm(".")
38 "update-db-image": METADATA
["resources"]["update-db-image"]["upstream-source"],
40 await ops_test
.model
.deploy(charm
, resources
=resources
, application_name
="update-db")
41 await ops_test
.model
.wait_for_idle(apps
=["update-db"], status
="active", timeout
=1000)
42 assert ops_test
.model
.applications
["update-db"].units
[0].workload_status
== "active"
44 await ops_test
.model
.set_config({"update-status-hook-interval": "60m"})
47 def base64_encode(phrase
: str) -> str:
48 return base64
.b64encode(phrase
.encode("utf-8")).decode("utf-8")