qcs-python/user/modules/test_contentapi.py

46 lines
1.6 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 17:07:31 +00:00
# Requires some local setup. This data points to the SBS instance you usually run to
# test the SBS frontend (contentapi_copy)
self.api = contentapi.ApiContext("http://localhost:5000/api", logging)
self.known_content_id = 15050 # 384
self.known_name = "Big Dumb" # "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()