def test_setter_properties(app): from aura.models import User user = User(username="******", password="******") user.username = "******" assert user.username == "other" user.password = "******" assert user.password_is("otherpass")
def test_username_failures(mock_user, name, app): mock_user.return_value = None from aura.models import User user = User() #Username empty, too short, too long with pytest.raises(UserDomainError): user.username = name
def test_password_failures(mock_user, pw, app): mock_user.return_value = None from aura.models import User user = User() #Password empty, too short with pytest.raises(UserDomainError): user.password = pw
def create_user(data): data = validate( Schema({ 'username': str, 'password': str }, ignore_extra_keys=True), data) user = User(username=data['username'], password=data['password']) db.session.add(user) db.session.commit() return user
def test_retrieve_user_invalid_credentials(app): from aura.models import User db = get_db() db.session.add(User(username='******', password='******')) db.session.commit() from aura.services import retrieve_user #Non existing user with pytest.raises(ServiceError): retrieve_user({'username':'******', 'password': '******'}) #Wrong password still raises Service error with pytest.raises(ServiceError): retrieve_user({'username':'******', 'password': '******'})
def test_retrieve_user(app): from aura.models import User from aura.services import retrieve_user with app.app_context(): db = get_db() db.session.add(User(username='******', password='******')) db.session.commit() user = User.query.filter_by(username='******').first() print("==") print(user) print("==") user = retrieve_user({'username':'******', 'password': '******'}) assert isinstance(user, User) assert user.username == 'admin' assert user.password_is('admin')
def test_password_encryption(app): from aura.models import User user = User("user", "pass") assert user.password != "pass"
def test_hybrid_properties(app): from aura.models import User user = User(username="******", password="******") assert user.username == user._username assert user.password == user._password
def test_constructor(app): from aura.models import User user = User(username="******", password="******") assert user.username == "user" assert user.password_is("pass")