Skip to content

Commit

Permalink
Added unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kbecker42 committed Oct 2, 2024
1 parent bcc1901 commit b45beb7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
11 changes: 11 additions & 0 deletions test/test_cache/test_cache_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ def test_get_user_summary_user_exists(self):
assert type(zizou) is dict, type(zizou)
assert zizou != None, zizou

@with_context
def test_get_user_summary_user_exists_restrict(self):
"""Test CACHE USERS get_user_summary returns a dict with the user data
if the user exists restricted"""
UserFactory.create(name='zidane', restrict=True)
UserFactory.create(name='figo')

zizou = cached_users.get_user_summary('zidane')

assert zizou is None, zizou

@with_context
def test_public_get_user_summary_user_exists(self):
"""Test public CACHE USERS get_user_summary returns a dict with the user data
Expand Down
32 changes: 30 additions & 2 deletions test/test_view/test_project_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
# You should have received a copy of the GNU Affero General Public License
# along with PYBOSSA. If not, see <http://www.gnu.org/licenses/>.
import json
from test import with_context
from test import with_context, with_request_context
from test.helper.web import Helper
from test.factories import ProjectFactory, UserFactory
from unittest.mock import patch

from nose.tools import assert_raises
from pybossa.view.projects import sanitize_project_owner

class TestProjectContact(Helper):

Expand Down Expand Up @@ -178,3 +179,30 @@ def test_project_contact_no_auth(self):

# Verify status code from response.
assert res.status_code == 405

@with_request_context
@patch('pybossa.cache.users.public_get_user_summary')
def test_project_sanitize_project_no_owner_not_project_owner(self, public_get_user_summary):
"""Test Project sanitize_project_owner when no onwer returned and current user not owner."""
admin, owner, user = UserFactory.create_batch(3)
project = ProjectFactory.create(owner=owner, short_name='test-app', name='My New Project')

# Simulate no returned user.
public_get_user_summary.return_value = None

# Verify error is raised from owner_sanitized.pop().
with assert_raises(AttributeError) as ex:
sanitize_project_owner(project, owner, user)

@with_request_context
@patch('pybossa.cache.users.get_user_summary')
def test_project_sanitize_project_no_owner_is_project_owner(self, get_user_summary):
"""Test Project sanitize_project_owner when no onwer returned and current user is owner."""
admin, owner, user = UserFactory.create_batch(3)
project = ProjectFactory.create(owner=owner, short_name='test-app', name='My New Project')

get_user_summary.return_value = None

# Verify error is raised from owner_sanitized.pop().
with assert_raises(AttributeError) as ex:
sanitize_project_owner(project, owner, user)

0 comments on commit b45beb7

Please sign in to comment.