11"""Tests for the redis orm"""
22from datetime import date
3+ from ipaddress import ip_network
4+ from ipaddress import IPv4Network
35from random import randint
46from random import sample
57from typing import List
@@ -58,6 +60,12 @@ class TestModelWithNone(Model):
5860 optional_field : Optional [str ]
5961
6062
63+ class TestModelWithIP (Model ):
64+ _primary_key_field = "name"
65+ name : str
66+ ip_network : IPv4Network
67+
68+
6169extended_books = [
6270 ExtendedBook (** book .dict (), editions = sample (editions , randint (0 , len (editions ))))
6371 for book in books
@@ -69,6 +77,11 @@ class TestModelWithNone(Model):
6977 TestModelWithNone (name = "test2" ),
7078]
7179
80+ test_ip_models = [
81+ TestModelWithIP (name = "test" , ip_network = ip_network ("10.10.0.0/24" )),
82+ TestModelWithIP (name = "test2" , ip_network = ip_network ("192.168.0.0/16" )),
83+ ]
84+
7285
7386@pytest .fixture ()
7487async def redis_store (redis_server ):
@@ -81,6 +94,7 @@ async def redis_store(redis_server):
8194 store .register_model (Book )
8295 store .register_model (ExtendedBook )
8396 store .register_model (TestModelWithNone )
97+ store .register_model (TestModelWithIP )
8498 yield store
8599 keys = [f"book_%&_{ book .title } " for book in books ]
86100 await store .redis_store .delete (* keys )
@@ -126,6 +140,7 @@ def test_store_model(redis_store):
126140 (pytest .lazy_fixture ("redis_store" ), books , Book ),
127141 (pytest .lazy_fixture ("redis_store" ), extended_books , ExtendedBook ),
128142 (pytest .lazy_fixture ("redis_store" ), test_models , TestModelWithNone ),
143+ (pytest .lazy_fixture ("redis_store" ), test_ip_models , TestModelWithIP ),
129144]
130145
131146
0 commit comments