Skip to content

Commit

Permalink
Mock the Cloudinary calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel81 committed May 15, 2024
1 parent 0fdbc0c commit 20e7d2c
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions backend/store/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from django.urls import reverse
from django.test import override_settings
from unittest.mock import patch
from dotenv import load_dotenv
import os

load_dotenv()

class CategoryTestCase(APITestCase):
def setUp(self):
Expand All @@ -17,7 +20,15 @@ def setUp(self):
def test_category_str_method(self):
self.assertEqual(str(self.category), 'Electronics')

@override_settings(MEDIA_URL='http://testserver')
# @override_settings(MEDIA_URL='http://testserver')

@override_settings(
CLOUDINARY_STORAGE = {
'CLOUD_NAME': os.getenv('CLOUDINARY_NAME'),
'API_KEY': os.getenv('CLOUDINARY_API_KEY'),
'API_SECRET': os.getenv('CLOUDINARY_API_SECRET_KEY'),
}
)
class ProductTestCase(APITestCase):
def setUp(self):
self.category = Category.objects.create(name='Electronics')
Expand Down Expand Up @@ -55,9 +66,9 @@ def test_product_list_view_with_search(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['products'], ProductSerializer([self.product1], many=True).data)

@patch('cloudinary.utils.cloudinary_url')
def test_product_list_view_pagination(self, mock_cloudinary):
mock_cloudinary.return_value = ['http://dummy-url.com/image.png', 'options']
# @patch('cloudinary.utils.cloudinary_url')
def test_product_list_view_pagination(self):
# mock_cloudinary.return_value = ['http://dummy-url.com/image.png', 'options']

for i in range(10):
Product.objects.create(name=f'Product {i+3}', price=10)
Expand Down Expand Up @@ -246,9 +257,9 @@ def setUp(self):
def test_orderItem_str_method(self):
self.assertEqual(str(self.orderItem), 'Order Item')

@patch('cloudinary.utils.cloudinary_url')
def test_add_order_items(self, mock_cloudinary):
mock_cloudinary.return_value = ['http://dummy-url.com/image.png', 'options']
# @patch('cloudinary.utils.cloudinary_url')
def test_add_order_items(self):
# mock_cloudinary.return_value = ['http://dummy-url.com/image.png', 'options']
self.client.force_authenticate(user=self.user)
url = reverse("orders-add")

Expand Down

0 comments on commit 20e7d2c

Please sign in to comment.