def test_save_database_sent_email(self, email_send_mock): self.service(subject=fake.bothify(text='Title Number: ????-###'), body_text=fake.bothify(text='Body str ????-###'), body_html=fake.bothify(text='Body html ????-###'), user_id=self.user.id) # Emails sent, create account and send email utility self.assertEqual(2, Email.objects.count())
def test_service_with_invalid_user(self, email_users_create_mock): with self.assertRaises(ValidationError): self.service( user_id=fake.random_digit(), subject=fake.bothify(text='Subject Number: ????-###'), body_text=fake.bothify(text='Body text: ????-###'), body_html=fake.bothify(text='Body html: ????-###') )
def test_service_return_users(self, email_users_create_mock): for x in range(4): user_create(first_name=fake.first_name(), last_name=fake.last_name(), email=fake.email(), password=fake.password()) self.assertNotEqual(0, BaseUser.objects.count()) users = BaseUser.objects.filter(is_admin=False).filter(is_active=True) users_list = [x.id for x in users] self.service(subject=fake.bothify(text='Title Number: ????-###'), body_text=fake.bothify(text='Body str ????-###'), body_html=fake.bothify(text='Body html ????-###'), users=users_list) self.assertNotEqual(0, Email.objects.count())
def test_selector_return_appointment_assign(self, appointment_assign_by_id): # Create user user = user_create_superuser(first_name=fake.first_name(), last_name=fake.last_name(), password=fake.password(), email=fake.email()) # Create specialty specialty_create(title=fake.bothify(text='Specialty ????-###')) # Create appointment # Add day to date current_date = datetime.date.today() add_day = timedelta(days=1) date = current_date + add_day # Set hour-> range 8:00:00 - 16:00:00 time = datetime.time(10, 30, 00) appointment_assign_create(user=user.id, date=date, time=time) appointment_assign_id = AppointmentAssign.objects.first().id result = self.selector(id=appointment_assign_id) # Match appointment with database self.assertNotEqual([], len([result]))
def test_selector_return_specialty(self, specialty_by_id_mock): # Create specialty specialty_create(title=fake.bothify(text='Specialty ????-###')) self.assertEqual(1, Specialty.objects.count()) # Obtain specialty by id result = self.selector(id=Specialty.objects.first().id) self.assertNotEqual([], result)
def test_specialty_update(self, specialty_update_mock): specialty_create(title= fake.bothify(text='Specialty ????-###')) data = OrderedDict({ 'is_active': False }) self.service( specialty_id=Specialty.objects.first().id, data=data ) self.assertFalse(Specialty.objects.first().is_active)
def setUp(self): # Create a user self.user = user_create(first_name=fake.first_name(), last_name=fake.last_name(), password=fake.password(), email=fake.email()) specialty_create(title=fake.bothify(text='Specialty ????-###')) # Invoque service test self.service = appointment_remember
def test_specialty_not_create_capitalize_title(self, specialty_create_mock): # Create a specialty title = fake.bothify(text='Specialty ????-###') title_upper = title.upper() self.service(title=title) with self.assertRaises(ValidationError): # Specialty with a exists title capitalize self.service(title=title_upper) self.assertEqual(1, Specialty.objects.count())
def test_service_reject_true(self, appointment_delete_mock): # Create a specialty specialty_create( title=fake.bothify(text='Specialty ????-###')) # Create a appointment # Add day to date current_date = datetime.date.today() add_day = timedelta(days=1) date = current_date + add_day # Set hour -> range 8:00:00 - 16:00:00 time = datetime.time(10, 30, 00) # Appointment return dict appointment = appointment_create( specialty=Specialty.objects.first().id, user=self.user.id, date=date, time=time ) self.assertEqual(1, Appointment.objects.count()) self.service( user_id=self.user.id, appointment_id=appointment.get('id') ) self.assertEqual(1, Appointment.objects.count()) self.assertTrue(Appointment.objects.first().rejected) # Delete a appointment with rejected=True # Should raise ValidationError with self.assertRaises(ValidationError): self.service( user_id=self.user.id, appointment_id=appointment.get('id') )
def test_service_with_empty_users_list(self, emails_send_mock): with self.assertRaises(ValidationError): self.service(subject=fake.bothify(text='Title Number: ????-###'), body_text=fake.bothify(text='Body str ????-###'), body_html=fake.bothify(text='Body html ????-###'), users=[])
def test_service_invalid_data(self, specialty_update_mock): specialty_create(title= fake.bothify(text='Specialty ????-###')) with self.assertRaises(ValidationError): self.service(specialty_id=Specialty.objects.first().id, data={})
def test_when_has_already_been_reused(self, appointment_delete_mock): # Create user user = user_create( first_name=fake.first_name(), last_name=fake.last_name(), password=fake.password(), email=fake.email() ) # Create specialty specialty_create( title=fake.bothify(text='Specialty ????-###')) # Create appointment # Add day current_date = datetime.date.today() add_day = timedelta(days=1) date = current_date + add_day # Set hour -> range 8:00:00 - 16:00:00 time = datetime.time(10, 30, 00) # Appointment return dict() appointment_create( user=user.id, specialty=Specialty.objects.first().id, date=date, time=time ) self.assertEqual(1, Appointment.objects.count()) # Delete appoinment appointment_delete( user_id=user.id, appointment_id=Appointment.objects.first().id ) # Create a user per reused appointment new_user = user_create( first_name=fake.first_name(), last_name=fake.last_name(), password=fake.password(), email=fake.email() ) # Reused appointment with rejected=True self.service( user_id=new_user.id, appointment_id=Appointment.objects.first().id ) self.assertEqual(1, Appointment.objects.count()) # Reused appointment with rejected=False # Should raise ValidationError with self.assertRaises(ValidationError): self.service( user_id=new_user.id, appointment_id=Appointment.objects.first().id ) self.assertEqual(1, Appointment.objects.count())
def test_call_event(self, email_send_message_mock): self.service(subject=fake.bothify(text='Title Number: ????-###'), body_text=fake.bothify(text='Body str ????-###'), body_html=fake.bothify(text='Body html ????-###'), user_id=self.user.id) email_send_message_mock.assert_called()