1717
1818
1919class Base (Model ):
20+ """A base class representing a PynamoDB `Model`.
21+
22+ Args:
23+ Model (_type_): The PynamoDB base class definition.
24+ """
2025 pass
2126
2227
2328class User (DynamoDBBaseUserTableUUID , Base ):
29+ """A class representing an `User` object.
30+
31+ Args:
32+ DynamoDBBaseUserTableUUID (_type_): The underlying table object.
33+ Base (_type_): The PynamoDB base class definition.
34+ """
2435 __tablename__ : str = config .get ("DATABASE_USERTABLE_NAME" ) + "_test"
2536
2637 class Meta :
38+ """The required `Meta` definitions for PynamoDB.
39+
40+ Args:
41+ table_name (str): The name of the table.
42+ region (str): The AWS region string where the table should be created.
43+ billing_mode (str): The billing mode to use when creating the table. \
44+ Currently only supports `PAY_PER_REQUEST`.
45+ """
2746 table_name : str = config .get ("DATABASE_USERTABLE_NAME" ) + "_test"
2847 region : str = config .get ("DATABASE_REGION" )
2948 billing_mode : str = config .get ("DATABASE_BILLING_MODE" ).value
@@ -35,17 +54,42 @@ class Meta:
3554
3655
3756class OAuthBase (Model ):
57+ """The base class representing `OAuth` related models.
58+
59+ Args:
60+ Model (_type_): The PynamoDB base class definition.
61+ """
3862 pass
3963
4064
4165class OAuthAccount (DynamoDBBaseOAuthAccountTableUUID , OAuthBase ):
66+ """A class representing an `OAuthAccount` object.
67+
68+ Args:
69+ DynamoDBBaseOAuthAccountTableUUID (_type_): The underlying table object.
70+ OAuthBase (_type_): The base class for `OAuth`.
71+ """
4272 pass
4373
4474
4575class UserOAuth (DynamoDBBaseUserTableUUID , OAuthBase ):
76+ """A class representing an `UserOAuth` object.
77+
78+ Args:
79+ DynamoDBBaseUserTableUUID (_type_): The underlying table object.
80+ OAuthBase (_type_): The base class representing `OAuth` related models.
81+ """
4682 __tablename__ : str = config .get ("DATABASE_OAUTHTABLE_NAME" ) + "_test"
4783
4884 class Meta :
85+ """The required `Meta` definitions for PynamoDB.
86+
87+ Args:
88+ table_name (str): The name of the table.
89+ region (str): The AWS region string where the table should be created.
90+ billing_mode (str): The billing mode to use when creating the table. \
91+ Currently only supports `PAY_PER_REQUEST`.
92+ """
4993 table_name : str = config .get ("DATABASE_OAUTHTABLE_NAME" ) + "_test"
5094 region : str = config .get ("DATABASE_REGION" )
5195 billing_mode : str = config .get ("DATABASE_BILLING_MODE" ).value
@@ -60,18 +104,39 @@ class Meta:
60104
61105@pytest_asyncio .fixture
62106async def dynamodb_user_db () -> AsyncGenerator [DynamoDBUserDatabase , None ]:
107+ """Create and yield a new `User` database instance for other tests to use.
108+
109+ Returns:
110+ AsyncGenerator[DynamoDBUserDatabase, None]: The `User` database instance.
111+
112+ Yields:
113+ Iterator[AsyncGenerator[DynamoDBUserDatabase, None]]: The `User` database instance.
114+ """
63115 db = DynamoDBUserDatabase (User )
64116 yield db
65117
66118
67119@pytest_asyncio .fixture
68120async def dynamodb_user_db_oauth () -> AsyncGenerator [DynamoDBUserDatabase , None ]:
121+ """Create and yield a new `OAuth` database instance for other tests to use.
122+
123+ Returns:
124+ AsyncGenerator[DynamoDBUserDatabase, None]: The `OAuth` database instance.
125+
126+ Yields:
127+ Iterator[AsyncGenerator[DynamoDBUserDatabase, None]]: The `OAuth` database instance.
128+ """
69129 db = DynamoDBUserDatabase (UserOAuth , OAuthAccount )
70130 yield db
71131
72132
73133@pytest .mark .asyncio
74134async def test_queries (dynamodb_user_db : DynamoDBUserDatabase [User , UUID_ID ]):
135+ """Test basic **CRUD** operations on a `User`.
136+
137+ Args:
138+ dynamodb_user_db (DynamoDBUserDatabase[User, UUID_ID]): The `User` database instance to use.
139+ """
75140 user_create = {"email" : "lancelot@camelot.bt" , "hashed_password" : "guinevere" }
76141
77142 # Create user
@@ -134,6 +199,11 @@ async def test_queries(dynamodb_user_db: DynamoDBUserDatabase[User, UUID_ID]):
134199async def test_insert_existing_email (
135200 dynamodb_user_db : DynamoDBUserDatabase [User , UUID_ID ],
136201):
202+ """Test inserting an email, which already exists.
203+
204+ Args:
205+ dynamodb_user_db (DynamoDBUserDatabase[User, UUID_ID]): The `User` database instance to use.
206+ """
137207 user_create = {
138208 "email" : "lancelot@camelot.bt" ,
139209 "hashed_password" : "guinevere" ,
@@ -157,7 +227,11 @@ async def test_insert_existing_email(
157227async def test_queries_custom_fields (
158228 dynamodb_user_db : DynamoDBUserDatabase [User , UUID_ID ],
159229):
160- """It should output custom fields in query result."""
230+ """Test basic **CRUD** operations (especially querying) on custom fields.
231+
232+ Args:
233+ dynamodb_user_db (DynamoDBUserDatabase[User, UUID_ID]): The `User` database instance to use.
234+ """
161235 user_create = {
162236 "email" : "lancelot@camelot.bt" ,
163237 "hashed_password" : "guinevere" ,
@@ -178,6 +252,14 @@ async def test_queries_oauth(
178252 oauth_account2 : dict [str , Any ],
179253 user_id : UUID_ID ,
180254):
255+ """Test `OAuth` implemenatation and basic **CRUD** operations.
256+
257+ Args:
258+ dynamodb_user_db_oauth (DynamoDBUserDatabase[UserOAuth, UUID_ID]): The `OAuth` database instance to use.
259+ oauth_account1 (dict[str, Any]): A fake `OAuth` account for testing.
260+ oauth_account2 (dict[str, Any]): Another fake `OAuth` account for testing.
261+ user_id (UUID_ID): The default user id to use.
262+ """
181263 # Test OAuth accounts
182264 user_create = {"email" : "lancelot@camelot.bt" , "hashed_password" : "guinevere" }
183265
0 commit comments