-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_user_service.py
73 lines (50 loc) · 2.48 KB
/
test_user_service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import unittest
from corbado_python_sdk import CorbadoSDK, UserEntity, UserService, UserStatus
from corbado_python_sdk.exceptions import ServerException
from tests.utils import TestUtils
class TestBase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.sdk: CorbadoSDK = TestUtils.instantiate_sdk()
cls.fixture: UserService = cls.sdk.users
class TestMisc(TestBase):
def test_instantiate_sdk_expect_not_none(self) -> None:
sdk: CorbadoSDK = self.sdk
self.assertIsNotNone(obj=sdk)
class UserCreateTest(TestBase):
"""Test cases for user creation."""
def test_user_create_expect_success(self) -> None:
"""Test case for successful user creation."""
test_status = UserStatus.ACTIVE
test_name: str = TestUtils.create_random_test_name()
rsp: UserEntity = self.fixture.create(status=test_status, full_name=test_name)
self.assertEqual(first=test_status, second=rsp.status)
self.assertEqual(first=test_name, second=rsp.full_name)
class TestUserDelete(TestBase):
"""Tests for the user deletion functionality."""
def test_user_delete_expect_not_found(self) -> None:
"""Test for deleting a user that does not exist."""
with self.assertRaises(expected_exception=ServerException) as context:
self.fixture.delete(user_id="usr-123456789")
e: ServerException = context.exception
self.assertIsNotNone(e)
self.assertEqual(400, e.http_status_code)
self.assertListEqual(["userID: does not exist"], e.validation_messages)
def test_user_delete_expect_success(self) -> None:
"""Test for successfully deleting a user."""
user: UserEntity = TestUtils.create_user()
self.fixture.delete(user_id=user.user_id)
class TestUserGet(TestBase):
"""Tests for the user retrieval functionality."""
def test_user_get_expect_not_found(self) -> None:
"""Test for retrieving a user that does not exist."""
with self.assertRaises(expected_exception=ServerException) as context:
self.fixture.get(user_id="usr-123456789")
e: ServerException = context.exception
self.assertIsNotNone(e)
self.assertEqual(400, e.http_status_code)
def test_user_get_expect_success(self) -> None:
"""Test for successfully retrieving a user."""
user: UserEntity = TestUtils.create_user()
rsp: UserEntity = self.fixture.get(user_id=user.user_id)
self.assertEqual(first=user, second=rsp)