Skip to content

Commit

Permalink
While updating tests found some dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
marcpage authored and pagerk committed Aug 28, 2024
1 parent aa9d267 commit 4bed5e6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
6 changes: 2 additions & 4 deletions genweb/webapi_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,8 @@ def handle_post(self, handler: Handler) -> tuple[bytes, str, int]:
body = None
mimetype = "text/json"
response_code = 200

if category != "metadata" or not identifier:
assert body is not None, f"Not an API call {handler.path}"
return body, mimetype, response_code
assert category == "metadata", f"Only POST metadata supported, not {category}"
assert identifier, "POST metadata requires an identifier in the URI"

# upload a metadata entry
body_bytes = int(handler.headers["Content-Length"])
Expand Down
35 changes: 34 additions & 1 deletion tests/test_webapi_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def __getitem__(self, key: str) -> dict:
return self.dict.__getitem__(key)

def get(self, key, default):
print(f"get({key}, {default})")
return self.dict.get(key, default)


Expand Down Expand Up @@ -315,6 +314,39 @@ def test_load() -> None:
api.load()


def test_post():
api = ApiV1()
api.settings = {}
api.people = {}
api.metadata = MockMetadata()
handler = MockHandler(ApiV1.URL + "people")

try:
api.handle_post(handler)
raise AssertionError("Expected an exception")

except AssertionError:
pass

handler = MockHandler(ApiV1.URL + "people/people1")

try:
api.handle_post(handler)
raise AssertionError("Expected an exception")

except AssertionError:
pass

handler = MockHandler(ApiV1.URL + "metadata")

try:
api.handle_post(handler)
raise AssertionError("Expected an exception")

except AssertionError:
pass


if __name__ == "__main__":
test_list_people()
test_list_metadata()
Expand All @@ -326,3 +358,4 @@ def test_load() -> None:
test_person_404()
test_is_call()
test_load()
test_post()

0 comments on commit 4bed5e6

Please sign in to comment.