Skip to content

Commit

Permalink
fix for sample data in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
collerek committed Dec 1, 2020
1 parent 61da7b4 commit 4c4e624
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tests/test_reverse_fk_queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ class Meta:
written_by: Optional[Writer] = ormar.ForeignKey(Writer)


@pytest.fixture(autouse=True)
@pytest.mark.asyncio
async def sample_data():
async def get_sample_data():
album = await Album(name="Malibu").save()
writer1 = await Writer.objects.create(name="John")
writer2 = await Writer.objects.create(name="Sue")
Expand Down Expand Up @@ -78,9 +76,10 @@ def create_test_database():


@pytest.mark.asyncio
async def test_quering_by_reverse_fk(sample_data):
async def test_quering_by_reverse_fk():
async with database:
async with database.transaction(force_rollback=True):
sample_data = await get_sample_data()
track1 = sample_data[1][0]
album = await Album.objects.first()

Expand Down Expand Up @@ -128,9 +127,10 @@ async def test_quering_by_reverse_fk(sample_data):


@pytest.mark.asyncio
async def test_getting(sample_data):
async def test_getting():
async with database:
async with database.transaction(force_rollback=True):
sample_data = await get_sample_data()
album = sample_data[0]
track1 = await album.tracks.fields(["album", "title", "position"]).get(
title="The Bird"
Expand Down Expand Up @@ -192,9 +192,10 @@ async def test_getting(sample_data):


@pytest.mark.asyncio
async def test_loading_related(sample_data):
async def test_loading_related():
async with database:
async with database.transaction(force_rollback=True):
sample_data = await get_sample_data()
album = sample_data[0]
tracks = await album.tracks.select_related("written_by").all()
assert len(tracks) == 3
Expand All @@ -210,9 +211,10 @@ async def test_loading_related(sample_data):


@pytest.mark.asyncio
async def test_adding_removing(sample_data):
async def test_adding_removing():
async with database:
async with database.transaction(force_rollback=True):
sample_data = await get_sample_data()
album = sample_data[0]
track_new = await Track(title="Rainbow", position=5, play_count=300).save()
await album.tracks.add(track_new)
Expand Down

0 comments on commit 4c4e624

Please sign in to comment.