adding test of active and phantom login

This commit is contained in:
Cayo Puigdefabregas 2021-04-09 20:10:52 +02:00
parent eae5422d42
commit 4157aa8273

View file

@ -87,6 +87,39 @@ def test_login_success(client: Client, app: Devicehub):
assert user['inventories'][0]['id'] == 'test'
@pytest.mark.mvp
@pytest.mark.usefixtures(app_context.__name__)
def test_login_active_phantom(client: Client):
"""Tests successfully performing login.
This checks that:
- User is returned if is active and is not phantom.
"""
dbuser = User(email='foo@foo.com', password='foo')
dbuser1 = User(email='foo1@foo.com', password='foo', active=True, phantom=False)
dbuser2 = User(email='foo2@foo.com', password='foo', active=False, phantom=False)
dbuser3 = User(email='foo3@foo.com', password='foo', active=True, phantom=True)
dbuser4 = User(email='foo4@foo.com', password='foo', active=False, phantom=True)
db.session.add(dbuser)
db.session.add(dbuser1)
db.session.add(dbuser2)
db.session.add(dbuser3)
db.session.add(dbuser4)
db.session.commit()
db.session.flush()
assert dbuser.active
assert not dbuser.phantom
uri = '/users/login/'
client.post({'email': 'foo@foo.com', 'password': 'foo'}, uri=uri, status=200)
client.post({'email': 'foo1@foo.com', 'password': 'foo'}, uri=uri, status=200)
client.post({'email': 'foo2@foo.com', 'password': 'foo'}, uri=uri, status=401)
client.post({'email': 'foo3@foo.com', 'password': 'foo'}, uri=uri, status=401)
client.post({'email': 'foo4@foo.com', 'password': 'foo'}, uri=uri, status=401)
@pytest.mark.mvp
def test_login_failure(client: Client, app: Devicehub):
"""Tests performing wrong login."""