Files
plexpy/test/services/test_security.py
2023-10-26 21:45:48 -05:00

77 lines
2.7 KiB
Python

import unittest
import responses
from src.plexsdk.net.http_client import HTTPClient
from http_exceptions import ClientException
from src.plexsdk.services.security import Security
class TestSecurity_(unittest.TestCase):
def test_true(self):
self.assertTrue(True)
@responses.activate
def test_get_transient_token(self):
# Mock the API response
responses.get("{protocol}://{ip}:{port}/security/token", json={}, status=200)
# call the method to test
test_service = Security("testkey")
response = test_service.get_transient_token("all", "delegation")
self.assertEqual(response.data, {})
responses.reset(),
@responses.activate
def test_get_transient_token_required_fields_missing(self):
# Mock the API response
responses.get("{protocol}://{ip}:{port}/security/token", json={}, status=202)
with self.assertRaises(TypeError):
test_service = Security("testkey")
test_service.get_transient_token()
responses.reset(),
@responses.activate
def test_get_transient_token_error_on_non_200(self):
# Mock the API response
responses.get("{protocol}://{ip}:{port}/security/token", json={}, status=404)
with self.assertRaises(ClientException):
test_service = Security("testkey")
test_service.get_transient_token("all", "delegation")
responses.reset()
@responses.activate
def test_get_source_connection_information(self):
# Mock the API response
responses.get(
"{protocol}://{ip}:{port}/security/resources", json={}, status=200
)
# call the method to test
test_service = Security("testkey")
response = test_service.get_source_connection_information("provident")
self.assertEqual(response.data, {})
responses.reset(),
@responses.activate
def test_get_source_connection_information_required_fields_missing(self):
# Mock the API response
responses.get(
"{protocol}://{ip}:{port}/security/resources", json={}, status=202
)
with self.assertRaises(TypeError):
test_service = Security("testkey")
test_service.get_source_connection_information()
responses.reset(),
@responses.activate
def test_get_source_connection_information_error_on_non_200(self):
# Mock the API response
responses.get(
"{protocol}://{ip}:{port}/security/resources", json={}, status=404
)
with self.assertRaises(ClientException):
test_service = Security("testkey")
test_service.get_source_connection_information("molestiae")
responses.reset()
if __name__ == "__main__":
unittest.main()