Skip to content
Snippets Groups Projects
Verified Commit af2bc95c authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

test: add fixtures for user with note permissios, owned show/timeslot and API client

parent 743dbeaf
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ from datetime import datetime, timedelta
import pytest
from rest_framework.test import APIClient
from django.contrib.auth.models import User
from django.contrib.auth.models import Permission, User
from django.core.files.uploadedfile import SimpleUploadedFile
from program.models import (
FundingCategory,
......@@ -27,6 +27,7 @@ from program.tests.factories import (
ShowFactory,
TimeslotFactory,
TypeFactory,
UserWithPermissionsFactory,
)
......@@ -97,6 +98,17 @@ def common_user2() -> User:
return CommonUserFactory()
@pytest.fixture
def user_with_note_perms() -> User:
"""User with add_note, change_note, delete_note permissions"""
permissions = Permission.objects.filter(
codename__in=["add_note", "change_note", "delete_note"]
)
return UserWithPermissionsFactory.create(user_permissions=permissions)
@pytest.fixture
def common_api_client1(api_client, common_user1) -> APIClient:
"""Authenticated common user 1 API client"""
......@@ -115,6 +127,15 @@ def common_api_client2(api_client, common_user2) -> APIClient:
api_client.force_authenticate()
@pytest.fixture
def api_client_note_perms(api_client, user_with_note_perms) -> APIClient:
"""Authenticated API client for user with add_note, change_note, delete_note permissions"""
api_client.force_authenticate(user_with_note_perms)
yield api_client
api_client.force_authenticate()
@pytest.fixture
def once_rrule() -> RRule:
return RRuleFactory(freq=0)
......@@ -126,8 +147,8 @@ def show() -> Show:
@pytest.fixture
def owned_show(common_user1):
show = ShowFactory()
def owned_show(common_user1, show) -> Show:
"""Show owned by a common user"""
show.owners.set([common_user1])
show.save()
......@@ -137,12 +158,27 @@ def owned_show(common_user1):
@pytest.fixture
def owned_show_once_timeslot(common_user1, show, once_schedule) -> TimeSlot:
"""Timeslot of a once schedule for a show owned by a common user"""
show.owners.set([common_user1])
show.save()
timeslot = TimeslotFactory(schedule=once_schedule)
return TimeslotFactory(schedule=once_schedule)
@pytest.fixture
def owned_show_once_timeslot_perms(user_with_note_perms, show, once_schedule) -> TimeSlot:
"""Timeslot of a once schedule for a show owned by a user with add_note permission"""
show.owners.set([user_with_note_perms])
show.save()
return TimeslotFactory(schedule=once_schedule)
return timeslot
@pytest.fixture
def show_once_timeslot(show, once_schedule) -> TimeSlot:
return TimeslotFactory(schedule=once_schedule)
@pytest.fixture
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment