Skip to content

Commit

Permalink
markup of tests for api-gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
ek committed Jul 4, 2021
1 parent a45c536 commit fa2caeb
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 6 deletions.
7 changes: 7 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
- дальше что??
- сайт с доменным именем и хттпс
## фичи
- добавление домена к api-gw
- поддержка статики через cdn
- обработка ошибок
- когда функция уже есть
- когда нет прав
- когда сломанные конфиги
- ентрипоинт не правильный
- cli комманда rollback
- поддержка задания масштабирования
- поддержка выкладвания без пакетов и без бакета
Expand Down
6 changes: 3 additions & 3 deletions tests/functions.py → tests/yc_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_uploaded_package(uploaded_package, config):
assert uploaded_package in keys, keys


def test_function_list(yc):
def test_get_function(yc):
functions = yc.get_functions()
assert isinstance(functions, dict)

Expand All @@ -34,9 +34,9 @@ def test_function_creation(yc, function_name):

def test_function_access(yc, function):
assert yc.is_function_public(function.id) == True
yc.set_access(function.id, is_public=False)
yc.set_function_access(function.id, is_public=False)
assert yc.is_function_public(function.id) == False
yc.set_access(function.id, is_public=True)
yc.set_function_access(function.id, is_public=True)


def test_function_version_creation(yc, function, function_version, config):
Expand Down
64 changes: 64 additions & 0 deletions tests/yc_gateway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import httpx
import pytest


@pytest.mark.skip(reason="not yet implemented")
def test_gw_config_update(function, config):
"""
test if correct yaml is produced
"""


@pytest.fixture(scope="session")
def gateway_name():
return "test-gateway-231"


@pytest.fixture(scope="session")
def gateway_yaml(config):
"""
reads default gw config and adds function_id
"""
pass


@pytest.fixture(scope="session")
def gateway(gateway_yaml, yc):
gw = yc.create_gateway()
yield gw


@pytest.mark.skip(reason="not yet implemented")
def test_get_gateways(yc):
gws = yc.get_gateways()
assert isinstance(gws, dict)


@pytest.mark.skip(reason="not yet implemented")
def test_gateway_creation(gateway, gateway_name, yc):
assert gateway_name in yc.get_gateways()


@pytest.mark.skip(reason="not yet implemented")
def test_gateway_update():
pass


@pytest.mark.skip(reason="not yet implemented")
def test_gateway_call(gateway, function_version):
url = gateway.domain
response = httpx.get(url)
assert response.status_code == 200
assert response.text == "root url"

response = httpx.get(f"{url}/json") # TODO compose url properly
assert response.status_code == 200
assert response.json() == {"result": "json",
"sub_result": {"sub": "json"}
}
num = "param" # TODO generate random string or number?
response = httpx.get(f"{url}/url_param/{num}") # TODO compose url properly
assert response.status_code == 200
assert response.json() == {"param": num}

# TODO add another two urls
1 change: 1 addition & 0 deletions yappa/handle_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def handle(event, context):
response = call_app(app, event)
if not config["debug"]:
return patch_response(response)
# TODO add test if debug is true
return {
'statusCode': 200,
'body': {
Expand Down
21 changes: 18 additions & 3 deletions yappa/yc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def create_function(self, name, description="", is_public=True):
meta_type=CreateFunctionMetadata,
)
function = operation_result.response
self.set_access(function.id, is_public)
self.set_function_access(function.id, is_public)
return function

def delete_function(self, function_id):
Expand All @@ -71,7 +71,7 @@ def delete_function(self, function_id):
)
return operation_result.response

def set_access(self, function_id, is_public=True):
def set_function_access(self, function_id, is_public=True):
if is_public:
access_bindings = [AccessBinding(
role_id='serverless.functions.invoker',
Expand Down Expand Up @@ -106,7 +106,8 @@ def is_function_public(self, function_id):
return False

def create_function_version(self, function_id, runtime, description,
bucket_name, object_name,application_type="wsgi",
bucket_name, object_name,
application_type="wsgi",
memory="128MB", service_account_id=None,
timeout=None, named_service_accounts=None,
environment=None, **kwargs):
Expand All @@ -130,10 +131,24 @@ def create_function_version(self, function_id, runtime, description,
meta_type=CreateFunctionVersionMetadata,
)
return operation_result.response

def get_latest_version(self, function_id):
version = self.function_service.GetVersionByTag(
GetFunctionVersionByTagRequest(
function_id=function_id,
tag="$latest",
))
return version

def get_gateways(self):
pass

def create_gateway(self, name, description, openapi_spec):
pass

def update_gateway(self):
pass

def delete_gateway(self):
pass

0 comments on commit fa2caeb

Please sign in to comment.