2018-10-26 18:02:41 +01:00
|
|
|
|
import pytest
|
2017-03-17 16:21:41 +00:00
|
|
|
|
from flask import json
|
|
|
|
|
|
|
2023-07-10 11:06:29 -07:00
|
|
|
|
from tests.app.db import create_organization, create_service
|
2019-04-11 13:38:21 +01:00
|
|
|
|
|
2017-03-17 16:21:41 +00:00
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
|
@pytest.mark.parametrize("path", ["/", "/_status"])
|
2018-10-26 18:02:41 +01:00
|
|
|
|
def test_get_status_all_ok(client, notify_db_session, path):
|
2017-03-17 16:21:41 +00:00
|
|
|
|
response = client.get(path)
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
|
resp_json = json.loads(response.get_data(as_text=True))
|
2023-08-29 14:54:30 -07:00
|
|
|
|
assert resp_json["status"] == "ok"
|
|
|
|
|
|
assert resp_json["db_version"]
|
|
|
|
|
|
assert resp_json["git_commit"]
|
|
|
|
|
|
assert resp_json["build_time"]
|
2019-04-11 13:38:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
2023-07-10 11:06:29 -07:00
|
|
|
|
def test_empty_live_service_and_organization_counts(admin_request):
|
2023-08-29 14:54:30 -07:00
|
|
|
|
assert admin_request.get("status.live_service_and_organization_counts") == {
|
|
|
|
|
|
"organizations": 0,
|
|
|
|
|
|
"services": 0,
|
2019-04-11 13:38:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-07-10 11:06:29 -07:00
|
|
|
|
def test_populated_live_service_and_organization_counts(admin_request):
|
2019-04-11 13:38:21 +01:00
|
|
|
|
# Org 1 has three real live services and one fake, for a total of 3
|
2023-08-29 14:54:30 -07:00
|
|
|
|
org_1 = create_organization("org 1")
|
|
|
|
|
|
live_service_1 = create_service(service_name="1")
|
2023-07-10 11:06:29 -07:00
|
|
|
|
live_service_1.organization = org_1
|
2023-08-29 14:54:30 -07:00
|
|
|
|
live_service_2 = create_service(service_name="2")
|
2023-07-10 11:06:29 -07:00
|
|
|
|
live_service_2.organization = org_1
|
2023-08-29 14:54:30 -07:00
|
|
|
|
live_service_3 = create_service(service_name="3")
|
2023-07-10 11:06:29 -07:00
|
|
|
|
live_service_3.organization = org_1
|
2023-08-29 14:54:30 -07:00
|
|
|
|
fake_live_service_1 = create_service(service_name="f1", count_as_live=False)
|
2023-07-10 11:06:29 -07:00
|
|
|
|
fake_live_service_1.organization = org_1
|
2023-08-29 14:54:30 -07:00
|
|
|
|
inactive_service_1 = create_service(service_name="i1", active=False)
|
2023-07-10 11:06:29 -07:00
|
|
|
|
inactive_service_1.organization = org_1
|
2019-04-11 13:38:21 +01:00
|
|
|
|
|
|
|
|
|
|
# This service isn’t associated to an org, but should still be counted as live
|
2023-08-29 14:54:30 -07:00
|
|
|
|
create_service(service_name="4")
|
2019-04-11 13:38:21 +01:00
|
|
|
|
|
|
|
|
|
|
# Org 2 has no real live services
|
2023-08-29 14:54:30 -07:00
|
|
|
|
org_2 = create_organization("org 2")
|
|
|
|
|
|
trial_service_1 = create_service(service_name="t1", restricted=True)
|
2023-07-10 11:06:29 -07:00
|
|
|
|
trial_service_1.organization = org_2
|
2023-08-29 14:54:30 -07:00
|
|
|
|
fake_live_service_2 = create_service(service_name="f2", count_as_live=False)
|
2023-07-10 11:06:29 -07:00
|
|
|
|
fake_live_service_2.organization = org_2
|
2023-08-29 14:54:30 -07:00
|
|
|
|
inactive_service_2 = create_service(service_name="i2", active=False)
|
2023-07-10 11:06:29 -07:00
|
|
|
|
inactive_service_2.organization = org_2
|
2019-04-11 13:38:21 +01:00
|
|
|
|
|
|
|
|
|
|
# Org 2 has no services at all
|
2023-08-29 14:54:30 -07:00
|
|
|
|
create_organization("org 3")
|
2019-04-11 13:38:21 +01:00
|
|
|
|
|
|
|
|
|
|
# This service isn’t associated to an org, and should not be counted as live
|
|
|
|
|
|
# because it’s marked as not counted
|
2023-08-29 14:54:30 -07:00
|
|
|
|
create_service(service_name="f3", count_as_live=False)
|
2019-04-11 13:38:21 +01:00
|
|
|
|
|
|
|
|
|
|
# This service isn’t associated to an org, and should not be counted as live
|
|
|
|
|
|
# because it’s in trial mode
|
2023-08-29 14:54:30 -07:00
|
|
|
|
create_service(service_name="t", restricted=True)
|
|
|
|
|
|
create_service(service_name="i", restricted=False, active=False)
|
2019-04-11 13:38:21 +01:00
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
|
assert admin_request.get("status.live_service_and_organization_counts") == {
|
|
|
|
|
|
"organizations": 1,
|
|
|
|
|
|
"services": 4,
|
2019-04-11 13:38:21 +01:00
|
|
|
|
}
|