Skip to content

Commit 0353747

Browse files
committed
Fix docs and tests for classproperty
1 parent 94c5332 commit 0353747

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

fastapi_users_db_dynamodb/_generics.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,24 @@
66
UUID_ID = uuid.UUID
77

88

9-
class classproperty:
9+
class classproperty: # pragma: no cover
10+
"""A decorator which behaves like `@property`, but for classmethods.
11+
This allows to define read-only class properties.
12+
Example::
13+
```python
14+
class Foo:
15+
@classproperty
16+
def bar(cls):
17+
return 42 \
18+
19+
Foo.bar # calls __get__ \
20+
21+
Foo.bar = 99 # does NOT call __set__ on classproperty, just sets Foo.bar to 99 \
22+
23+
del Foo.bar # does NOT call __delete__ on classproperty, just deletes Foo.bar
24+
```
25+
"""
26+
1027
def __init__(self, fget=None, fset=None, fdel=None):
1128
self.fget = fget
1229
self.fset = fset

tests/test_misc.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import pytest
22
from aiopynamodb.models import Model
33

4-
from fastapi_users_db_dynamodb import config
4+
from fastapi_users_db_dynamodb import DynamoDBBaseUserTable, config
55
from fastapi_users_db_dynamodb._generics import classproperty
6+
from fastapi_users_db_dynamodb.access_token import DynamoDBBaseAccessTokenTable
67
from fastapi_users_db_dynamodb.attributes import GUID
78
from fastapi_users_db_dynamodb.tables import delete_tables, ensure_tables_exist
89

@@ -94,6 +95,24 @@ def test_config(monkeypatch):
9495
config.set("DATABASE_REGION", region)
9596
assert config.get("DATABASE_REGION") == region
9697

98+
# Test Meta definitions
99+
assert DynamoDBBaseUserTable.Meta.table_name == config.get(
100+
"DATABASE_USERTABLE_NAME"
101+
)
102+
assert DynamoDBBaseAccessTokenTable.Meta.table_name == config.get(
103+
"DATABASE_TOKENTABLE_NAME"
104+
)
105+
assert (
106+
DynamoDBBaseUserTable.Meta.region
107+
== DynamoDBBaseAccessTokenTable.Meta.region
108+
== config.get("DATABASE_REGION")
109+
)
110+
assert (
111+
DynamoDBBaseUserTable.Meta.billing_mode
112+
== DynamoDBBaseAccessTokenTable.Meta.billing_mode
113+
== config.get("DATABASE_BILLING_MODE").value
114+
)
115+
97116

98117
def test_attributes(user_id):
99118
"""Test serialization and deserialization of `Attribute` instances.

0 commit comments

Comments
 (0)