Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nsyed22 committed Dec 19, 2024
1 parent ba5dd6d commit 09fa359
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions test/test_api/test_project_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
CategoryFactory, AuditlogFactory)
from test.helper.gig_helper import make_subadmin, make_admin
from test.test_api import TestAPI
from test.test_authorization import mock_current_user

project_repo = ProjectRepository(db)
task_repo = TaskRepository(db)
Expand Down Expand Up @@ -2585,10 +2586,12 @@ def test_clone_project_access(self):
self._setup_project(short_name, subadminowner)
headers = [('Authorization', subadminowner.api_key)]

# check 404 response when no project param
res = self.app.post('/api/project//clone', headers=headers)
error_msg = "A valid project must be used"
assert res.status_code == 404, error_msg
# check 401 response for anonymous user
mock_anonymous = mock_current_user()
with patch('pybossa.api.current_user', new=mock_anonymous):
res = self.app.post(f'/api/project/{short_name}/clone', headers=headers)
error_msg = "User must have access"
assert res.status_code == 401, res.status_code

# check 404 response when the project doesn't exist
res = self.app.post('/api/project/9999/clone', headers=headers)
Expand Down Expand Up @@ -2651,7 +2654,7 @@ def test_clone_project_edge_cases(self):


@with_context
def test_clone_project_success(self):
def test_clone_project(self):
"""Test API clone project success state"""
from pybossa.view.projects import data_access_levels

Expand All @@ -2671,7 +2674,27 @@ def test_clone_project_success(self):


@with_context
def test_clone_project_success_no_password(self):
def test_clone_project_by_id(self):
"""Test API clone project by id success state"""
from pybossa.view.projects import data_access_levels

[admin, subadminowner] = UserFactory.create_batch(2)
make_admin(admin)
make_subadmin(subadminowner)

short_name = "testproject"
self._setup_project(short_name, subadminowner)
headers = [('Authorization', subadminowner.api_key)]

data = {'short_name': 'newname', 'name': 'newname', 'password': 'Test123', 'input_data_class': 'L4 - public','output_data_class': 'L4 - public'}
with patch.dict(data_access_levels, self.patch_data_access_levels):
res = self.app.post(f'/api/project/40/clone', headers=headers, data=json.dumps(data), content_type='application/json')
data = json.loads(res.data)
assert res.status_code == 200, data


@with_context
def test_clone_project_no_password(self):
"""Test API clone project success state without project password"""
from pybossa.view.projects import data_access_levels

Expand Down

0 comments on commit 09fa359

Please sign in to comment.