import json
from http import HTTPMethod, HTTPStatus

from layercake.dynamodb import DynamoDBPersistenceLayer

from ..conftest import HttpApiProxy, LambdaContext


def test_get_admins(
    app,
    seeds,
    http_api_proxy: HttpApiProxy,
    lambda_context: LambdaContext,
):
    r = app.lambda_handler(
        http_api_proxy(
            raw_path='/orgs/f6000f79-6e5c-49a0-952f-3bda330ef278/admins',
            method=HTTPMethod.GET,
        ),
        lambda_context,
    )
    assert r['statusCode'] == HTTPStatus.OK

    r = json.loads(r['body'])
    assert len(r['items']) == 1


def test_revoke(
    app,
    seeds,
    dynamodb_persistence_layer: DynamoDBPersistenceLayer,
    http_api_proxy: HttpApiProxy,
    lambda_context: LambdaContext,
):
    r = app.lambda_handler(
        http_api_proxy(
            raw_path='/orgs/f6000f79-6e5c-49a0-952f-3bda330ef278/admins/15bacf02-1535-4bee-9022-19d106fd7518',
            method=HTTPMethod.DELETE,
        ),
        lambda_context,
    )
    assert r['statusCode'] == HTTPStatus.NO_CONTENT


def test_get_scheduled(
    app,
    seeds,
    http_api_proxy: HttpApiProxy,
    lambda_context: LambdaContext,
):
    r = app.lambda_handler(
        http_api_proxy(
            raw_path='/orgs/1234/enrollments/scheduled',
            method=HTTPMethod.GET,
        ),
        lambda_context,
    )
    assert r['statusCode'] == HTTPStatus.OK
