Пример #1
0
 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']
Пример #2
0
 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']
Пример #3
0
 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)
Пример #4
0
 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)
Пример #5
0
def admin_model_2_admin(admin_model: AdminModel):
    return Admin(
        **_extract_properties(admin_model, 'username', 'updated_at', 'sign',
                              'tip', ('password', 'encrypted_password')))
Пример #6
0
def set_repo_get(admin_repo, admin_data):
    admin_repo.get.return_value = Admin(**admin_data)
Пример #7
0
def test_get_tip(admin_repo, admin_data):
    admin_repo.get.return_value = Admin(**admin_data)
    assert get_tip() == admin_data['tip']
Пример #8
0
 def test_admin(self, app_context, set_repo_get, admin_data):
     user = Admin(**admin_data)
     assert not is_valid_anonymous(user)
Пример #9
0
 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)
Пример #10
0
 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)
Пример #11
0
 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