def test_multiple_admin_persistence(self, table, repo, admin1_data, admin2_data): repo.set(Admin(**admin1_data)) repo.set(Admin(**admin2_data)) admin = repo.get() assert admin.username == admin2_data['username'] assert admin.password != admin2_data['original_password']
def test_init_with_original_password(self): admin_data = { 'username': '******', 'updated_at': datetime.now() - timedelta(hours=1), 'sign': 'bullshit', 'tip': 'How\'s the code?', 'original_password': '******', 'auth_at': datetime.now() } admin = Admin(**admin_data) assert admin.username == admin_data['username'] assert admin.password != admin_data['original_password'] assert admin.updated_at == admin_data['updated_at'] assert admin.sign == admin_data['sign'] assert admin.tip == admin_data['tip'] assert admin.auth_at == admin_data['auth_at']
def test_model_to_entity(self, admin_data, admin_model_data): admin = Admin(**admin_data) admin_model = AdminModel(**admin_model_data) converted = admin_model_2_admin(admin_model) for key in ('username', 'password', 'sign', 'tip', 'updated_at'): assert getattr(converted, key) == getattr(admin, key)
def test_entity_to_model(self, admin_data, admin_model_data): admin = Admin(**admin_data) admin_model = AdminModel(**admin_model_data) converted = admin_2_admin_model(admin) for key in admin_model_data.keys(): assert getattr(converted, key) == getattr(admin_model, key)
def admin_model_2_admin(admin_model: AdminModel): return Admin( **_extract_properties(admin_model, 'username', 'updated_at', 'sign', 'tip', ('password', 'encrypted_password')))
def set_repo_get(admin_repo, admin_data): admin_repo.get.return_value = Admin(**admin_data)
def test_get_tip(admin_repo, admin_data): admin_repo.get.return_value = Admin(**admin_data) assert get_tip() == admin_data['tip']
def test_admin(self, app_context, set_repo_get, admin_data): user = Admin(**admin_data) assert not is_valid_anonymous(user)
def test_updated_admin(self, app_context, set_repo_get, admin_data): admin_data['updated_at'] = datetime.now() - timedelta(hours=12) user = Admin(**admin_data) assert not is_valid_admin(user)
def test_outdated_admin(self, app_context, set_repo_get, admin_data): admin_data['auth_at'] = datetime.now() - timedelta( days=current_app.config['AUTH_VALID_PERIOD_IN_DAY'] + 1) user = Admin(**admin_data) assert not is_valid_admin(user)
def test_admin_token(self, app_context, set_repo_get, admin_data): token = Admin(**admin_data).token() user = get_user_by_token(token) assert user.username == admin_data['username'] assert user.auth_at == admin_data['auth_at'] assert user.role == Admin.role