Skip to content

Commit

Permalink
Test set_up_schemathesis
Browse files Browse the repository at this point in the history
  • Loading branch information
ways committed Nov 19, 2024
1 parent 6c61cc2 commit f67d3c9
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 4 deletions.
3 changes: 2 additions & 1 deletion sedr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
__license__ = "GPL-3.0"
__version__ = "v0.7.5"

import sys
import pytest
import util

Expand All @@ -14,7 +15,7 @@ def main():


# Handle --version and --help
util.args = util.parse_args(__version__)
util.args = util.parse_args(sys.argv[1:], __version__)
util.logger = util.set_up_logging(
args=util.args, logfile=util.args.log_file, version=__version__
)
Expand Down
22 changes: 22 additions & 0 deletions sedr/test_schemat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Unit tests for schemat.py."""

import unittest
import util


class TestInit(unittest.TestCase):
def test_set_up_schemathesis(self):
"""Test set_up_schemathesis."""
__version__ = "testversion"

util.args = util.parse_args([], __version__)
util.args.openapi_version == "3.1"

util.logger = util.set_up_logging(
args=util.args, logfile=util.args.log_file, version=__version__
)
import schemat

schemat.schema = schemat.set_up_schemathesis(util.args)
self.assertTrue(schemat.schema)

9 changes: 8 additions & 1 deletion sedr/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
class TestUtil(unittest.TestCase):
def test_parse_landing_json(self):
"""Test parsing a generic landing page in json."""
with open("../testdata/landingpage.json", "r", encoding="utf-8") as f:
with open("testdata/landingpage.json", "r", encoding="utf-8") as f:
landingpage_json = json.loads(f.read())
landing, _ = util.parse_landing_json(landingpage_json)
self.assertTrue(landing)

def test_parse_bad_landing(self):
"""Test parsing a bad landing page (in json)."""
with open("testdata/landingpage_bad_service-desc.json", "r", encoding="utf-8") as f:
landingpage_json = json.loads(f.read())
landing, _ = util.parse_landing_json(landingpage_json)
self.assertFalse(landing)
4 changes: 2 additions & 2 deletions sedr/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
args = logger = None


def parse_args(version: str = "") -> argparse.Namespace:
def parse_args(args, version: str = "") -> argparse.Namespace:
"""Parse arguments."""
parser = argparse.ArgumentParser(description="schemathesis-edr")
parser.add_argument("-v", "--version", action="version", version=version)
Expand Down Expand Up @@ -53,7 +53,7 @@ def parse_args(version: str = "") -> argparse.Namespace:
help="Use the rodeo profile even though the API doesn't specify it. Default False.",
)

args = parser.parse_args()
args = parser.parse_args(args)
# Parse out base_path for conveience
args.base_path = urlsplit(args.url).path or "/"

Expand Down
79 changes: 79 additions & 0 deletions testdata/landingpage_bad_service-desc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"title": "Example API Landing Page",
"description": "This is an example of an API landing page in JSON format",
"attribution": "<a href='www.ign.es' rel=' '>IGN</a> <a href='www.govdata.de/dl-de/by-2-0'>(c)</a>",
"links": [
{
"rel": "service-desc",
"type": "application/json",
"title": "API definition for this endpoint as JSON",
"href": "http://www.example.com/oapi-c/api?f=application/json"
},
{
"rel": "service-desc",
"type": "text/html",
"title": "API definition for this endpoint as HTML",
"href": "https://edrisobaric.k8s.met.no/docs"
},
{
"rel": "http://www.opengis.net/def/rel/ogc/1.0/data-meta",
"type": "application/xml",
"title": "ISO 19115 Metadata as XML",
"href": "http://www.example.com/oapi-c/data-meta?f=application/xml"
},
{
"rel": "http://www.opengis.net/def/rel/ogc/1.0/conformance",
"type": "application/json",
"title": "Conformance Declaration as JSON",
"href": "http://www.example.com/oapi-c/conformance?f=application/json"
},
{
"rel": "http://www.opengis.net/def/rel/ogc/1.0/conformance",
"type": "application/xml",
"title": "Conformance Declaration as XML",
"href": "http://www.example.com/oapi-c/conformance?f=application/xml"
},
{
"rel": "http://www.opengis.net/def/rel/ogc/1.0/conformance",
"type": "text/html",
"title": "Conformance Declaration as HTML",
"href": "http://www.example.com/oapi-c/conformance?f=text/html"
},
{
"rel": "http://www.opengis.net/def/rel/ogc/1.0/data",
"type": "application/json",
"title": "Collections Metadata as JSON",
"href": "http://www.example.com/oapi-c/collections?f=application/json"
},
{
"rel": "http://www.opengis.net/def/rel/ogc/1.0/data",
"type": "application/xml",
"title": "Collections Metadata as XML",
"href": "http://www.example.com/oapi-c/collections?f=application/xml"
},
{
"rel": "http://www.opengis.net/def/rel/ogc/1.0/data",
"type": "text/html",
"title": "Collections Metadata as HTML",
"href": "http://www.example.com/oapi-c/collections?f=text/html"
},
{
"rel": "self",
"type": "application/json",
"title": "This Document",
"href": "http://www.example.com/oapi-c?f=application/json"
},
{
"rel": "alternate",
"type": "application/xml",
"title": "This Document as XML",
"href": "http://www.example.com/oapi-c?f=application/xml"
},
{
"rel": "alternate",
"type": "text/html",
"title": "This Document as HTML",
"href": "http://www.example.com/oapi-c?f=text/html"
}
]
}

0 comments on commit f67d3c9

Please sign in to comment.