tests: add some assertions about hobo json (#61944)

This commit is contained in:
Emmanuel Cazenave 2022-03-01 13:03:01 +01:00
parent 120723aeab
commit 003b15204f
1 changed files with 192 additions and 0 deletions

View File

@ -24,22 +24,208 @@ def get_hobo_json_filename(tenant):
return json_filename
def count_hobo_services(hobo_json):
return len([service for service in hobo_json['services'] if service['service-id'] == 'hobo'])
def assert_hobo1_service_in_hobo1(hobo_json):
for service in hobo_json['services']:
if service['slug'] == 'hobo':
assert service['service-id'] == 'hobo'
assert service['title'] == 'Hobo'
assert service['backoffice-menu-url'] == 'http://tenant1.example.net/menu.json'
assert service['base_url'] == 'http://tenant1.example.net/'
assert service['provisionning-url'] == 'http://tenant1.example.net/__provision__/'
assert service['saml-sp-metadata-url'] == 'http://tenant1.example.net/accounts/mellon/metadata/'
assert service['secret_key'] == 'fe4a8768479f0b82d3f465f65609fd7c43b4fc8f'
assert 'id' not in service
return
assert False, "Can't find hobo1 service"
def assert_hobo1_service_in_hobo2(hobo_json):
for service in hobo_json['services']:
if service['slug'] == '_interco_hobo':
assert service['service-id'] == 'hobo'
assert service['title'] == 'Hobo'
assert 'backoffice-menu-url' not in service
assert service['base_url'] == 'http://tenant1.example.net/'
assert service['provisionning-url'] == 'http://tenant1.example.net/__provision__/'
assert service['saml-sp-metadata-url'] == 'http://tenant1.example.net/accounts/mellon/metadata/'
assert service['secret_key'] == 'fe4a8768479f0b82d3f465f65609fd7c43b4fc8f'
assert 'id' in service
assert service['secondary'] is True
assert service['template_name'] == ''
assert service['variables'] == {}
return
assert False, "Can't find hobo1 service"
def assert_hobo1_service_in_hobo3(hobo_json):
for service in hobo_json['services']:
if service['slug'] == '_interco_hobo':
assert service['service-id'] == 'hobo'
assert service['title'] == 'Hobo'
assert 'backoffice-menu-url' not in service
assert service['base_url'] == 'http://tenant1.example.net/'
assert service['provisionning-url'] == 'http://tenant1.example.net/__provision__/'
assert service['saml-sp-metadata-url'] == 'http://tenant1.example.net/accounts/mellon/metadata/'
assert service['secret_key'] == 'fe4a8768479f0b82d3f465f65609fd7c43b4fc8f'
assert 'id' in service
assert service['secondary'] is True
assert service['template_name'] == ''
assert service['variables'] == {}
return
assert False, "Can't find hobo1 service"
def assert_hobo2_service_in_hobo1(hobo_json):
for service in hobo_json['services']:
if service['slug'] == 'hobo-coll2':
assert service['service-id'] == 'hobo'
assert service['title'] == 'Coll2'
assert 'backoffice-menu-url' not in service
assert 'base-url' not in service
assert service['base_url'] == 'http://hobo2.example.net/'
assert service['provisionning-url'] == 'http://hobo2.example.net/__provision__/'
assert service['saml-sp-metadata-url'] == 'http://hobo2.example.net/accounts/mellon/metadata/'
assert service['secondary'] is False
assert service['template_name'] == ''
assert service['variables'] == {}
assert 'secret_key' in service
assert 'id' in service
return
assert False, "Can't find hobo2 service"
def assert_hobo2_service_in_hobo2(hobo_json):
for service in hobo_json['services']:
if service['slug'] == 'hobo':
assert service['service-id'] == 'hobo'
assert service['title'] == 'Hobo'
assert service['backoffice-menu-url'] == 'https://hobo2.example.net/menu.json'
assert service['base_url'] == 'https://hobo2.example.net/'
assert service['provisionning-url'] == 'https://hobo2.example.net/__provision__/'
assert service['saml-sp-metadata-url'] == 'https://hobo2.example.net/accounts/mellon/metadata/'
assert 'secret_key' in service
assert 'id' not in service
return
assert False, "Can't find hobo2 service"
def assert_hobo2_service_in_hobo3(hobo_json):
for service in hobo_json['services']:
if service['slug'] == '_interco_hobo-coll2':
assert service['service-id'] == 'hobo'
assert service['title'] == 'Coll2'
assert 'backoffice-menu-url' not in service
assert 'base-url' not in service
assert service['base_url'] == 'http://hobo2.example.net/'
assert service['provisionning-url'] == 'http://hobo2.example.net/__provision__/'
assert service['saml-sp-metadata-url'] == 'http://hobo2.example.net/accounts/mellon/metadata/'
assert service['secondary'] is True
assert service['template_name'] == ''
assert service['variables'] == {}
assert 'secret_key' in service
assert 'id' in service
return
assert False, "Can't find hobo2 service"
def assert_hobo3_service_in_hobo1(hobo_json):
for service in hobo_json['services']:
if service['slug'] == 'hobo-coll3':
assert service['service-id'] == 'hobo'
assert service['title'] == 'Coll3'
assert 'backoffice-menu-url' not in service
assert 'base-url' not in service
assert service['base_url'] == 'http://hobo3.example.net/'
assert service['provisionning-url'] == 'http://hobo3.example.net/__provision__/'
assert service['saml-sp-metadata-url'] == 'http://hobo3.example.net/accounts/mellon/metadata/'
assert service['secondary'] is False
assert service['template_name'] == ''
assert service['variables'] == {}
assert 'secret_key' in service
assert 'id' in service
return
assert False, "Can't find hobo3 service"
def assert_hobo3_service_in_hobo2(hobo_json):
for service in hobo_json['services']:
if service['slug'] == '_interco_hobo-coll3':
assert service['service-id'] == 'hobo'
assert service['title'] == 'Coll3'
assert 'backoffice-menu-url' not in service
assert 'base-url' not in service
assert service['base_url'] == 'http://hobo3.example.net/'
assert service['provisionning-url'] == 'http://hobo3.example.net/__provision__/'
assert service['saml-sp-metadata-url'] == 'http://hobo3.example.net/accounts/mellon/metadata/'
assert service['secondary'] is True
assert service['template_name'] == ''
assert service['variables'] == {}
assert 'secret_key' in service
assert 'id' in service
return
assert False, "Can't find hobo3 service"
def assert_hobo3_service_in_hobo3(hobo_json):
for service in hobo_json['services']:
if service['slug'] == 'hobo':
assert service['service-id'] == 'hobo'
assert service['title'] == 'Hobo'
assert service['backoffice-menu-url'] == 'https://hobo3.example.net/menu.json'
assert service['base_url'] == 'https://hobo3.example.net/'
assert service['provisionning-url'] == 'https://hobo3.example.net/__provision__/'
assert service['saml-sp-metadata-url'] == 'https://hobo3.example.net/accounts/mellon/metadata/'
assert 'secret_key' in service
assert 'id' not in service
return
assert False, "Can't find hobo3 service"
def test_multipublik(tenants, mocker):
hobo1 = tenants[0]
hobo1.base_url = 'http://tenant1.example.net/'
with tenant_context(hobo1):
hobo_json = get_hobo_json()
assert count_hobo_services(hobo_json) == 1
assert_hobo1_service_in_hobo1(hobo_json)
hobo2 = Hobo(title='Coll2', slug='hobo-coll2', base_url='http://hobo2.example.net')
hobo2.save()
hobo_json = get_hobo_json()
assert count_hobo_services(hobo_json) == 2
assert_hobo1_service_in_hobo1(hobo_json)
assert_hobo2_service_in_hobo1(hobo_json)
hobo3 = Hobo(title='Coll3', slug='hobo-coll3', base_url='http://hobo3.example.net')
hobo3.save()
hobo_json = get_hobo_json()
assert count_hobo_services(hobo_json) == 3
assert_hobo1_service_in_hobo1(hobo_json)
assert_hobo2_service_in_hobo1(hobo_json)
assert_hobo3_service_in_hobo1(hobo_json)
combo = Combo(title='Portail', slug='portal', base_url='http://combo1.example.net')
combo.save()
assert count_hobo_services(hobo_json) == 3
assert_hobo1_service_in_hobo1(hobo_json)
assert_hobo2_service_in_hobo1(hobo_json)
assert_hobo3_service_in_hobo1(hobo_json)
# inform coll2 about interco environment
HoboDeployCommand().handle(hobo2.base_url, get_hobo_json_filename(hobo1))
hobo2 = TenantMiddleware.get_tenant_by_hostname('hobo2.example.net')
with tenant_context(hobo2):
hobo_json = get_hobo_json()
assert count_hobo_services(hobo_json) == 3
assert_hobo1_service_in_hobo2(hobo_json)
assert_hobo2_service_in_hobo2(hobo_json)
assert_hobo3_service_in_hobo2(hobo_json)
# interco combo created
assert Combo.objects.count() == 1
combo = Combo.objects.first()
@ -103,6 +289,12 @@ def test_multipublik(tenants, mocker):
hobo3 = TenantMiddleware.get_tenant_by_hostname('hobo3.example.net')
hobo3.base_url = 'http://hobo3.example.net/'
with tenant_context(hobo3):
hobo_json = get_hobo_json()
assert count_hobo_services(hobo_json) == 3
assert_hobo1_service_in_hobo3(hobo_json)
assert_hobo2_service_in_hobo3(hobo_json)
assert_hobo3_service_in_hobo3(hobo_json)
# interco combo created
assert Combo.objects.count() == 1
combo = Combo.objects.first()