Skip to content

Commit

Permalink
Add integration tests for headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Toktar committed Jul 11, 2022
1 parent 4c59827 commit 645b062
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
10 changes: 5 additions & 5 deletions tests/pytest/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
FAKE_MAINNET_DID = "did:cheqd:mainnet:zFWM1mKVGGU2gHYuLAQcTJfZBebqBpGf"
FAKE_MAINNET_FRAGMENT = MAINNET_DID + "#fake_key"

DIDJSON = "application/did+json"
DIDLDJSON = "application/did+ld+json"
LDJSON = "application/ld+json"
HTML = "text/html"


IMPLICIT_TIMEOUT = 40
ENCODING = "utf-8"
Expand All @@ -30,11 +35,6 @@ def run(command, params, expected_output):
return cli


def run_interaction(cli, input_string, expected_output):
cli.sendline(input_string)
cli.expect(expected_output)


def json_loads(s_to_load: str) -> dict:
s = copy.copy(s_to_load)
s = s.replace("\\", "")
Expand Down
32 changes: 31 additions & 1 deletion tests/pytest/test_resolution.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import re

import pytest
import requests

from helpers import run, TESTNET_DID, MAINNET_DID, TESTNET_FRAGMENT, MAINNET_FRAGMENT, \
FAKE_TESTNET_DID, FAKE_MAINNET_DID, FAKE_TESTNET_FRAGMENT, FAKE_MAINNET_FRAGMENT, RESOLVER_URL, PATH
FAKE_TESTNET_DID, FAKE_MAINNET_DID, FAKE_TESTNET_FRAGMENT, FAKE_MAINNET_FRAGMENT, RESOLVER_URL, PATH, \
LDJSON, DIDJSON, DIDLDJSON, HTML


@pytest.mark.parametrize(
Expand Down Expand Up @@ -29,3 +34,28 @@
)
def test_resolution(did_url, expected_output):
run("curl", RESOLVER_URL + PATH + did_url.replace("#", "%23"), expected_output)


@pytest.mark.parametrize(
"accept, expected_header, expected_body",
[
(LDJSON, LDJSON, r"(.*?)didDocument(.*?)@context(.*?)didDocumentMetadata"
r"(.*?)didResolutionMetadata(.*?)application/ld\+json"),
(DIDLDJSON, DIDLDJSON, "(.*?)didDocument(.*?)@context(.*?)didDocumentMetadata"
"(.*?)didResolutionMetadata(.*?)application/did\+ld\+json"),
("", DIDLDJSON, "(.*?)didDocument(.*?)@context(.*?)didDocumentMetadata"
"(.*?)didResolutionMetadata(.*?)application/did\+ld\+json"),
(DIDJSON, DIDJSON, r"(.*?)didDocument(.*?)(?!`@context`)(.*?)didDocumentMetadata"
r"(.*?)didResolutionMetadata(.*?)application/did\+json"),
(HTML + ",application/xhtml+xml", HTML, fr"(.*?)didDocument(.*?)(?!`@context`)(.*?)didDocumentMetadata"
fr"(.*?)didResolutionMetadata(.*?){HTML}"),
]
)
def test_resolution_content_type(accept, expected_header, expected_body):
url = RESOLVER_URL + PATH + TESTNET_DID
header = {"Accept": accept} if accept else {}

r = requests.get(url, headers=header)

assert r.headers["Content-Type"] == expected_header
assert re.match(expected_body, r.text)

0 comments on commit 645b062

Please sign in to comment.