def test_attach_n_approve(self): normal = fh.create_user() org = fh.create_organization(subdomain=u'one') self.flush() assert not org.get_user_connection(normal) assert not org.get_role(normal) #add twice to make sure that doesnt break orguser = org.attach_user(normal) self.flush() assert orguser.status == STATUS_PENDING assert orguser.role == APP_ROLE_READ assert org.get_role(normal) == None assert org.get_role(normal, status=STATUS_PENDING) == APP_ROLE_READ ou = org.approve_user(normal) assert ou self.flush() assert org.get_role(normal) == APP_ROLE_READ users = org.interested_users assert len(users) == 2 assert normal in users assert org.reject_user(normal) self.flush() assert org.get_role(normal) == None assert org.get_role(normal, status=STATUS_REJECTED) == APP_ROLE_READ users = org.interested_users assert len(users) == 1 assert normal not in users
def test_edit(self): rando = fh.create_user() u = fh.create_user() org = fh.create_organization(user=u) self.flush() eorg = api.organization.edit(u, u, org, name=u'omgwow', url=u'http://wowza.com', is_active=u'f') self.flush() assert eorg.id == org.id assert eorg.name == u'omgwow' assert eorg.is_active == True assert eorg.url == u'http://wowza.com' eorg = api.organization.edit(u, u, org, name=u'wowza!') self.flush() assert self.throws_exception(lambda: api.organization.edit( rando, rando, org, name='m')).code == FORBIDDEN assert self.throws_exception(lambda: api.user.edit( u, u, None, first_name='s')).code == NOT_FOUND
def test_get(self): org_owner = fh.create_user() rando_no_org = fh.create_user() owner = fh.create_user() rando = fh.create_user() read = fh.create_user() org = fh.create_organization(user=org_owner) project1 = fh.create_project(user=owner, organization=org, name=u"helloooo") project2 = fh.create_project(user=owner, organization=org, name=u"omgwow") project3 = fh.create_project(user=owner, organization=org, name=u"heyman") org.is_read_open = True for u in [owner, rando, read]: org.attach_user(u, status=STATUS_APPROVED) project1.attach_user(read) project2.attach_user(read) self.flush() assert len(api.project.get(owner, owner, org)) == 3 assert len(api.project.get(read, read, org)) == 3 assert len(api.project.get(rando_no_org, rando_no_org, org)) == 0 org.is_read_open = False self.flush() assert len(api.project.get(org_owner, org_owner, org)) == 3 assert len(api.project.get(owner, owner, org)) == 3 assert len(api.project.get(read, read, org)) == 2 assert len(api.project.get(rando, rando, org)) == 0 assert len(api.project.get(rando_no_org, rando_no_org, org)) == 0 self.flush()
def test_membership(self): org_owner = fh.create_user() owner = fh.create_user() rando = fh.create_user() read = fh.create_user() write = fh.create_user() org = fh.create_organization(user=org_owner) project = fh.create_project(user=owner, organization=org, name=u"helloooo") org.is_read_open = False for u in [owner, rando, read, write]: org.attach_user(u, status=STATUS_APPROVED) self.flush() """ def attach_user(real_user, user, project, u, role=users.APP_ROLE_READ) def remove_user(real_user, user, project, u) def set_user_role(real_user, user, project, u, role) def get_users(real_user, user, project, status=None) """ assert api.project.attach_user(org_owner, org_owner, project, write, projects.APP_ROLE_WRITE) self.flush() assert project.get_role(write) == projects.APP_ROLE_WRITE assert api.project.set_user_role(owner, owner, project, write, projects.APP_ROLE_ADMIN) self.flush() assert project.get_role(write) == projects.APP_ROLE_ADMIN pus = api.project.get_users(org_owner, org_owner, project) assert len(pus) == 2 assert api.project.remove_user(org_owner, org_owner, project, write) self.flush() assert project.get_role(write) == None # attach write again assert api.project.attach_user(org_owner, org_owner, project, write, projects.APP_ROLE_WRITE) self.flush() ex = self.throws_exception(lambda: api.project.attach_user(write, write, project, read, projects.APP_ROLE_READ)) assert "project" == ex.field ex = self.throws_exception(lambda: api.project.remove_user(read, read, project, write)) assert "project" == ex.field ex = self.throws_exception( lambda: api.project.set_user_role(read, read, project, write, projects.APP_ROLE_READ) ) assert "project" == ex.field ex = self.throws_exception(lambda: api.project.attach_user(owner, owner, project, None, projects.APP_ROLE_READ)) assert ex.code == NOT_FOUND ex = self.throws_exception(lambda: api.project.attach_user(owner, owner, None, read, projects.APP_ROLE_READ)) assert ex.code == NOT_FOUND ex = self.throws_exception(lambda: api.project.attach_user(owner, owner, project, read, None)) assert "role" in ex.error_dict
def test_is_unique(self): one = fh.create_organization(subdomain=u'one') two = fh.create_organization(subdomain=u'two') self.flush() assert self.throws_exception(lambda: api.organization.is_unique('one')) assert api.organization.is_unique('three')['is'] assert api.organization.is_unique('ab-c')['is'] err = self.throws_exception(lambda: api.organization.is_unique('_ []')) assert err.message err = self.throws_exception(lambda: api.organization.is_unique('-')) assert err.message err = self.throws_exception(lambda: api.organization.is_unique('-abc')) assert err.message err = self.throws_exception(lambda: api.organization.is_unique('abc-')) assert err.message
def test_project_add_change(self): u = fh.create_user() org = fh.create_organization(subdomain=u'one') orguser = org.attach_user(u) self.flush() project = p.Project(name=u"foobar", creator=u, description=u"description", organization=org) Session.add(project) filepath = file_path('ffcc00.gif') change = project.add_change(u, u"/main/project/arnold/foobar.gif", filepath, u"this is a new change") self.flush() act = activity.get_activities(organization=org) assert len(act) == 2 assert act[0].type == activity.NewFile.TYPE assert act[0].get_message() filepath = file_path('ffcc00.gif') change = project.add_change(u, u"/main/project/arnold/foobar.gif", filepath, u"this is a new change") self.flush() act = activity.get_activities(organization=org) assert len(act) == 3 assert act[0].type == activity.NewVersion.TYPE assert act[0].get_message() comment = change.add_comment(u, "This is a comment") self.flush() reply = change.add_comment(u, "This is a reply", in_reply_to=comment) self.flush() act = activity.get_activities(organization=org) assert len(act) == 5 assert act[0].type == activity.NewReply.TYPE assert act[0].get_message() assert act[1].type == activity.NewComment.TYPE assert act[1].get_message() comment.set_completion_status(u, STATUS_COMPLETED) self.flush() comment.set_completion_status(u, STATUS_OPEN) self.flush() act = activity.get_activities(organization=org) assert len(act) == 7 assert act[0].type == activity.CommentComplete.TYPE assert 'uncompleted' in act[0].get_message() assert act[1].type == activity.CommentComplete.TYPE assert 'completed' in act[1].get_message()
def test_index(self): u = fh.create_user() r = self.get('/', status=200) self.login(u) r = self.get('/', status=200) org = fh.create_organization(user=u) self.flush() #one org; redir to the org home page r = self.get('/', status=302) assert org.subdomain in r org2 = fh.create_organization(user=u) self.flush() #one org; redir to the org home page r = self.get('/', status=200) assert 'org-' + org.subdomain not in r assert 'org-' + org2.subdomain not in r
def test_index(self): u = fh.create_user() r = self.get('/', status=200) self.login(u) r = self.get('/', status=200) org = fh.create_organization(user=u) self.flush() #one org; redir to the org home page r = self.get('/', status=302) assert org.subdomain in r org2 = fh.create_organization(user=u) self.flush() #one org; redir to the org home page r = self.get('/', status=200) assert 'org-'+org.subdomain not in r assert 'org-'+org2.subdomain not in r
def test_create(self): """ Verifies that an ApiPrologueException is handled properly """ u = fh.create_user() org = fh.create_organization(user=u, subdomain='cats', name='CATS!') project = fh.create_project(user=u, organization=org, name=u"helloooo") change = project.add_change(u, u"/main/project/arnold/foobar.gif", file_path('ffcc00.gif'), u"this is a new change") self.flush() self.login(u) response = self.client_async(api_url('invite', 'create', entity=change.entity.eid), { 'email': '*****@*****.**', 'role': APP_ROLE_READ }) assert response.results.eid
def test_register(self): u = fh.create_user() org = fh.create_organization(user=u) self.flush() post_vars = {'default_timezone' : u'-8', 'password' : u'secret', 'confirm_password' : u'secret', 'email' : '*****@*****.**', 'name': 'Jim Bob'} r = self.client_async('/register', post_vars, sub_domain=org.subdomain) assert r.results.url == '/' r = self.get('/', sub_domain=org.subdomain, status=302) assert '/pending' in r user = api.user.get(username='******') orgu = org.get_user_connection(user) assert orgu assert orgu.status == STATUS_PENDING
def test_project_creation(self): normal = fh.create_user() u2 = fh.create_user() org = fh.create_organization(subdomain=u'one') orguser = org.attach_user(normal) orguser = org.attach_user(u2) self.flush() project = p.Project(name=u"foobar", creator=normal, description=u"description", organization=org) Session.add(project) self.flush() project2 = p.Project(name=u"meh", creator=u2, description=u"description", organization=org) Session.add(project2) self.flush() act = activity.get_activities(organization=org) assert len(act) == 2 assert act[0].type == activity.NewProject.TYPE assert act[0].project == project2 assert act[0].get_message() assert act[1].type == activity.NewProject.TYPE assert act[1].project == project assert act[1].get_message() act = activity.get_activities(project=project) assert len(act) == 1 assert act[0].type == activity.NewProject.TYPE assert act[0].project == project assert act[0].get_message() act = activity.get_activities(user=normal) assert len(act) == 1 assert act[0].type == activity.NewProject.TYPE assert act[0].project == project assert act[0].get_message()
def test_attach_approve(self): user = fh.create_user() creator = fh.create_user() admin = fh.create_user() rando = fh.create_user() org = fh.create_organization(user=admin) self.flush() assert org.get_role(admin) == APP_ROLE_ADMIN #anyone can attach themselves, but unless admin, they will be user:pending assert api.organization.attach_user(user, user, org, user, role=APP_ROLE_ADMIN, status=STATUS_APPROVED) self.flush() assert org.get_role(user, status=STATUS_PENDING) == APP_ROLE_READ #approve assert api.organization.attachment_approval(admin, admin, org, user) self.flush() assert org.get_role(user) == APP_ROLE_READ #approve creator automatically cause I'M AN ADMIN, BITCH assert api.organization.attach_user(admin, admin, org, creator, role=APP_ROLE_WRITE, status=STATUS_APPROVED) self.flush() assert org.get_role(creator) == APP_ROLE_WRITE #creator tries to add rando. CANNOT assert api.organization.attach_user(creator, creator, org, rando, role=APP_ROLE_ADMIN, status=STATUS_APPROVED) self.flush() assert org.get_role(rando, status=STATUS_PENDING) == APP_ROLE_READ #everyone tries to approve, and all fail but admin's attempt assert self.throws_exception(lambda: api.organization.attachment_approval(user, user, org, rando)).code == FORBIDDEN self.flush() assert not org.get_role(rando) assert self.throws_exception(lambda: api.organization.attachment_approval(creator, creator, org, rando)).code == FORBIDDEN self.flush() assert not org.get_role(rando) assert api.organization.attachment_approval(admin, admin, org, rando) self.flush() assert org.get_role(rando) == APP_ROLE_READ
def test_edit(self): rando = fh.create_user() u = fh.create_user() org = fh.create_organization(user=u) self.flush() eorg = api.organization.edit(u, u, org, name=u'omgwow', url=u'http://wowza.com', is_active=u'f') self.flush() assert eorg.id == org.id assert eorg.name == u'omgwow' assert eorg.is_active == True assert eorg.url == u'http://wowza.com' eorg = api.organization.edit(u, u, org, name=u'wowza!') self.flush() assert self.throws_exception(lambda: api.organization.edit(rando, rando, org, name='m')).code ==FORBIDDEN assert self.throws_exception(lambda: api.user.edit(u, u, None, first_name='s')).code == NOT_FOUND
def test_base(self): u = fh.create_user() rando = fh.create_user() org = fh.create_organization(user=u) self.flush() url = h.get_domain(org.subdomain) + '/' #TODO: when login working check for user not logged in redir to subdomain login... #resp = self.get(url) self.login(rando) resp = self.follow(self.get(url, status=302, sub_domain=org.subdomain)) assert 'org-'+org.subdomain not in resp self.login(u) resp = self.get(url, sub_domain=org.subdomain) assert 'org-'+org.subdomain in resp
def test_get_structure(self): import pprint pp = pprint.PrettyPrinter(indent=4) u = fh.create_user() user = fh.create_user() o = fh.create_organization(user=u) p1 = fh.create_project(organization=o, user=u) p2 = fh.create_project(organization=o, user=u) p3 = fh.create_project(organization=o, user=u) self.flush() filepath = file_path('ffcc00.gif') change = p1.add_change(u, u"/this/is/a/foobar.gif", filepath, u"this is a new change") self.flush() filepath = file_path('ffcc00.gif') change = p1.add_change(u, u"/this/is/a/foobar.gif", filepath, u"this is Another!") self.flush() filepath = file_path('ffcc00.gif') change = p1.add_change(user, u"/this/is/a/foobar.gif", filepath, u"And again") self.flush() filepath = file_path('ffcc00.gif') change = p3.add_change(user, u"/something.gif", filepath, u"New") self.flush() filepath = file_path('ffcc00.gif') change = p3.add_change(user, u"/something_else.gif", filepath, u"New") self.flush() self.login(u) response = self.client_async(api_url('organization', 'get_structure'), {'organization': o.eid}) assert response.results assert len(response.results.projects) == 3 projs = dict([(p.eid, p) for p in [p1, p2, p3]]) for p in response.results.projects: assert p.eid in projs
def test_create(self): """ Verifies that an ApiPrologueException is handled properly """ u = fh.create_user() org = fh.create_organization(user=u, subdomain='cats', name='CATS!') project = fh.create_project(user=u, organization=org, name=u"helloooo") change = project.add_change(u, u"/main/project/arnold/foobar.gif", file_path('ffcc00.gif'), u"this is a new change") self.flush() self.login(u) response = self.client_async( api_url('invite', 'create', entity=change.entity.eid), { 'email': '*****@*****.**', 'role': APP_ROLE_READ }) assert response.results.eid
def test_attach(self): normal = fh.create_user() reject = fh.create_user() org = fh.create_organization(subdomain=u'one') self.flush() assert not org.get_user_connection(normal) assert not org.get_role(normal) #add twice to make sure that doesnt break orguser = org.attach_user(normal) self.flush() orguser = org.attach_user(normal) self.flush() assert orguser.status == STATUS_PENDING assert orguser.role == APP_ROLE_READ #add as rejected orguser = org.attach_user(reject, status=STATUS_REJECTED, role=APP_ROLE_ADMIN) self.flush() assert orguser.status == STATUS_REJECTED assert orguser.role == APP_ROLE_ADMIN #filtering works? assert org.get_user_connection(normal).status == STATUS_PENDING assert not org.get_user_connection(normal, status=STATUS_APPROVED) #make sure user is rejected assert org.get_user_connection(reject).status == STATUS_REJECTED assert org.get_role(reject) == None assert org.get_role(reject, status=STATUS_REJECTED) == APP_ROLE_ADMIN #make sure removal works orguser = org.remove_user(reject) self.flush() assert not org.get_user_connection(reject)
def test_get_structure(self): import pprint pp = pprint.PrettyPrinter(indent=4) u = fh.create_user() user = fh.create_user() o = fh.create_organization(user=u) p1 = fh.create_project(organization=o, user=u) p2 = fh.create_project(organization=o, user=u) p3 = fh.create_project(organization=o, user=u) self.flush() filepath = file_path('ffcc00.gif') change = p1.add_change(u, u"/this/is/a/foobar.gif", filepath, u"this is a new change") self.flush() filepath = file_path('ffcc00.gif') change = p1.add_change(u, u"/this/is/a/foobar.gif", filepath, u"this is Another!") self.flush() filepath = file_path('ffcc00.gif') change = p1.add_change(user, u"/this/is/a/foobar.gif", filepath, u"And again") self.flush() filepath = file_path('ffcc00.gif') change = p3.add_change(user, u"/something.gif", filepath, u"New") self.flush() filepath = file_path('ffcc00.gif') change = p3.add_change(user, u"/something_else.gif", filepath, u"New") self.flush() self.login(u) response = self.client_async(api_url('organization', 'get_structure'), {'organization': o.eid}) assert response.results assert len(response.results.projects) == 3 projs = dict([(p.eid,p) for p in [p1,p2,p3]]) for p in response.results.projects: assert p.eid in projs
def test_project_creation(self): """ Test that you can create a project. """ normal = fh.create_user() org = fh.create_organization(subdomain=u'one') orguser = org.attach_user(normal) self.flush() project = p.Project(name=u"foobar", creator=normal, description=u"descripsion", organization=org) Session.add(project) self.flush() assert project.status == STATUS_APPROVED assert project.created_date assert project.name == u"foobar" assert project.description == u"descripsion" assert project.id assert project.eid assert project.organization == org self.flush()
def test_all(self): a = fh.create_user(is_admin=True) org_owner = fh.create_user() inviteme = fh.create_user(email="*****@*****.**") org = fh.create_organization(user=org_owner, subdomain='cats', name='CATS!') project = fh.create_project(user=org_owner, organization=org, name=u"helloooo") change = project.add_change(org_owner, u"/main/project/arnold/foobar.gif", file_path('ffcc00.gif'), u"this is a new change") file = change.entity self.flush() email = '*****@*****.**' #invite user not in the system to file invite = api.invite.create(a, org_owner, email, entity=file) #based on email only assert self.throws_exception(lambda: api.invite.create(a, org_owner, email, entity=file)).code == err.DUPLICATE assert invite.role == APP_ROLE_READ assert invite.invited_user == None assert invite.user == org_owner assert invite.invited_email == email assert invite.object == file emails = self.get_sent_mails() assert len(emails) == 1 assert api.invite.get(invite.eid) == invite #need to create a new user to accept u = fh.create_user(email=email, username=email) self.flush() api.invite.accept(u, u, invite.eid) self.flush() Session.refresh(invite) assert invite.invited_user == u assert invite.status == STATUS_APPROVED #invite user in system to proj invite = api.invite.create(org_owner, org_owner, email, project=project) assert invite.invited_user == u assert invite.invited_email == email assert invite.object == project emails = self.get_sent_mails() assert len(emails) == 2 api.invite.reject(u, u, invite.eid) self.flush() Session.refresh(invite) assert invite.invited_user == u assert invite.status == STATUS_REJECTED #invite user in system to org invite = api.invite.create(org_owner, org_owner, email, organization=org, role=APP_ROLE_WRITE) assert invite.object == org emails = self.get_sent_mails() assert len(emails) == 3 # FAIL #already invited assert self.throws_exception(lambda: api.invite.create(a, org_owner, email, entity=file)).code == err.DUPLICATE #no params ex = self.throws_exception(lambda: api.invite.create(org_owner, org_owner, email)).code assert ex# == err.NOT_FOUND #not in org at all assert self.throws_exception(lambda: api.invite.create(inviteme, inviteme, email, organization=org)).code == err.FORBIDDEN #in org as writer assert self.throws_exception(lambda: api.invite.create(u, u, email, entity=file)).code == err.FORBIDDEN #validation assert 'email' in self.throws_exception(lambda: api.invite.create(org_owner, org_owner, '', entity=file)).error_dict
def load(self): pw = u'password' admin = fh.create_user(username=u'admin', email=u'*****@*****.**', password=pw, role=u'admin') org = fh.create_organization(user=admin, name=u'Mudhut Software', subdomain='mudhut') jim = fh.create_user(username=u'*****@*****.**', email=u'*****@*****.**', password=pw) kyle = fh.create_user(username=u'*****@*****.**', email=u'*****@*****.**', password=pw) joe = fh.create_user(username=u'*****@*****.**', email=u'*****@*****.**', password=pw) jethro = fh.create_user(username=u'*****@*****.**', email=u'*****@*****.**', password=pw) creator = fh.create_user(username=u'*****@*****.**', email=u'*****@*****.**', password=pw) unapproved = fh.create_user(username=u'*****@*****.**', email=u'*****@*****.**', password=pw) self.flush() org.attach_user(creator, role=users.APP_ROLE_WRITE, status=STATUS_APPROVED) for u in [jim, kyle, joe, jethro]: org.attach_user(u, status=STATUS_APPROVED) org.attach_user(unapproved) self.flush() p1 = fh.create_project(user=creator, organization=org, name='Some Magic App') p2 = fh.create_project(user=admin, organization=org, name='Shopping Cart') p3 = fh.create_project(user=admin, organization=org, name='Desio') self.flush() p1.attach_user(jim, projects.APP_ROLE_READ); p1.attach_user(kyle, projects.APP_ROLE_WRITE); p1.attach_user(joe, projects.APP_ROLE_ADMIN); p2.attach_user(jim, projects.APP_ROLE_ADMIN); p2.attach_user(jethro, projects.APP_ROLE_WRITE); self.flush() filepath = file_path('headphones.eps') change1 = p1.add_change(joe, u"/headphones.eps", filepath, u"My headphones file") filepath = file_path('headphones.eps') change2 = p1.add_change(kyle, u"/headphones.eps", filepath, u"My headphones file again") self.flush() extract1 = change1.change_extracts[0] extract2 = change2.change_extracts[0] print change2.change_extracts _, c1 = api.file.add_comment(admin, admin, 'This is on version one', extract=extract1.id, x=40, y=50, width=50, height=50) _, c1 = api.file.add_comment(kyle, kyle, 'I dont know what to do about that', extract=extract1.id, x=100, y=75, width=50, height=50) # have admin, kyle, jim and joe _, c1 = api.file.add_comment(admin, admin, 'I think we should put blue in here.', extract=extract2.id, x=40, y=50, width=50, height=50) _, c2 = api.file.add_comment(kyle, kyle, 'I dont like this thing', extract=extract2.id, x=200, y=300, width=50, height=50) _, c3 = api.file.add_comment(jim, jim, 'Yeah, I see what you\'re doing there!', extract=extract2.id, x=250, y=100, width=40, height=50) _, c4 = api.file.add_comment(joe, joe, 'This comment has no coordinates', extract=extract2.id) self.flush() api.file.add_comment(kyle, kyle, 'Nah, I like red better.', change=change2.eid, in_reply_to=c1.eid) api.file.add_comment(joe, joe, 'How about green?', change=change2.eid, in_reply_to=c1.eid) api.file.add_comment(kyle, kyle, 'My reply i asdio oiajsdoi oasod asdj io oaisd io asod oasodj oajs doi jaiosdio aoisd oiasdio aiosd oijasdio aiodiojsddp aosd!', change=change2.eid, in_reply_to=c2.eid) api.file.add_comment(jim, jim, 'But it has a reply', change=change2.eid, in_reply_to=c4.eid) self.commit()
def load(self): pw = u'password' admin = fh.create_user(username=u'admin', email=u'*****@*****.**', password=pw, role=u'admin') org = fh.create_organization(user=admin, name=u'Mudhut Software', subdomain='mudhut') jim = fh.create_user(username=u'*****@*****.**', email=u'*****@*****.**', password=pw) kyle = fh.create_user(username=u'*****@*****.**', email=u'*****@*****.**', password=pw) joe = fh.create_user(username=u'*****@*****.**', email=u'*****@*****.**', password=pw) jethro = fh.create_user(username=u'*****@*****.**', email=u'*****@*****.**', password=pw) creator = fh.create_user(username=u'*****@*****.**', email=u'*****@*****.**', password=pw) unapproved = fh.create_user(username=u'*****@*****.**', email=u'*****@*****.**', password=pw) self.flush() org.attach_user(creator, role=users.APP_ROLE_WRITE, status=STATUS_APPROVED) for u in [jim, kyle, joe, jethro]: org.attach_user(u, status=STATUS_APPROVED) org.attach_user(unapproved) self.flush() p1 = fh.create_project(user=creator, organization=org, name='Some Magic App') p2 = fh.create_project(user=admin, organization=org, name='Shopping Cart') p3 = fh.create_project(user=admin, organization=org, name='Desio') self.flush() p1.attach_user(jim, projects.APP_ROLE_READ) p1.attach_user(kyle, projects.APP_ROLE_WRITE) p1.attach_user(joe, projects.APP_ROLE_ADMIN) p2.attach_user(jim, projects.APP_ROLE_ADMIN) p2.attach_user(jethro, projects.APP_ROLE_WRITE) self.flush() filepath = file_path('headphones.eps') change1 = p1.add_change(joe, u"/headphones.eps", filepath, u"My headphones file") filepath = file_path('headphones.eps') change2 = p1.add_change(kyle, u"/headphones.eps", filepath, u"My headphones file again") self.flush() extract1 = change1.change_extracts[0] extract2 = change2.change_extracts[0] print change2.change_extracts _, c1 = api.file.add_comment(admin, admin, 'This is on version one', extract=extract1.id, x=40, y=50, width=50, height=50) _, c1 = api.file.add_comment(kyle, kyle, 'I dont know what to do about that', extract=extract1.id, x=100, y=75, width=50, height=50) # have admin, kyle, jim and joe _, c1 = api.file.add_comment(admin, admin, 'I think we should put blue in here.', extract=extract2.id, x=40, y=50, width=50, height=50) _, c2 = api.file.add_comment(kyle, kyle, 'I dont like this thing', extract=extract2.id, x=200, y=300, width=50, height=50) _, c3 = api.file.add_comment(jim, jim, 'Yeah, I see what you\'re doing there!', extract=extract2.id, x=250, y=100, width=40, height=50) _, c4 = api.file.add_comment(joe, joe, 'This comment has no coordinates', extract=extract2.id) self.flush() api.file.add_comment(kyle, kyle, 'Nah, I like red better.', change=change2.eid, in_reply_to=c1.eid) api.file.add_comment(joe, joe, 'How about green?', change=change2.eid, in_reply_to=c1.eid) api.file.add_comment( kyle, kyle, 'My reply i asdio oiajsdoi oasod asdj io oaisd io asod oasodj oajs doi jaiosdio aoisd oiasdio aiosd oijasdio aiodiojsddp aosd!', change=change2.eid, in_reply_to=c2.eid) api.file.add_comment(jim, jim, 'But it has a reply', change=change2.eid, in_reply_to=c4.eid) self.commit()
def test_create(self): """ """ u = fh.create_user() org = fh.create_organization(user=u, subdomain='cats', name='CATS!') project = fh.create_project(user=u, organization=org, name=u"helloooo") change = project.add_change(u, u"/main/project/arnold/foobar.gif", file_path('ffcc00.gif'), u"this is a new change") self.flush() #invite to entity invite = api.invite.create(u, u, '*****@*****.**', entity=change.entity) self.flush() #the user doesnt exist, so we will show the register form response = self.get(url_for(controller='invite', action='index', id=invite.eid)) assert 'invite_' + invite.eid in response assert 'confirm_password' in response assert 'register_user' in response response = self.client_async(url_for(controller='invite', action='index', id=invite.eid), {}, assert_success=False, status=400) #try to accept with a different user self.login(u) response = self.client_async(url_for(controller='invite', action='index', id=invite.eid), { 'default_timezone': 0, 'password': '******', 'confirm_password': '******' }, assert_success=False, status=400) #shouldnt work Session.refresh(invite) assert invite.status == STATUS_PENDING assert not invite.invited_user_id self.logout() #accept the invite response = self.client_async(url_for(controller='invite', action='index', id=invite.eid), { 'default_timezone': 0, 'password': '******', 'confirm_password': '******' }) assert response.results.url Session.refresh(invite) assert invite.status == STATUS_APPROVED assert invite.invited_user self.logout() ## # invite him to the org ## invite = api.invite.create(u, u, '*****@*****.**', organization=org) self.flush() assert invite.status == STATUS_PENDING assert invite.invited_user_id response = self.get(url_for(controller='invite', action='index', id=invite.eid)) assert 'invite_' + invite.eid in response assert 'confirm_password' not in response assert 'login_user' in response #accept the invite response = self.client_async(url_for(controller='invite', action='index', id=invite.eid), { 'password': '******' }) assert response.results.url == 'http://%s.dev.local:5001/' % org.subdomain Session.refresh(invite) assert invite.status == STATUS_APPROVED assert invite.invited_user response = self.get(url_for(controller='organization/home', action='index'), sub_domain=org.subdomain, status=200) assert 'user-logged-in' in response
def test_membership_complex(self): org_owner = fh.create_user() owner = fh.create_user() u = [fh.create_user() for i in range(5)] org = fh.create_organization(user=org_owner) org.attach_user(owner, status=STATUS_APPROVED) project1 = fh.create_project(user=org_owner, organization=org, name=u"helloooo") project2 = fh.create_project(user=org_owner, organization=org, name=u"jioasdjio") change1 = project1.add_change(org_owner, u"/main/project/arnold/foobar.gif", file_path('ffcc00.gif'), u"this is a new change") change2 = project1.add_change(owner, u"/main/project/arnold/foobarblah.gif", file_path('ffcc00.gif'), u"this is a new change 2") change3 = project2.add_change(owner, u"/main/project/arnold/meh.gif", file_path('ffcc00.gif'), u"this is a new change 3") file1, file2, file3 = change1.entity, change2.entity, change3.entity # this means anyone in the org has minimum read privileges org.is_read_open = True self.flush() assert org.get_role(u[0]) == None assert project1.get_role(u[0]) == None assert file1.get_role(u[0]) == None # only org_owner and owner are in the org. Everyone else is an invite. # attach to project read project1.attach_user(u[0], APP_ROLE_READ) self.flush() assert org.get_role(u[0]) == None assert project1.get_role(u[0]) == APP_ROLE_READ assert project2.get_role(u[0]) == None assert file1.get_role(u[0]) == APP_ROLE_READ assert file2.get_role(u[0]) == APP_ROLE_READ assert file3.get_role(u[0]) == None # attach to file file1.attach_user(u[1], APP_ROLE_WRITE) self.flush() assert org.get_role(u[1]) == None assert project1.get_role(u[1]) == None assert project2.get_role(u[1]) == None assert file1.get_role(u[1]) == APP_ROLE_WRITE assert file2.get_role(u[1]) == None assert file3.get_role(u[1]) == None # attach to file write, project read project1.attach_user(u[2], APP_ROLE_READ) file1.attach_user(u[2], APP_ROLE_WRITE) self.flush() assert org.get_role(u[2]) == None assert project1.get_role(u[2]) == APP_ROLE_READ assert project2.get_role(u[2]) == None assert file1.get_role(u[2]) == APP_ROLE_WRITE assert file2.get_role(u[2]) == APP_ROLE_READ assert file3.get_role(u[2]) == None # attach to file read, project write, org admin org.attach_user(u[2], APP_ROLE_READ, status=STATUS_APPROVED) self.flush() assert org.get_role(u[2]) == APP_ROLE_READ assert project1.get_role(u[2]) == APP_ROLE_READ assert project2.get_role(u[2]) == APP_ROLE_READ assert file1.get_role(u[2]) == APP_ROLE_WRITE assert file2.get_role(u[2]) == APP_ROLE_READ assert file3.get_role(u[2]) == APP_ROLE_READ # attach to file read, project write project1.attach_user(u[3], APP_ROLE_WRITE) file1.attach_user(u[3], APP_ROLE_READ) self.flush() assert org.get_role(u[3]) == None assert project1.get_role(u[3]) == APP_ROLE_WRITE assert project2.get_role(u[3]) == None assert file1.get_role(u[3]) == APP_ROLE_WRITE assert file2.get_role(u[3]) == APP_ROLE_WRITE assert file3.get_role(u[3]) == None # attach to file read, project write, org admin org.attach_user(u[3], APP_ROLE_ADMIN, status=STATUS_APPROVED) self.flush() assert org.get_role(u[3]) == APP_ROLE_ADMIN assert project1.get_role(u[3]) == APP_ROLE_ADMIN assert project2.get_role(u[3]) == APP_ROLE_ADMIN assert file1.get_role(u[3]) == APP_ROLE_ADMIN assert file2.get_role(u[3]) == APP_ROLE_ADMIN assert file3.get_role(u[3]) == APP_ROLE_ADMIN
def test_membership(self): """ Test user connection BS, everyone is in the org """ org_owner = fh.create_user() owner = fh.create_user() rando_no_org = fh.create_user() rando = fh.create_user() read = fh.create_user() write = fh.create_user() admin = fh.create_user() org = fh.create_organization(user=org_owner) project = fh.create_project(user=owner, organization=org, name=u"helloooo") # this means anyone in the org has minimum read privileges org.is_read_open = True org.attach_user(rando_no_org, status=STATUS_PENDING) for u in [owner, rando, read, write, admin]: org.attach_user(u, status=STATUS_APPROVED) self.flush() """ Testing: def get_role(self, user, status=STATUS_APPROVED) def set_role(self, user, role) def get_user_connection(self, user, status=None) def get_user_connections(self, status=None) def attach_user(self, user, role=APP_ROLE_READ, status=STATUS_APPROVED) def remove_user(self, user) """ #this guy is not on the user, but he is an admin! assert project.get_role(org_owner) == APP_ROLE_ADMIN assert project.creator == owner assert project.get_role(owner) == APP_ROLE_ADMIN assert project.get_role(rando_no_org) == None assert project.get_role(rando) == APP_ROLE_READ #test attach pu = project.attach_user(write, APP_ROLE_WRITE) self.flush() assert pu.role == APP_ROLE_WRITE assert pu.project == project assert pu.user == write assert pu.status == STATUS_APPROVED assert project.get_role(write) == APP_ROLE_WRITE assert project.get_user_connection(write).role == APP_ROLE_WRITE #test set role project.attach_user(admin, APP_ROLE_WRITE) self.flush() assert project.set_role(admin, APP_ROLE_ADMIN) self.flush() assert project.get_role(admin) == APP_ROLE_ADMIN #test get project users pus = project.get_user_connections(status=STATUS_APPROVED) assert len(pus) == 3 #owner, write, admin #test is_read_open == false org.is_read_open = False self.flush() assert project.get_role(read) == None project.attach_user(read, APP_ROLE_READ) self.flush() assert project.get_role(read) == APP_ROLE_READ #test remove assert project.remove_user(read) self.flush() assert project.get_role(read) == None #test fail assert project.remove_user(rando) == False assert project.set_role(rando, APP_ROLE_READ) == False self.flush()
def test_attach_approve(self): user = fh.create_user() creator = fh.create_user() admin = fh.create_user() rando = fh.create_user() org = fh.create_organization(user=admin) self.flush() assert org.get_role(admin) == APP_ROLE_ADMIN #anyone can attach themselves, but unless admin, they will be user:pending assert api.organization.attach_user(user, user, org, user, role=APP_ROLE_ADMIN, status=STATUS_APPROVED) self.flush() assert org.get_role(user, status=STATUS_PENDING) == APP_ROLE_READ #approve assert api.organization.attachment_approval(admin, admin, org, user) self.flush() assert org.get_role(user) == APP_ROLE_READ #approve creator automatically cause I'M AN ADMIN, BITCH assert api.organization.attach_user(admin, admin, org, creator, role=APP_ROLE_WRITE, status=STATUS_APPROVED) self.flush() assert org.get_role(creator) == APP_ROLE_WRITE #creator tries to add rando. CANNOT assert api.organization.attach_user(creator, creator, org, rando, role=APP_ROLE_ADMIN, status=STATUS_APPROVED) self.flush() assert org.get_role(rando, status=STATUS_PENDING) == APP_ROLE_READ #everyone tries to approve, and all fail but admin's attempt assert self.throws_exception( lambda: api.organization.attachment_approval( user, user, org, rando)).code == FORBIDDEN self.flush() assert not org.get_role(rando) assert self.throws_exception( lambda: api.organization.attachment_approval( creator, creator, org, rando)).code == FORBIDDEN self.flush() assert not org.get_role(rando) assert api.organization.attachment_approval(admin, admin, org, rando) self.flush() assert org.get_role(rando) == APP_ROLE_READ
def test_all(self): a = fh.create_user(is_admin=True) org_owner = fh.create_user() inviteme = fh.create_user(email="*****@*****.**") org = fh.create_organization(user=org_owner, subdomain='cats', name='CATS!') project = fh.create_project(user=org_owner, organization=org, name=u"helloooo") change = project.add_change(org_owner, u"/main/project/arnold/foobar.gif", file_path('ffcc00.gif'), u"this is a new change") file = change.entity self.flush() email = '*****@*****.**' #invite user not in the system to file invite = api.invite.create(a, org_owner, email, entity=file) #based on email only assert self.throws_exception(lambda: api.invite.create( a, org_owner, email, entity=file)).code == err.DUPLICATE assert invite.role == APP_ROLE_READ assert invite.invited_user == None assert invite.user == org_owner assert invite.invited_email == email assert invite.object == file emails = self.get_sent_mails() assert len(emails) == 1 assert api.invite.get(invite.eid) == invite #need to create a new user to accept u = fh.create_user(email=email, username=email) self.flush() api.invite.accept(u, u, invite.eid) self.flush() Session.refresh(invite) assert invite.invited_user == u assert invite.status == STATUS_APPROVED #invite user in system to proj invite = api.invite.create(org_owner, org_owner, email, project=project) assert invite.invited_user == u assert invite.invited_email == email assert invite.object == project emails = self.get_sent_mails() assert len(emails) == 2 api.invite.reject(u, u, invite.eid) self.flush() Session.refresh(invite) assert invite.invited_user == u assert invite.status == STATUS_REJECTED #invite user in system to org invite = api.invite.create(org_owner, org_owner, email, organization=org, role=APP_ROLE_WRITE) assert invite.object == org emails = self.get_sent_mails() assert len(emails) == 3 # FAIL #already invited assert self.throws_exception(lambda: api.invite.create( a, org_owner, email, entity=file)).code == err.DUPLICATE #no params ex = self.throws_exception( lambda: api.invite.create(org_owner, org_owner, email)).code assert ex # == err.NOT_FOUND #not in org at all assert self.throws_exception(lambda: api.invite.create( inviteme, inviteme, email, organization=org)).code == err.FORBIDDEN #in org as writer assert self.throws_exception(lambda: api.invite.create( u, u, email, entity=file)).code == err.FORBIDDEN #validation assert 'email' in self.throws_exception(lambda: api.invite.create( org_owner, org_owner, '', entity=file)).error_dict
def test_create(self): u = fh.create_user() u2 = fh.create_user() o = {"subdomain": u"mycompany", "name": u"My company", "url": u"http://heyman.com"} org = api.organization.create(u, u, **o) self.flush() assert org.subdomain == o["subdomain"] assert org.name == o["name"] assert org.url == o["url"] assert org.is_active == True l = len(u.organization_users) assert l == 1 orgu = u.organization_users[0] assert orgu.user_id == u.id assert orgu.organization_id == org.id assert orgu.role == users.APP_ROLE_ADMIN assert orgu.status == STATUS_APPROVED p = {"name": u" Hella Project! ye$ah man_", "description": u"No description for HellaProject"} project = api.project.create(u, u, org, **p) self.flush() assert project.eid assert project.slug == "hella-project-ye-ah-man" assert project.status == STATUS_APPROVED assert project.name == p["name"] assert project.description == p["description"] assert project.created_date assert project.last_modified_date assert project.organization == org fetched_p = api.project.get(u, u, org) assert fetched_p == [project] fetched_p = api.project.get(u, u, org, project.eid) assert fetched_p == project fetched_p = api.project.get(u, u, org, project.slug) assert fetched_p == project o = {"subdomain": u"blahcomp", "name": u"My company", "url": u"http://asdasd.com"} org1 = fh.create_organization(user=u2, **o) _p = {"name": u"WOWZA", "description": u"No description for wow"} project = api.project.create(u2, u2, org1, **_p) projs = api.project.get(u, u, org1) assert not projs assert api.project.get(u2, u2, org1, u"wowza") assert self.throws_exception(lambda: api.project.get(u, u, org1, u"wowza")).code == FORBIDDEN assert self.throws_exception(lambda: api.project.get(u, u, org1, u"fakeeid")).code == NOT_FOUND assert self.throws_exception(lambda: api.project.get(u, u, org, u"fakeeid")).code == NOT_FOUND err = self.throws_exception(lambda: api.project.create(u, u, org, **p)) assert "A project with this name already exists. Please choose another" in err.msg p["name"] = u"Hella Project! ye$ah man" project = api.project.create(u, u, org, **p) self.flush() assert project.slug == "hella-project-ye-ah-man1"
def test_create(self): u = fh.create_user() u2 = fh.create_user() o = { 'subdomain': u'mycompany', 'name': u'My company', 'url': u'http://heyman.com', } org = api.organization.create(u, u, **o) self.flush() assert org.subdomain == o['subdomain'] assert org.name == o['name'] assert org.url == o['url'] assert org.is_active == True l = len(u.organization_users) assert l == 1 orgu = u.organization_users[0] assert orgu.user_id == u.id assert orgu.organization_id == org.id assert orgu.role == users.APP_ROLE_ADMIN assert orgu.status == STATUS_APPROVED p = { 'name': u' Hella Project! ye$ah man_', 'description': u'No description for HellaProject' } project = api.project.create(u, u, org, **p) self.flush() assert project.eid assert project.slug == 'hella-project-ye-ah-man' assert project.status == STATUS_APPROVED assert project.name == p['name'] assert project.description == p['description'] assert project.created_date assert project.last_modified_date assert project.organization == org fetched_p = api.project.get(u, u, org) assert fetched_p == [project] fetched_p = api.project.get(u, u, org, project.eid) assert fetched_p == project fetched_p = api.project.get(u, u, org, project.slug) assert fetched_p == project o = { 'subdomain': u'blahcomp', 'name': u'My company', 'url': u'http://asdasd.com', } org1 = fh.create_organization(user=u2, **o) _p = {'name': u'WOWZA', 'description': u'No description for wow'} project = api.project.create(u2, u2, org1, **_p) projs = api.project.get(u, u, org1) assert not projs assert api.project.get(u2, u2, org1, u'wowza') assert self.throws_exception( lambda: api.project.get(u, u, org1, u'wowza')).code == FORBIDDEN assert self.throws_exception( lambda: api.project.get(u, u, org1, u'fakeeid')).code == NOT_FOUND assert self.throws_exception( lambda: api.project.get(u, u, org, u'fakeeid')).code == NOT_FOUND err = self.throws_exception(lambda: api.project.create(u, u, org, **p)) assert 'A project with this name already exists. Please choose another' in err.msg p['name'] = u'Hella Project! ye$ah man' project = api.project.create(u, u, org, **p) self.flush() assert project.slug == 'hella-project-ye-ah-man1'
def test_membership(self): org_owner = fh.create_user() owner = fh.create_user() rando = fh.create_user() read = fh.create_user() write = fh.create_user() org = fh.create_organization(user=org_owner) project = fh.create_project(user=owner, organization=org, name=u"helloooo") org.is_read_open = False for u in [owner, rando, read, write]: org.attach_user(u, status=STATUS_APPROVED) self.flush() """ def attach_user(real_user, user, project, u, role=users.APP_ROLE_READ) def remove_user(real_user, user, project, u) def set_user_role(real_user, user, project, u, role) def get_users(real_user, user, project, status=None) """ assert api.project.attach_user(org_owner, org_owner, project, write, projects.APP_ROLE_WRITE) self.flush() assert project.get_role(write) == projects.APP_ROLE_WRITE assert api.project.set_user_role(owner, owner, project, write, projects.APP_ROLE_ADMIN) self.flush() assert project.get_role(write) == projects.APP_ROLE_ADMIN pus = api.project.get_users(org_owner, org_owner, project) assert len(pus) == 2 assert api.project.remove_user(org_owner, org_owner, project, write) self.flush() assert project.get_role(write) == None #attach write again assert api.project.attach_user(org_owner, org_owner, project, write, projects.APP_ROLE_WRITE) self.flush() ex = self.throws_exception(lambda: api.project.attach_user( write, write, project, read, projects.APP_ROLE_READ)) assert 'project' == ex.field ex = self.throws_exception( lambda: api.project.remove_user(read, read, project, write)) assert 'project' == ex.field ex = self.throws_exception(lambda: api.project.set_user_role( read, read, project, write, projects.APP_ROLE_READ)) assert 'project' == ex.field ex = self.throws_exception(lambda: api.project.attach_user( owner, owner, project, None, projects.APP_ROLE_READ)) assert ex.code == NOT_FOUND ex = self.throws_exception(lambda: api.project.attach_user( owner, owner, None, read, projects.APP_ROLE_READ)) assert ex.code == NOT_FOUND ex = self.throws_exception( lambda: api.project.attach_user(owner, owner, project, read, None)) assert 'role' in ex.error_dict
def test_membership(self): """ Test user connection BS, everyone is in the org """ org_owner = fh.create_user() owner = fh.create_user() rando_no_org = fh.create_user() rando = fh.create_user() read = fh.create_user() write = fh.create_user() admin = fh.create_user() org = fh.create_organization(user=org_owner) project = fh.create_project(user=owner, organization=org, name=u"helloooo") # this means anyone in the org has minimum read privileges org.is_read_open = True org.attach_user(rando_no_org, status=STATUS_PENDING) for u in [owner, rando, read, write, admin]: org.attach_user(u, status=STATUS_APPROVED) self.flush(); """ Testing: def get_role(self, user, status=STATUS_APPROVED) def set_role(self, user, role) def get_user_connection(self, user, status=None) def get_user_connections(self, status=None) def attach_user(self, user, role=APP_ROLE_READ, status=STATUS_APPROVED) def remove_user(self, user) """ #this guy is not on the user, but he is an admin! assert project.get_role(org_owner) == APP_ROLE_ADMIN assert project.creator == owner assert project.get_role(owner) == APP_ROLE_ADMIN assert project.get_role(rando_no_org) == None assert project.get_role(rando) == APP_ROLE_READ #test attach pu = project.attach_user(write, APP_ROLE_WRITE) self.flush() assert pu.role == APP_ROLE_WRITE assert pu.project == project assert pu.user == write assert pu.status == STATUS_APPROVED assert project.get_role(write) == APP_ROLE_WRITE assert project.get_user_connection(write).role == APP_ROLE_WRITE #test set role project.attach_user(admin, APP_ROLE_WRITE) self.flush() assert project.set_role(admin, APP_ROLE_ADMIN) self.flush() assert project.get_role(admin) == APP_ROLE_ADMIN #test get project users pus = project.get_user_connections(status=STATUS_APPROVED) assert len(pus) == 3 #owner, write, admin #test is_read_open == false org.is_read_open = False self.flush() assert project.get_role(read) == None project.attach_user(read, APP_ROLE_READ) self.flush() assert project.get_role(read) == APP_ROLE_READ #test remove assert project.remove_user(read) self.flush() assert project.get_role(read) == None #test fail assert project.remove_user(rando) == False assert project.set_role(rando, APP_ROLE_READ) == False self.flush()