def test_set_user_role_with_nonexistent_user_or_role(auth_post): mutation = read_graphql("tests/auth/e2e/queries/permission.graphql") command = { "userAccessKey": helpers.random_word(), "roleCode": helpers.DEFAULT_ROLE_CODE, } response = auth_post( json=dict( query=mutation, operationName="setUserRole", variables=dict(command=command), ), ) errors = response.json()["errors"] assert errors assert "user_not_found" in errors[0]["extensions"]["status"].lower() mutation = read_graphql("tests/auth/e2e/queries/permission.graphql") command = { "userAccessKey": DEFAULT_USER, "roleCode": helpers.random_word(), } response = auth_post( json=dict( query=mutation, operationName="setUserRole", variables=dict(command=command), ), ) errors = response.json()["errors"] assert errors assert "role_not_found" in errors[0]["extensions"]["status"].lower()
def test_send_email(fake_dependencies): sender = fakes.FakeEmailSender() response = sender.send_email( email_to=helpers.TEST_USER_EMAIL, subject=helpers.random_word(), template=helpers.random_word(), ) assert response == 250
def test_role_equality(): code = helpers.random_word() a_role = model.Role( name=helpers.random_word(), code=code, permissions=set() ) b_role = model.Role( name=helpers.random_word(), code=code, permissions=set() ) assert a_role == b_role
def test_unit_of_work_can_persist_role(postgres_session_factory): role = { "code": helpers.random_word(), "name": helpers.random_word(), } uow = unit_of_work.AuthSqlAlchemyUnitOfWork(postgres_session_factory) with uow: model_role = model.Role(**role, permissions=set(uow.permissions.list()[:1])) uow.roles.add(model_role) uow.commit() session = postgres_session_factory() role = helpers.query_role_by_code(session, role["code"]) assert role permissions = helpers.query_role_permissions(session, role["code"]) assert len(permissions) == 1
def test_query_unknown_role(auth_post): response = auth_post(json=dict( query=permission_queries, operationName="role", variables=dict(code=helpers.random_word()), ), ) role = response.json()["data"]["role"] assert role is None
def test_create_role_with_existing_code(auth_post): mutation = read_graphql("tests/auth/e2e/queries/permission.graphql") command = { "code": helpers.DEFAULT_ROLE_CODE, "name": helpers.random_word(), "permissions": [], } response = auth_post( json=dict( query=mutation, operationName="createRole", variables=dict(command=command), ), ) errors = response.json()["errors"] assert errors assert "role_already_exist" in errors[0]["extensions"]["status"].lower()
def test_wrong_scheme(starlette_client): mutation = read_graphql("tests/auth/e2e/queries/permission.graphql") command = { "userAccessKey": helpers.random_word(), "roleCode": helpers.DEFAULT_ROLE_CODE, } headers = dict(Authorization=f"not_bearer wrong.token.for_sure") response = starlette_client.post( json=dict( query=mutation, operationName="setUserRole", variables=dict(command=command), ), url="/", headers=headers, ) errors = response.json()["errors"] assert errors assert "invalid_auth_schema" in errors[0]["extensions"]["status"].lower()
def test_create_role_without_permissions(auth_post): mutation = read_graphql("tests/auth/e2e/queries/permission.graphql") code = helpers.random_word() command = { "code": code, "name": code, } response = auth_post( json=dict( query=mutation, operationName="createRole", variables=dict(command=command), ), ) command_response = response.json()["data"]["createRole"] assert command_response assert "role_created" in command_response["status"].lower()