Skip to content
Snippets Groups Projects
Commit d7b7bc63 authored by Juan Pedro Sánchez's avatar Juan Pedro Sánchez
Browse files

base fixtures to test

parent f67c8bde
No related branches found
No related tags found
No related merge requests found
......@@ -187,12 +187,6 @@ KEYCLOAK = {
'password': env('KEYCLOAK_ADMIN_PASSWORD'),
'realm_name': env('KEYCLOAK_REALM'),
'verify': env.bool("KEYCLOAK_ADMIN_VERIFY"),
},
'openid_client': {
'server_url': env('KEYCLOAK_SERVER_URL'),
'client_id': env('OIDC_RP_CLIENT_ID'),
'realm_name': env('KEYCLOAK_REALM'),
'client_secret_key': env('OIDC_RP_CLIENT_SECRET')
}
}
......
from .fixtures import keycloak_admin, keycloak, user_id
\ No newline at end of file
from .fixtures import *
\ No newline at end of file
from http import server
import pytest
from keycloak import KeycloakAdmin, KeycloakOpenID
@pytest.fixture
def keycloak_master_admin(settings):
def ov_ccee_client():
'''
OV CCEE client example
'''
return {
'clientId': 'ov_ccee_client',
'protocol': 'openid-connect',
'enabled': True,
'secret': '7srwMecg9qw23sAM1JSoB0aFtSqYFJAD',
'directAccessGrantsEnabled': True,
'redirectUris': ['http://localhost:8080/auth/*']
}
@pytest.fixture
def emma_goldman():
return {
'email': 'emma.goldman@ccee.coop',
'username': 'emma.goldman',
'enabled': True,
'firstName': 'Emma',
'lastName': 'Goldman',
'credentials': [{
'type': 'password',
'value': '1234',
'temporary': False
}]
}
@pytest.fixture
def enrico_malatesta():
return {
'email': 'e.malatesta@ccee.coop',
'username': 'e.malatesta',
'enabled': True,
'firstName': 'Errico',
'lastName': 'Malatesta',
'credentials': [{
'type': 'password',
'value': '1234',
'temporary': False
}]
}
@pytest.fixture
def ov_ccee_clients(ov_ccee_client):
'''
Test client for ccee realm
'''
return [ov_ccee_client]
@pytest.fixture
def ov_ccee_users(emma_goldman, enrico_malatesta):
'''
Base users for ccee realm
'''
return [emma_goldman, enrico_malatesta]
@pytest.fixture
def ov_ccee_realm(ov_ccee_clients, ov_ccee_users):
'''
OV CCEE realm sample
'''
realm = {
'realm': 'ccee',
'enabled': True,
'users': ov_ccee_users,
'clients': ov_ccee_clients,
}
return realm
@pytest.fixture
def keycloak_admin(settings):
'''
Keycloak admin client
'''
admin = KeycloakAdmin(**settings.KEYCLOAK['admin'])
yield admin
@pytest.fixture
def keycloak(settings):
keycloak = KeycloakOpenID(**settings.KEYCLOAK['openid_client'])
yield keycloak
def ccee_base_setup(keycloak_admin, ov_ccee_realm):
'''
Creates the minimal users and realm configuration to test
against keycloak auth server
'''
# create test ccee realm
keycloak_admin.create_realm(
payload=ov_ccee_realm
)
ccee_realm = keycloak_admin.get_realm(ov_ccee_realm['realm'])
yield ccee_realm
keycloak_admin.delete_realm(ccee_realm['realm'])
@pytest.fixture
def user_id(keycloak_admin):
user_id = keycloak_admin.create_user({
'email': 'emma.goldman@ccee.coop',
'username': 'emma.goldman',
'enabled': True,
'firstName': 'Emma',
'lastName': 'Goldman'
})
yield user_id
keycloak_admin.delete_user(user_id)
def keycloak(keycloak_admin, ccee_base_setup, ov_ccee_client, ov_ccee_realm):
'''
keycloak ccee client
'''
keycloak = KeycloakOpenID(
server_url=keycloak_admin._server_url,
client_id=ov_ccee_client['clientId'],
realm_name=ov_ccee_realm['realm'],
client_secret_key=ov_ccee_client['secret']
)
yield keycloak
@pytest.fixture
def auth_token(keycloack):
# Not implemented yet
pass
def emma_auth_token(keycloak, emma_goldman):
'''
Emma Goldman authetication token. This token is the same as the
returned to the frontend
'''
password = emma_goldman['credentials'][0]['value']
token = keycloak.token(emma_goldman['username'], password)
return token
\ No newline at end of file
def test_create_user_fixture(user_id):
assert user_id is not None
\ No newline at end of file
def test_base_setup_fixture(ccee_base_setup):
assert ccee_base_setup is not None
def test_keycloak_fixture(keycloak):
assert keycloak is not None
def test_emma_auth_token_fixture(emma_auth_token):
assert emma_auth_token is not None
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment