Skip to content

Commit

Permalink
* Create new model movie and removed the index tat defined in meta.
Browse files Browse the repository at this point in the history
  • Loading branch information
harshalizode committed Dec 18, 2024
1 parent 6b1cc1f commit a350fc1
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions tests/indexes/test_indexes_drop_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,26 @@ class Meta:
autogenerate_index = True


class Movie(Document):
name: str = mongoz.String()
email: str = mongoz.Email(index=True, unique=True)
year: int = mongoz.Integer()
uuid: Optional[ObjectId] = mongoz.ObjectId(null=True)

class Meta:
registry = client
database = "test_db"
autogenerate_index = True


@pytest.fixture(scope="function", autouse=True)
async def prepare_database() -> AsyncGenerator:
collection = AnotherMovie.objects.using("another_test_db")._collection
await AnotherMovie.drop_indexes(force=True, collection=collection)
await AnotherMovie.objects.using("another_test_db").delete()
collection = Movie.objects.using("another_test_db")._collection
await Movie.drop_indexes(force=True, collection=collection)
await Movie.objects.using("another_test_db").delete()
yield
await AnotherMovie.drop_indexes(force=True)
await AnotherMovie.objects.using("another_test_db").delete()
await Movie.drop_indexes(force=True)
await Movie.objects.using("another_test_db").delete()


async def test_drops_indexes() -> None:
Expand Down Expand Up @@ -75,10 +87,10 @@ async def test_drops_indexes() -> None:


async def test_drops_indexes_different_db() -> None:
collection = AnotherMovie.objects.using("another_test_db")._collection
await AnotherMovie.create_indexes(collection=collection)
await AnotherMovie.objects.using("another_test_db").create(
collection = Movie.objects.using("another_test_db")._collection
await Movie.create_indexes(collection=collection)
await Movie.objects.using("another_test_db").create(
name="Mongoz", email="mongoz@mongoz.com", year=2023)
total_indexes = await AnotherMovie.list_indexes(collection=collection)
total_indexes = await Movie.list_indexes(collection=collection)

assert len(total_indexes) == 3
assert len(total_indexes) == 2

0 comments on commit a350fc1

Please sign in to comment.