async def test_configure():
    c = WebhookClient()
    c.configure("http://localhost:1234/some/path", "itsme", "secr3t password")
    assert c.configured is True
    assert c._url == "http://localhost:1234/some/path"
    assert c._session._default_headers["Content-Type"] == "application/json"
    assert c._session._default_headers["User-Agent"].startswith(
        "cratedb-operator/")
    assert c._session._default_auth.login == "itsme"
    assert c._session._default_auth.password == "secr3t password"
 async def test_error(self):
     client = WebhookClient()
     client.configure(
         f"{self.server.scheme}://{self.server.host}:{self.server.port}/error/",
         "itsme",
         "secr3t password",
     )
     response = await client.send_upgrade_notification(
         WebhookStatus.SUCCESS,
         "my-namespace",
         "my-cluster",
         WebhookUpgradePayload(old_registry="a",
                               new_registry="b",
                               old_version="c",
                               new_version="d"),
         logging.getLogger(__name__),
     )
     assert response.status == 418
 async def test_send_scale_notification(self):
     client = WebhookClient()
     client.configure(
         f"{self.server.scheme}://{self.server.host}:{self.server.port}/some/path/",
         "itsme",
         "secr3t password",
     )
     response = await client.send_scale_notification(
         WebhookStatus.SUCCESS,
         "my-namespace",
         "my-cluster",
         WebhookScalePayload(
             old_data_replicas={"a": 1},
             new_data_replicas={"a": 2},
             old_master_replicas=3,
             new_master_replicas=4,
         ),
         logging.getLogger(__name__),
     )
     assert response.status == 200
     data = await response.json()
     assert data == {
         "username": "******",
         "password": "******",
         "payload": {
             "event": "scale",
             "status": "success",
             "namespace": "my-namespace",
             "cluster": "my-cluster",
             "scale_data": {
                 "old_data_replicas": {
                     "a": 1
                 },
                 "new_data_replicas": {
                     "a": 2
                 },
                 "old_master_replicas": 3,
                 "new_master_replicas": 4,
             },
             "upgrade_data": None,
         },
     }
 async def test_not_configured(self):
     client = WebhookClient()
     response = await client.send_upgrade_notification(
         WebhookStatus.SUCCESS,
         "my-namespace",
         "my-cluster",
         WebhookUpgradePayload(old_registry="a",
                               new_registry="b",
                               old_version="c",
                               new_version="d"),
         logging.getLogger(__name__),
     )
     assert response is None
 async def test_send_upgrade_notification(self):
     client = WebhookClient()
     client.configure(
         f"{self.server.scheme}://{self.server.host}:{self.server.port}/some/path/",
         "itsme",
         "secr3t password",
     )
     response = await client.send_upgrade_notification(
         WebhookStatus.SUCCESS,
         "my-namespace",
         "my-cluster",
         WebhookUpgradePayload(
             old_registry="a",
             new_registry="b",
             old_version="c",
             new_version="d",
         ),
         logging.getLogger(__name__),
     )
     assert response.status == 200
     data = await response.json()
     assert data == {
         "username": "******",
         "password": "******",
         "payload": {
             "event": "upgrade",
             "status": "success",
             "namespace": "my-namespace",
             "cluster": "my-cluster",
             "scale_data": None,
             "upgrade_data": {
                 "old_registry": "a",
                 "new_registry": "b",
                 "old_version": "c",
                 "new_version": "d",
             },
         },
     }
def test_not_configured():
    c = WebhookClient()
    assert c.configured is False