create_company_user endpoint open for auth and anon users
This commit is contained in:
@@ -85,3 +85,4 @@ class YourOwnUserPermissions(permissions.BasePermission):
|
|||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -535,11 +535,58 @@ class CreateCompanyUserTest(APITestCase):
|
|||||||
# create user
|
# create user
|
||||||
self.email = "user@mail.com"
|
self.email = "user@mail.com"
|
||||||
self.password = ''.join(random.choices(string.ascii_uppercase, k = 10))
|
self.password = ''.join(random.choices(string.ascii_uppercase, k = 10))
|
||||||
self.user = self.factory(email=self.email, is_active=False)
|
self.user = self.factory(email=self.email, is_active=True)
|
||||||
self.user.set_password(self.password)
|
self.user.set_password(self.password)
|
||||||
self.user.save()
|
self.user.save()
|
||||||
|
|
||||||
def test_succesful_creation(self):
|
def test_auth_user_can_create(self):
|
||||||
|
# instances data
|
||||||
|
data = {
|
||||||
|
'user': {
|
||||||
|
'email': 'test@email.com',
|
||||||
|
'full_name': 'TEST NAME',
|
||||||
|
'password': 'VENTILADORES1234499.89',
|
||||||
|
},
|
||||||
|
'company': {
|
||||||
|
'cif': 'qwerewq',
|
||||||
|
'company_name': 'qwerewq',
|
||||||
|
'short_name': 'qwerewq',
|
||||||
|
'web_link': 'http://qwerewq.com',
|
||||||
|
'shop': True,
|
||||||
|
'shop_link': 'http://qwerewq.com',
|
||||||
|
'platform': 'PRESTASHOP',
|
||||||
|
'email': 'test@email.com',
|
||||||
|
'logo': None,
|
||||||
|
'city': None,
|
||||||
|
'address': 'qwer qewr 5',
|
||||||
|
'geo': {'longitude': 1.0, 'latitude': 1.0},
|
||||||
|
'phone': '1234',
|
||||||
|
'mobile': '4321',
|
||||||
|
'other_phone': '41423',
|
||||||
|
'description': 'dfgfdgdfg',
|
||||||
|
'shop_rss_feed': 'http://qwerewq.com',
|
||||||
|
'sale_terms': 'tewrnmfew f ewfrfew ewewew f',
|
||||||
|
'shipping_cost': '12.25',
|
||||||
|
'sync': False
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Authenticate
|
||||||
|
token = get_tokens_for_user(self.user)
|
||||||
|
self.client.credentials(HTTP_AUTHORIZATION=f"Bearer {token['access']}")
|
||||||
|
|
||||||
|
response = self.client.post(self.endpoint, data=data, format='json')
|
||||||
|
|
||||||
|
self.assertEquals(response.status_code, 201)
|
||||||
|
self.assertEquals(len(mail.outbox), 1)
|
||||||
|
# user exists and it's inactice
|
||||||
|
self.assertTrue(self.model.objects.get(email='test@email.com'))
|
||||||
|
self.assertFalse(self.model.objects.get(email='test@email.com').is_active)
|
||||||
|
self.assertTrue(Company.objects.get(cif='qwerewq'))
|
||||||
|
# assert verification email
|
||||||
|
self.assertTrue(len(mail.outbox) == 1)
|
||||||
|
|
||||||
|
def test_anon_user_can_create(self):
|
||||||
data = {
|
data = {
|
||||||
'user': {
|
'user': {
|
||||||
'email': 'test@email.com',
|
'email': 'test@email.com',
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class ChangeUserPasswordView(UpdateAPIView):
|
|||||||
|
|
||||||
|
|
||||||
@api_view(['POST',])
|
@api_view(['POST',])
|
||||||
@permission_classes([CustomUserPermissions,])
|
@permission_classes([AllowAny])
|
||||||
def create_company_user(request):
|
def create_company_user(request):
|
||||||
"""
|
"""
|
||||||
Create non-validated company and associated managing user
|
Create non-validated company and associated managing user
|
||||||
|
|||||||
Reference in New Issue
Block a user