def seed_application_users(self): try: admin_role = Role( role_type=RoleTypes.ADMIN, description="Admin role for belisce dev agency platform") admin_role.commit() client_role = Role( role_type=RoleTypes.CLIENT, description="Client role for belisce dev agency platform") client_role.commit() # Define application users admin_user = User( # TODO load from config email="*****@*****.**", confirmed=True, confirmed_date=datetime.utcnow()) admin_user.set_password('password') admin_user.add_to_role(RoleTypes.ADMIN) admin_user.commit() except IntegrityError: log.info('Data is already present in database') pass
def make_user(self, data, **kwargs): if not data['password']: raise ValidationError('Please provide password') password = data['password'] del data['password'] user = User(**data) user.set_password(password) return user
def test_user_login_unconfirmed(app): # Given user = User(email='*****@*****.**', name='test user') user.add_to_role(RoleTypes.CLIENT) user.set_password('password') user.commit() login_info = {'email': '*****@*****.**', 'password': '******'} # When response = app.test_client().post('/api/auth/login', data=dumps(login_info), content_type='application/json') response_body = loads(response.data) # Then assert response.status_code == 400 assert response_body['error'] == 'user not confirmed'
def test_user_login_successful(app): # Given user = User(email='*****@*****.**', name='test user') user.add_to_role(RoleTypes.CLIENT) user.set_password('password') user.confirm_account() user.commit() login_info = {'email': '*****@*****.**', 'password': '******'} # When response = app.test_client().post('/api/auth/login', data=dumps(login_info), content_type='application/json') response_body = loads(response.data) # Then assert response.status_code == 200 assert 'access_token' in response_body assert 'refresh_token' in response_body