qcs-python/test_contentapi.py

45 lines
1.5 KiB
Python
Raw Normal View History

2023-05-01 14:35:31 +00:00
import unittest
import contentapi
import logging
class TestContentapi(unittest.TestCase):
def setUp(self) -> None:
2023-05-01 15:21:45 +00:00
# MAYBE change all these some time? Should connect to a local instance!!
2023-05-01 14:35:31 +00:00
self.api = contentapi.ApiContext("https://oboy.smilebasicsource.com/api", logging)
2023-05-01 15:21:45 +00:00
self.known_content_id = 384
self.known_name = "Megathread"
2023-05-01 14:35:31 +00:00
def test_apistatus(self):
result = self.api.api_status()
2023-05-01 15:21:45 +00:00
self.assertIn("version", result)
2023-05-01 14:35:31 +00:00
def test_is_token_valid_none(self):
self.assertFalse(self.api.is_token_valid())
def test_is_token_valid_garbage(self):
self.api.token = "literalgarbage"
self.assertFalse(self.api.is_token_valid())
2023-05-01 15:21:45 +00:00
def test_get_by_id_notfound(self):
try:
self.api.get_by_id("content", 0)
except contentapi.NotFoundError:
return
self.assertFalse(True, "Didn't throw expected exception!")
def test_get_by_id_known(self):
result = self.api.get_by_id("content", self.known_content_id)
self.assertIn("id", result)
self.assertEqual(result["id"], self.known_content_id)
def test_basic_search(self):
result = self.api.basic_search(self.known_name)
self.assertIn("content", result["objects"])
self.assertTrue(len(result["objects"]["content"]) >= 1)
self.assertTrue(any(self.known_name in item["name"] for item in result["objects"]["content"]))
2023-05-01 14:35:31 +00:00
if __name__ == '__main__':
unittest.main()