class PersonModelTest(TestCase): def setUp(self): self.occupation = Occupation.objects.create( occupation='Web developer', ) self.person = Person( occupation=self.occupation, gender='M', treatment='sr', first_name='Regis', last_name='da Silva', cpf='11122233396', birthday='1979-05-31T00:00:00+00:00', email='*****@*****.**', blocked=False, ) def test_create(self): """ Person must have gender, first_name, last_name, cpf, birthday, email, phone, occupation, blocked """ self.person.save() self.assertEqual(1, self.person.pk) def test_has_created_at(self): 'Person must have automatic created_at.' self.person.save() self.assertIsInstance(self.person.created_at, datetime)
def setUp(self): self.occupation = Occupation.objects.create( occupation='Web developer', ) self.person = Person( occupation=self.occupation, gender='M', treatment='sr', first_name='Regis', last_name='da Silva', cpf='11122233396', birthday='1979-05-31T00:00:00+00:00', email='*****@*****.**', blocked=False, )
class PersonModelTest(TestCase): def setUp(self): self.obj = Person(**PERSON_DICT) self.obj.save() def test_create(self): self.assertTrue(Person.objects.exists()) def test_created_at(self): ''' Person must have an auto created_at attr. ''' self.assertIsInstance(self.obj.created, datetime) def test_str(self): self.assertEqual('Regis da Silva', str(self.obj)) def test_get_absolute_url(self): url = r('core:person_detail', self.obj.pk) self.assertEqual(url, self.obj.get_absolute_url())
def test_cpf_unique(self): 'CPF must be unique' p = Person( occupation=self.occupation, gender='M', treatment='sr', first_name='Regis', last_name='da Silva', cpf='11122233396', birthday='1979-05-31T00:00:00+00:00', email='*****@*****.**', blocked=False, ) self.assertRaises(IntegrityError, p.save)
def create_person(): aux_list = [] Person.objects.all().delete() for _ in range(100): name = f'{fake.first_name()} {fake.last_name()}' email = f'{slugify(name)}@email.com' phone = gen_phone() status = gen_status() obj = Person( name=name, email=email, phone=phone, status=status, ) aux_list.append(obj) Person.objects.bulk_create(aux_list)
'address': address(), 'complement': complement_, 'district': district(), 'city': city(), 'uf': state_uf(), 'cep': cep, 'blocked': blocked, } # Appending person_list for _ in range(REPEAT): person_list.append(person_data()) # Insert Persons obj = [Person(**person) for person in person_list] Person.objects.bulk_create(obj) # Appending phone_list persons = Person.objects.all() for person in persons: for _ in range(1, random.randint(2, 5)): phone_list.append({ 'person': person, 'phone': gen_phone(), 'phone_type': random.choice(PHONE_TYPE), }) # Insert Phones obj = [Phone(**phone) for phone in phone_list] Phone.objects.bulk_create(obj)
def setUp(self): self.obj = Person(**PERSON_DICT) self.obj.save()
City.objects.bulk_create(cities) districts = [] with open('fix/districts.csv') as csvfile: rows = csv.DictReader(csvfile) for row in rows: city = City.objects.get(name=row['city']) district = District(name=row['name'], city=city) districts.append(district) District.objects.bulk_create(districts) def gen_digits(max_length): return str(''.join(choice(string.digits) for i in range(max_length))) districts = District.objects.all() districts_list = [] for district in districts: for _ in range(7): name = names.get_full_name() email = slugify(name) + '@email.com' phone = gen_digits(11) data = dict(name=name, email=email, phone=phone, district=district) districts_list.append(Person(**data)) print(Person(**data)) Person.objects.bulk_create(districts_list)