def post(self, request): serializer = self.InputSerializer(data=request.data) serializer.is_valid(raise_exception=True) user_create(**serializer.validated_data) return Response(status=status.HTTP_201_CREATED)
def test_user_not_match_id(self, user_update_profile_mock): user = user_create(first_name=fake.first_name(), last_name=fake.last_name(), password=fake.password(), email=fake.email()) user_new = user_create(first_name=fake.first_name(), last_name=fake.last_name(), password=fake.password(), email=fake.email()) with self.assertRaises(ValidationError): data = dict() data['first_name'] = fake.first_name() self.service(user_session=user.id, user_id=user_new.id, data=data)
def test_user_update_return_data_user_and_call_service( self, user_update_profile_email_send_mock): # Create a user test user = user_create(first_name=fake.first_name(), last_name=fake.last_name(), password=fake.password(), email=fake.email()) # Data with new data data = dict() data['first_name'] = fake.first_name() data['last_name'] = fake.last_name() user = self.service(user_session=user.id, user_id=user.id, data=data) # Match database with quantity 1 self.assertEqual(1, BaseUser.objects.count()) # Transform database data to array expect = [BaseUser.objects.first()] result = [user] # Match database and user updated self.assertEqual(expect, result) user_update_profile_email_send_mock.assert_called()
def test_already_appointment(self, appointment_create_mock): # 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) # Create a appointment appointment = self.service(user=self.user.id, specialty=Specialty.objects.first().id, time=time, date=date) # Match appointment with count database self.assertEqual(1, Appointment.objects.count()) # Create a new user new_user = user_create(first_name=fake.first_name(), last_name=fake.last_name(), password=fake.password(), email=fake.email()) # Invoque service with same time and data with self.assertRaises(ValidationError): self.service(user=new_user.id, specialty=Specialty.objects.first().id, time=time, date=date) # Match database with the same data (no saved appointment) self.assertEqual(1, Appointment.objects.count())
def test_selector_return_appointment(self, appointment_by_id): # 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 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 = appointment_create( specialty=Specialty.objects.first().id, user=user.id, date=date, time=time) appointment_id = Appointment.objects.first().id result = self.selector(id=appointment_id) # Match appointment with database self.assertNotEqual([], [result])
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_users_list(self, user_list_mock): for x in range(5): user_create( first_name=fake.first_name(), last_name=fake.last_name(), email=fake.email(), password=fake.password() ) # Prepare filter # Fields avaibles # first_name, last_name, email, is_active filters = OrderedDict() filters['is_active']= True result = self.selector(filters=filters) self.assertNotEqual([], list(result))
def setUp(self): self.password = fake.password() self.user = user_create( first_name=fake.first_name(), last_name=fake.last_name(), email=fake.email(), password=self.password ) self.service = user_change_password
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() ) self.service = appointment_delete
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_selector_return_user(self, user_by_email): user = user_create(first_name=fake.first_name(), last_name=fake.last_name(), password=fake.password(), email=fake.email()) self.assertEqual(1, BaseUser.objects.count()) result_selector = self.selector(email=user.email) # Transform data to array -> [] self.assertEqual([result_selector], [user])
def test_token_valid_with_vulnerable_password(self, user_password_reset_check_mock): user = user_create( first_name=fake.first_name(), last_name=fake.last_name(), password=fake.password(), email=fake.email() ) # Obtain token and user _, token = user_password_reset(email=user.email) # Token valid with invalid password password_vulnerable = fake.password(length=5, digits=False) with self.assertRaises(ValidationError): self.service(token=token, password=password_vulnerable)
def test_selector_return_user(self, user_all): # Create user user = user_create(first_name=fake.first_name(), last_name=fake.last_name(), password=fake.password(), email=fake.email()) self.assertEqual(1, BaseUser.objects.count()) result_selector = self.selector() result = list(result_selector) expect = [user] self.assertEqual(expect, result)
def test_token_is_none(self, user_password_reset_check_mock): password = fake.password() user = user_create( first_name=fake.first_name(), last_name=fake.last_name(), password=password, email=fake.email() ) # Obtain token and user user_password_reset(email=user.email) # Code no valid in check with self.assertRaises(ValidationError): self.service(token=None, password=password)
def test_valid_token_password_and_call_service(self, user_password_reset_check_email_send_mock): user = user_create( first_name=fake.first_name(), last_name=fake.last_name(), password=fake.password(), email=fake.email() ) # Obtain token and user _, token = user_password_reset(email=user.email) # Token valid with invalid password password_vulnerable = fake.password(length=5, digits=False) self.service(token=token, password=fake.password()) user_password_reset_check_email_send_mock.assert_called()
def test_service_return_token_user_and_call_event( self, user_password_reset_email_send_mock): user = user_create(first_name=fake.first_name(), last_name=fake.last_name(), password=fake.password(), email=fake.email()) user_profile = self.service(email=user.email) # Data to array list -> [<BaseUser: [email protected]>, # 'alcr3d-93e02ecaf523d3332a99462eb93989fb_NQ'] result = list(user_profile) # Match length result -> BaseUser -Token self.assertEqual(2, len(result)) user_password_reset_email_send_mock.assert_called()
def test_user_create_and_call_event(self, user_create_email_send_mock): user = user_create(first_name=fake.first_name(), last_name=fake.last_name(), password=None, email=fake.email()) user_create_email_send_mock.assert_called()
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 setUp(self): self.user = user_create(first_name=fake.first_name(), last_name=fake.last_name(), email=fake.email(), password=fake.password()) self.service = email_send