testing purchase_email but getting 401 with AllowAny
This commit is contained in:
@@ -6,6 +6,7 @@ from urllib.parse import quote
|
||||
|
||||
from django.utils import timezone
|
||||
from django.test import TestCase
|
||||
from django.core import mail
|
||||
|
||||
from rest_framework.test import APITestCase
|
||||
from rest_framework import status
|
||||
@@ -1195,3 +1196,38 @@ class FindRelatedProductsTest(APITestCase):
|
||||
# assert result
|
||||
self.assertTrue(len(results) == len(expected_instances))
|
||||
|
||||
|
||||
class PurchaseEmailTest(APITestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""Tests setup
|
||||
"""
|
||||
self.endpoint = '/api/v1/purchase_email/'
|
||||
self.factory = ProductFactory
|
||||
self.model = Product
|
||||
# create user
|
||||
self.email = f"user@mail.com"
|
||||
self.password = ''.join(random.choices(string.ascii_uppercase, k = 10))
|
||||
self.user = CustomUserFactory(email=self.email, is_active=True)
|
||||
self.user.set_password(self.password)
|
||||
# self.user.role = 'SITE_ADMIN'
|
||||
self.user.save()
|
||||
|
||||
def test_anon_user_can_use(self):
|
||||
|
||||
company = CompanyFactory()
|
||||
product = ProductFactory(company=company)
|
||||
|
||||
data = {
|
||||
'email': self.email,
|
||||
'telephone': '123123123',
|
||||
'company': company.id,
|
||||
'product': product.id,
|
||||
'comment': '',
|
||||
}
|
||||
response = self.client.post(self.endpoint, json=data)
|
||||
import ipdb; ipdb.set_trace()
|
||||
# assertions
|
||||
self.assertEquals(response.status_code, 200)
|
||||
self.assertEquals(2, len(mail.outbox))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user