Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
n00rsy committed Oct 3, 2024
1 parent 8a07bc6 commit 8c71dfc
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions test/test_ownership_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import json
from unittest.mock import patch
from test.helper import web
from test import with_context
from test import db, Fixtures
from test.factories import ProjectFactory, UserFactory
from pybossa.core import user_repo
from pybossa.repositories import ProjectRepository


class TestOwnershipId(web.Helper):

def setup(self):
super(TestOwnershipId, self).setUp()
self.project_repo = ProjectRepository(db)

@with_context
def test_00_access_ownership_id(self):
"""Test admin and owner can access coowners page"""
self.register()
self.signin()
self.new_project()

res = self.app.get('/project/sampleapp/ownership_id', follow_redirects=True)
assert "ownership_id" in str(res.data), res.data

self.signout()
self.signin()


@with_context
def test_01_edit_ownership_id(self):
"""Test admin and owner can edit ownership id"""
self.register()
self.signin()

self.new_project()
payload = {'ownership_id': '12345'}
res = self.app.put('/project/sampleapp/ownership_id', data=json.dumps(payload))
assert "12345" in str(res.data), res.data

payload = {'ownership_id': ''}
res = self.app.put('/project/sampleapp/ownership_id', data=json.dumps(payload))
assert "12345" not in str(res.data), res.data

self.signout()
self.signin()


@with_context
def test_02_invalid_ownership_ids(self):
"""Test ownership id validation"""
self.register()
self.signin()

self.new_project()
payload = {'ownership_id': 'abcd123'}
res = self.app.put('/project/sampleapp/ownership_id', data=json.dumps(payload))
assert "Ownership ID must be numeric and less than 20 characters!" in str(res.data), res.data

payload = {'ownership_id': '123!!!abc'}
res = self.app.put('/project/sampleapp/ownership_id', data=json.dumps(payload))
assert "Ownership ID must be numeric and less than 20 characters!" in str(res.data), res.data

payload = {'ownership_id': '1111111111111111111111'}
res = self.app.put('/project/sampleapp/ownership_id', data=json.dumps(payload))
assert "Ownership ID must be numeric and less than 20 characters!" in str(res.data), res.data

self.signout()
self.signin()

0 comments on commit 8c71dfc

Please sign in to comment.