Skip to content

Commit

Permalink
Added unit tests for asset admin status actions
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuastegmaier committed Feb 15, 2024
1 parent 418925c commit ca8c7c3
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion concordia/tests/test_admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@

from concordia.admin.actions import (
anonymize_action,
change_status_to_completed,
change_status_to_in_progress,
change_status_to_needs_review,
publish_action,
publish_item_action,
unpublish_action,
unpublish_item_action,
)
from concordia.models import Asset, Campaign, Item, Project
from concordia.models import Asset, Campaign, Item, Project, TranscriptionStatus
from concordia.tests.utils import (
CreateTestUsers,
create_asset,
create_campaign,
create_item,
create_project,
create_transcription,
)
from concordia.utils import get_anonymous_user


class MockModelAdmin:
Expand Down Expand Up @@ -121,6 +126,73 @@ def test_unpublish_item_action(self):
self.assertFalse(asset4.published)


class AssetAdminActionTest(TestCase, CreateTestUsers):
def setUp(self):
self.user = self.create_user("testuser")
self.reviewed_asset = create_asset()
self.unreviewed_asset = create_asset(
item=self.reviewed_asset.item, slug="test-asset-slug-2"
)
self.anon_user = get_anonymous_user()
self.request = HttpRequest()
self.request.user = self.user
create_transcription(asset=self.reviewed_asset, user=self.anon_user)
create_transcription(asset=self.unreviewed_asset, user=self.anon_user)
create_transcription(
asset=self.reviewed_asset,
user=self.anon_user,
reviewed_by=self.user,
)

def test_change_status_to_completed(self):
queryset = Asset.objects.filter(
pk__in=[self.reviewed_asset.pk, self.unreviewed_asset.pk]
)
change_status_to_completed(modeladmin, self.request, queryset)

reviewed_asset = Asset.objects.get(pk=self.reviewed_asset.pk)
unreviewed_asset = Asset.objects.get(pk=self.unreviewed_asset.pk)

self.assertEqual(
reviewed_asset.transcription_status, TranscriptionStatus.COMPLETED
)
self.assertEqual(
unreviewed_asset.transcription_status, TranscriptionStatus.COMPLETED
)

def test_change_status_to_needs_review(self):
queryset = Asset.objects.filter(
pk__in=[self.reviewed_asset.pk, self.unreviewed_asset.pk]
)
change_status_to_needs_review(modeladmin, self.request, queryset)

reviewed_asset = Asset.objects.get(pk=self.reviewed_asset.pk)
unreviewed_asset = Asset.objects.get(pk=self.unreviewed_asset.pk)

self.assertEqual(
reviewed_asset.transcription_status, TranscriptionStatus.SUBMITTED
)
self.assertEqual(
unreviewed_asset.transcription_status, TranscriptionStatus.SUBMITTED
)

def test_change_status_to_in_progress(self):
queryset = Asset.objects.filter(
pk__in=[self.reviewed_asset.pk, self.unreviewed_asset.pk]
)
change_status_to_in_progress(modeladmin, self.request, queryset)

reviewed_asset = Asset.objects.get(pk=self.reviewed_asset.pk)
unreviewed_asset = Asset.objects.get(pk=self.unreviewed_asset.pk)

self.assertEqual(
reviewed_asset.transcription_status, TranscriptionStatus.IN_PROGRESS
)
self.assertEqual(
unreviewed_asset.transcription_status, TranscriptionStatus.IN_PROGRESS
)


class AdminActionTest(TestCase):
def _setUp(self, published=True):
self.asset1 = create_asset(published=published)
Expand Down

0 comments on commit ca8c7c3

Please sign in to comment.