Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 4 additions & 45 deletions commerce_coordinator/apps/commercetools/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ class MobileStandalonePriceChangeViewTests(APITestCase):

def setUp(self):
"""Set up test users"""
super().setUp()
User.objects.create_user(username=self.test_user_username, password=self.test_password)
User.objects.create_user(username=self.test_staff_username, password=self.test_password, is_staff=True)

def tearDown(self):
"""Clean up after each test"""
super().tearDown()
TieredCache.dangerous_clear_all_tiers()
self.client.logout()

Expand Down Expand Up @@ -139,56 +141,13 @@ class MobileCourseVariantAddViewTests(APITestCase):

def setUp(self):
"""Set up test users"""
super().setUp()
User.objects.create_user(username=self.test_user_username, password=self.test_password)
User.objects.create_user(username=self.test_staff_username, password=self.test_password, is_staff=True)

def tearDown(self):
"""Clean up after each test"""
TieredCache.dangerous_clear_all_tiers()
self.client.logout()

def test_view_returns_ok_for_admin_user(self):
"""Ensure a staff user gets 200 OK"""
self.client.login(username=self.test_staff_username, password=self.test_password)
response = self.client.post(self.url, data=EXAMPLE_COMMERCETOOLS_COURSE_VARIANT_ADD_MESSAGE, format='json')
self.assertEqual(response.status_code, 200)

def test_view_forbidden_for_non_admin_user(self):
"""Ensure a non-staff user gets 403 Forbidden"""
self.client.login(username=self.test_user_username, password=self.test_password)
response = self.client.post(self.url, data=EXAMPLE_COMMERCETOOLS_COURSE_VARIANT_ADD_MESSAGE, format='json')
self.assertEqual(response.status_code, 403)

def test_missing_payload_returns_400(self):
"""Check response for empty POST body"""
self.client.login(username=self.test_staff_username, password=self.test_password)
response = self.client.post(self.url, data={}, format='json')
# Assuming view should still return 200 (as per current logic). Change if behavior differs.
self.assertEqual(response.status_code, 200)

def test_unauthenticated_user_returns_401(self):
"""Ensure unauthenticated requests are denied with 401"""
response = self.client.post(self.url, data=EXAMPLE_COMMERCETOOLS_COURSE_VARIANT_ADD_MESSAGE, format='json')
self.assertEqual(response.status_code, 401)


class MobileCourseCreateViewTests(APITestCase):
"""Tests for MobileCourseVariantAddView"""
url = reverse('commercetools:mobile-course-variant-add')

client_class = APIClient

test_user_username = 'test_user'
test_staff_username = 'test_staff_user'
test_password = 'test_password'

def setUp(self):
"""Set up test users"""
User.objects.create_user(username=self.test_user_username, password=self.test_password)
User.objects.create_user(username=self.test_staff_username, password=self.test_password, is_staff=True)

def tearDown(self):
"""Clean up after each test"""
super().tearDown()
TieredCache.dangerous_clear_all_tiers()
self.client.logout()

Expand Down
2 changes: 0 additions & 2 deletions commerce_coordinator/apps/commercetools/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.urls import include, path

from commerce_coordinator.apps.commercetools.views import (
MobileCourseCreateView,
MobileCourseVariantAddView,
MobileStandalonePriceChangeView,
OrderFulfillView,
Expand All @@ -19,7 +18,6 @@
# EventBridge / CloudWatch Endpoints
path('fulfill', OrderFulfillView.as_view(), name='fulfill'),
path('mobile-course-variant-add', MobileCourseVariantAddView.as_view(), name='mobile-course-variant-add'),
path('mobile-course-create', MobileCourseCreateView.as_view(), name='mobile-course-create'),
path(
'mobile-standalone-price-change',
MobileStandalonePriceChangeView.as_view(),
Expand Down
23 changes: 0 additions & 23 deletions commerce_coordinator/apps/commercetools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,6 @@ def post(self, request):
return Response(status=status.HTTP_200_OK)


class MobileCourseCreateView(SingleInvocationAPIView):
"""Mobile Course Create View"""

authentication_classes = [JwtBearerAuthentication, SessionAuthentication]
permission_classes = [IsAdminUser]

def post(self, request):
"""Receive a message from commerce tools forwarded by AWS event bridge"""

tag = type(self).__name__

input_data = {
**request.data
}

logger.info(
f'[CT-{tag}] Message received from commercetools '
f'Course Create with details: {input_data}'
)

return Response(status=status.HTTP_200_OK)


class MobileCourseVariantAddView(SingleInvocationAPIView):
"""Mobile Course Variant Add View"""

Expand Down
Loading