Skip to content

Commit b8ae001

Browse files
committed
Add more general tests
1 parent 8cdaf4e commit b8ae001

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

tests/test_misc.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import pytest
2+
from aiopynamodb.models import Model
3+
4+
from fastapi_users_db_dynamodb import config
5+
from fastapi_users_db_dynamodb.attributes import GUID
6+
from fastapi_users_db_dynamodb.tables import ensure_tables_exist
7+
8+
9+
class NotAModel:
10+
pass
11+
12+
13+
class IncompleteModel(Model):
14+
pass
15+
16+
17+
@pytest.mark.asyncio
18+
async def test_tables_invalid_models(monkeypatch):
19+
with pytest.raises(TypeError, match="must be a subclass of Model"):
20+
await ensure_tables_exist(NotAModel) # type: ignore
21+
22+
with pytest.raises(AttributeError, match="PynamoDB Models require a"):
23+
await ensure_tables_exist(IncompleteModel)
24+
25+
monkeypatch.delattr(Model, "exists", raising=True)
26+
with pytest.raises(TypeError):
27+
await ensure_tables_exist(IncompleteModel)
28+
29+
30+
def test_config(monkeypatch):
31+
billing_mode = config.BillingMode.PAY_PER_REQUEST
32+
assert billing_mode.value == str(billing_mode)
33+
34+
local_get, local_set = config.__create_config()
35+
monkeypatch.setattr(config, "get", local_get)
36+
monkeypatch.setattr(config, "set", local_set)
37+
38+
with pytest.raises(KeyError, match="Unknown config key"):
39+
config.set("non_existent_key", "some_value")
40+
41+
with pytest.raises(TypeError, match="Invalid type for"):
42+
config.set("DATABASE_BILLING_MODE", 1001)
43+
44+
region = "us-east-1"
45+
config.set("DATABASE_REGION", region)
46+
assert config.get("DATABASE_REGION") == region
47+
48+
49+
def test_attributes(user_id):
50+
id = GUID()
51+
assert id.serialize(None) is None
52+
53+
user_id_str = str(user_id)
54+
assert user_id_str == id.serialize(user_id_str)
55+
56+
assert id.deserialize(None) is None
57+
assert user_id == id.deserialize(user_id)

0 commit comments

Comments
 (0)