def test_model_create_duplicate_company_should_return_duplicate_exception(self): guid = uuid.uuid4().hex from amspApp.amspUser.models import MyUser newUser = MyUser( username=guid + "test1", email=guid + "*****@*****.**", password=guid + "test1", ) newUser.save() # user created # creating new company from model from amspApp.CompaniesManagment.models import Company newCompany = Company( owner_user=newUser, name="Hellow" + guid ) newCompany.save() newCompany2 = Company( owner_user=newUser, name="Hellow" + guid ) from django.core.exceptions import ValidationError self.assertRaises(newCompany2.save(), ValidationError)
def test_serializer_create_company(self): guid = uuid.uuid4().hex from amspApp.amspUser.models import MyUser newUser = MyUser( username=guid + "test1", email=guid + "*****@*****.**", password=guid + "test1", ) newUser.save() # user created newCompany = { "name": "testName", "details": { "test1": "test2", "test11": "test3", "test12": "test4", "test13": "test5", "test14": "test6", }, "owner_user": newUser } from amspApp.CompaniesManagment.serializers.CompanySerializers import CompanySerializer newCompany = CompanySerializer(data=newCompany) if newCompany.is_valid(): newCompany = newCompany.create(newCompany.validated_data) self.assertTrue(newCompany)
def create_default_company_from_user(self, MyUser): newComp = { "owner_user":MyUser.id, "name":str(_("Default company of ")) + MyUser.username, "public_name":str(_("Default company of ")) + MyUser.username, "automatically_created":True } # "id", "name", "owner_user", "post_date", "automatically_created", "public_name" # a new company created with its dependecies # dependecies are : chart, secratrait, profile, company profile newCompany = CompanySerializer(data = newComp) newCompany.is_valid(raise_exception=True) newCompany = newCompany.create(newComp) # this company gets default MyUser.current_company = newCompany MyUser.save() # ChartSerializer().create_default_chart(newCompany) return newCompany
def test_model_create_company_should_return(self): guid = uuid.uuid4().hex from amspApp.amspUser.models import MyUser newUser = MyUser( username=guid + "test1", email=guid + "*****@*****.**", password=guid + "test1", ) newUser.save() # user created # creating new company from model from amspApp.CompaniesManagment.models import Company newCompany = Company( owner_user=newUser, name="Hellow" + guid ) newCompany.save() self.assertIsNotNone(newCompany.id)