Skip to content

Commit

Permalink
refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfermigier committed Apr 6, 2018
1 parent b1738e0 commit 376ed13
Show file tree
Hide file tree
Showing 8 changed files with 565 additions and 558 deletions.
34 changes: 1 addition & 33 deletions abilian/sbe/apps/communities/tests/test_community_noweb.py
Expand Up @@ -9,6 +9,7 @@
import sqlalchemy as sa
from abilian.core.entities import Entity
from abilian.core.models.subjects import User
from abilian.testing.util import login
from flask_login import login_user, logout_user
from mock import mock
from pytest import fixture
Expand Down Expand Up @@ -200,39 +201,6 @@ class CommunityContent(Entity):
##########################################################################


def login(user, remember=False, force=False):
"""Perform user login for `user`, so that code needing a logged-in user can
work.
This method can also be used as a context manager, so that logout is
performed automatically::
with login(user):
assert ...
.. seealso:: :meth:`logout`
"""
# self._login_tests_sanity_check()
success = login_user(user, remember=remember, force=force)
if not success:
raise ValueError(
'User is not active, cannot login; or use force=True',
)

class LoginContext(object):
def __enter__(self):
return None

def __exit__(self, type, value, traceback):
logout()

return LoginContext()


def logout():
logout_user()


def test_community_indexed(app, db):
index_service = app.services['indexing']
index_service.start()
Expand Down
14 changes: 7 additions & 7 deletions abilian/sbe/apps/communities/tests/test_community_web.py
Expand Up @@ -3,7 +3,7 @@
from __future__ import absolute_import, print_function, unicode_literals

from abilian.services.security import Admin
from abilian.testing.util import login
from abilian.testing.util import client_login
from flask import url_for
from flask_login import current_user
from pytest import mark
Expand All @@ -16,7 +16,7 @@ def test_index(app, client, community1):
security_service.start()

user = community1.test_user
with login(client, user):
with client_login(client, user):
response = client.get(url_for("communities.index"))
print(current_user)
assert response.status_code == 200
Expand All @@ -29,7 +29,7 @@ def test_community_home(app, client, community1, community2):
url = app.default_view.url_for(community1)

user1 = community1.test_user
with login(client, user1):
with client_login(client, user1):
response = client.get(url)
print(current_user)
assert response.status_code == 302
Expand All @@ -41,7 +41,7 @@ def test_community_home(app, client, community1, community2):
assert response.headers['Location'] == expected_url

user2 = community2.test_user
with login(client, user2):
with client_login(client, user2):
response = client.get(url)
print(current_user)
# assert response.headers['Location'] == ""
Expand All @@ -54,7 +54,7 @@ def test_new(app, client, community1):

user = community1.test_user

with login(client, user):
with client_login(client, user):
response = client.get(url_for("communities.new"))
assert response.status_code == 403

Expand All @@ -71,7 +71,7 @@ def test_community_settings(app, client, community1):
url = url_for('communities.settings', community_id=community1.slug)
user = community1.test_user

with login(client, user):
with client_login(client, user):
response = client.get(url)
assert response.status_code == 403

Expand Down Expand Up @@ -105,7 +105,7 @@ def test_members(app, client, db, community1, community2):
user1 = community1.test_user
user2 = community2.test_user

with login(client, user1):
with client_login(client, user1):
url = url_for(
"communities.members",
community_id=community1.slug,
Expand Down
1 change: 1 addition & 0 deletions abilian/sbe/apps/documents/tests/conftest.py
@@ -0,0 +1 @@
pytest_plugins = ['abilian.sbe.apps.communities.tests.fixtures']

0 comments on commit 376ed13

Please sign in to comment.