Пример #1
0
    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()
Пример #2
0
    def test_get_structure(self):
        """
        """
        user = fh.create_user()
        project = fh.create_project(user=user, name=u"kadkoasdok")
        self.flush()

        filepath = file_path("ffcc00.gif")
        change = project.add_change(user, u"/foobar.gif", filepath, u"this is a new change")
        filepath = file_path("ffcc00.gif")
        change = project.add_change(user, u"/stuff/things.gif", filepath, u"this is a new change")
        filepath = file_path("ffcc00.gif")
        change = project.add_change(user, u"/stuff/cats/kitten.gif", filepath, u"this is a new change")
        filepath = file_path("headphones.eps")
        change = project.add_change(user, u"/stuff/headphones.eps", filepath, u"Mah headphones")
        self.flush()

        s = api.project.get_structure(user, user, project, "/")
        assert len(s) == 2
        assert s[0][0].name == ""
        assert s[0][0].path == "/"

        file, ch = s[0][1][0]
        assert file.name == "foobar.gif"

        s = api.project.get_structure(user, user, project, "/stuff/")
        assert len(s) == 2

        s = api.project.get_structure(user, user, project, "/notthere/")
        assert s == None
Пример #3
0
    def test_get_directory_tree(self):
        """
        Test the generation of a directory tree.
        """
        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()
        self.login(user)

        filepath = file_path("ffcc00.gif")
        change = project.add_change(user, u"/this/is/a/foobar.gif", filepath, u"this is a new change")
        self.flush()

        filepath = file_path("ffcc00.gif")
        change = project.add_change(user, u"/this/is/a/foobar/too/foobar.gif", filepath, u"this is a new change")
        self.flush()

        r = self.client_async(api_url("project", "get_directories", project=project.eid), {})

        assert r.results.eid == project.eid
        tree = r.results.directories
        assert tree[0].full_path == u"/this"
        assert tree[0].children[0].full_path == u"/this/is"
        assert tree[0].children[0].children[0].full_path == u"/this/is/a"
        assert tree[0].children[0].children[0].children[0].full_path == u"/this/is/a/foobar"
        assert tree[0].children[0].children[0].children[0].children[0].full_path == u"/this/is/a/foobar/too"
Пример #4
0
    def test_get_structure(self):
        """
        """
        user = fh.create_user()
        project = fh.create_project(user=user, name=u"kadkoasdok")
        self.flush()

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/foobar.gif", filepath,
                                    u"this is a new change")
        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/stuff/things.gif", filepath,
                                    u"this is a new change")
        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/stuff/cats/kitten.gif", filepath,
                                    u"this is a new change")
        filepath = file_path('headphones.eps')
        change = project.add_change(user, u"/stuff/headphones.eps", filepath,
                                    u"Mah headphones")
        self.flush()

        s = api.project.get_structure(user, user, project, '/')
        assert len(s) == 2
        assert s[0][0].name == ''
        assert s[0][0].path == '/'

        file, ch = s[0][1][0]
        assert file.name == 'foobar.gif'

        s = api.project.get_structure(user, user, project, '/stuff/')
        assert len(s) == 2

        s = api.project.get_structure(user, user, project, '/notthere/')
        assert s == None
Пример #5
0
    def test_extracts(self):
        """
        Test basic changeset functionality
        """
        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()

        filepath = file_path('headphones.eps')
        change = project.add_change(user, u"/headphones.eps", filepath, u"this is a new change")
        self.flush()
        Session.refresh(change)
        
        extracts = change.change_extracts
        
        assert len(extracts) == 2
        foundthumb = False
        for e in extracts:
            if e.extract_type == image.EXTRACT_TYPE_THUMBNAIL:
                foundthumb = True
                assert e.url == change.thumbnail_url
                assert e.order_index == 0
            else:
                assert e.extract_type == image.EXTRACT_TYPE_FULL
                assert e.order_index == 0 or e.order_index == 1
            
            assert e.url
            
        assert foundthumb
        self.flush()
Пример #6
0
    def test_get_directory_tree(self):
        """
        Test the generation of a directory tree.
        """
        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()
        self.login(user)

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/this/is/a/foobar.gif", filepath,
                                    u"this is a new change")
        self.flush()

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/this/is/a/foobar/too/foobar.gif",
                                    filepath, u"this is a new change")
        self.flush()

        r = self.client_async(
            api_url('project', 'get_directories', project=project.eid), {})

        assert r.results.eid == project.eid
        tree = r.results.directories
        assert tree[0].full_path == u"/this"
        assert tree[0].children[0].full_path == u"/this/is"
        assert tree[0].children[0].children[0].full_path == u"/this/is/a"
        assert tree[0].children[0].children[0].children[
            0].full_path == u"/this/is/a/foobar"
        assert tree[0].children[0].children[0].children[0].children[
            0].full_path == u"/this/is/a/foobar/too"
Пример #7
0
    def test_comments(self):
        
        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()
        self.login(user)

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/foobar.gif", filepath, u"this is a new change")
        self.flush()
        
        extract = change.change_extracts[0]
        
        _, c1 = api.file.add_comment(user, user, 'My comment!', extract=extract.id, x=23, y=345, width=10, height=20)
        _, c2 = api.file.add_comment(user, user, 'My comment 2!', extract=extract.id)
        _, c3 = api.file.add_comment(user, user, 'My comment 3!', extract=extract.id, x=23, y=345, width=10, height=20)
        self.flush()
        
        _, r1 = api.file.add_comment(user, user, 'My reply2!', change=change.eid, in_reply_to=c1.eid)
        _, r2 = api.file.add_comment(user, user, 'My reply!', change=change.eid, in_reply_to=c2.eid)
        self.flush()
        
        r = self.client_async(api_url('file', 'get_comments', change=change.eid), {})
        
        r = r.results
        assert r.comments
        assert len(r.comments) == 3
        
        assert r.comments[0].eid == c1.eid
        assert len(r.comments[0].replies) == 1
        assert r.comments[0].replies[0].eid == r1.eid
Пример #8
0
    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
Пример #9
0
    def test_edit(self):
        
        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/wowza/foobar.gif", filepath, u"this is a new change")
        self.flush()
        filepath = file_path('ffcc00.gif')
        change2 = project.add_change(user, u"/wowza/kittens.gif", filepath, u"this is a new change")
        self.flush()
        
        r, change = api.file.get(user, user, project.eid, path=u"/wowza/foobar.gif")
        kittens, change2 = api.file.get(user, user, project.eid, path=u"/wowza/kittens.gif")
        directory = Session.query(projects.Entity).filter_by(name='wowza', project=project).first()
        
        assert directory
        assert r.name == 'foobar.gif'
        eid = r.eid
        
        r = api.file.edit(user, user, eid, name=u"somethingelse.gif")
        self.flush()
        
        assert r.name == 'somethingelse.gif'
        
        r, change = api.file.get(user, user, project.eid, path=u"/wowza/somethingelse.gif")
        
        assert r.name == 'somethingelse.gif'
        assert eid == r.eid
        
        #change again to same thing...
        r = api.file.edit(user, user, eid, name=u"somethingelse.gif")
        assert r
        
        r = self.throws_exception(lambda: api.file.edit(user, user, kittens.eid, name=u"somethingelse.gif"))
        assert 'name' in r.error_dict
        
        self.login(user)
        r = self.client_async(api_url('file', 'edit', id=kittens.eid), {'name': 'cats.gif'})
        assert r.results
        assert r.results.name == 'cats.gif'
        
        r = self.client_async(api_url('file', 'edit', id=kittens.eid), {'key': 'name', 'value': 'meow.gif'})
        assert r.results
        assert r.results.name == 'meow.gif'
        
        r = self.client_async(api_url('file', 'edit', id=directory.eid), {'key': 'name', 'value': 'omg'})
        assert r.results
        assert r.results.name == 'omg'
        
        r, change = api.file.get(user, user, project.eid, path=u"/omg/meow.gif")
        assert r.eid == kittens.eid
Пример #10
0
    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()
Пример #11
0
    def test_interested_users_project(self):
        """
        Test basic changes functionality
        """
        user = fh.create_user()
        user2 = fh.create_user()
        user3 = fh.create_user()
        user4 = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()
        
        project.organization.attach_user(user2)
        project.organization.attach_user(user3)
        project.organization.attach_user(user4)
        self.flush()
        
        #user created it
        users = project.interested_users
        assert user3 not in users
        assert user2 not in users
        assert user in users
        
        #attach user2
        project.attach_user(user2)
        self.flush()
        
        users = project.interested_users
        assert user3 not in users
        assert user2 in users
        assert user in users

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user3, u"/foobar.gif", filepath, u"this is a new change")
        self.flush()
        
        #user3 added a file
        
        users = project.interested_users
        assert user4 not in users
        assert user3 in users
        assert user2 in users
        assert user in users
        
        comment = change.add_comment(user4, u'foobar')
        self.flush()
        
        #user 4 commented, but that doesnt mean he is interested in the project
        users = project.interested_users
        assert user4 not in users
        assert user3 in users
        assert user2 in users
        assert user in users
Пример #12
0
 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
Пример #13
0
 def test_activity(self):
     
     user = fh.create_user()
     project = fh.create_project(user=user, name=u"helloooo")
     self.flush()
     self.login(user)
     
     time.sleep(1)
     
     filepath = file_path('ffcc00.gif')
     change = project.add_change(user, u"/foobar.gif", filepath, u"this is a new change")
     self.flush()
     
     time.sleep(1)
     
     filepath = file_path('cs5.png')
     changepng = project.add_change(user, u"/cs5.png", filepath, u"this is a new file")
     
     time.sleep(1)
     
     filepath = file_path('cs5.png')
     changepng = project.add_change(user, u"/cs5.png", filepath, u"this is a new change")
     
     time.sleep(1)
     
     filepath = file_path('cs5.png')
     changepng = project.add_change(user, u"/cs5.png", filepath, u"this is a new change")
     
     self.flush()
     
     all = self.client_async(api_url('activity', 'get', organization=project.organization.eid)).results
     four = self.client_async(api_url('activity', 'get', organization=project.organization.eid, limit='4')).results
     last = self.client_async(api_url('activity', 'get', organization=project.organization.eid, offset=all[2].created_date, limit='4')).results
     
     def p(r):
         print [res.type for res in r]
     
     #p(all)
     #p(four)
     #p(last)
     
     assert len(all) == 5 #['new_version', 'new_version', 'new_file', 'new_file', 'new_project']
     assert four == all[:4]
     assert last == all[3:]
     
     
     
     
Пример #14
0
    def test_get_files(self):
        """
        Test the generation of the project files structure.
        """
        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()
        self.login(user)

        r = self.client_async(api_url("project", "get_files", project=project.eid), {})
        assert r.results == {}

        filepath = file_path("ffcc00.gif")
        change = project.add_change(user, u"/this/is/a/foobar.gif", filepath, u"this is a new change")
        self.flush()

        filepath = file_path("ffcc00.gif")
        change = project.add_change(user, u"/this/is/a/foobar/too/foobar.gif", filepath, u"this is a new change")
        self.flush()

        r = self.client_async(api_url("project", "get_files", project=project.eid), {})

        assert len(r.results) == 2
        assert set(r.results.keys()) == set(["/this/is/a/foobar.gif", "/this/is/a/foobar/too/foobar.gif"])

        assert r.results.values()
        for value in r.results.values():
            assert set(value.keys()) == set(["path", "changes", "eid", "full_path", "name"])
            changes = value["changes"]
            assert len(changes) == 1
            assert set(changes[0].keys()) == set(
                [
                    "change_description",
                    "number_comments_open",
                    "creator",
                    "url",
                    "extracts",
                    "number_comments",
                    "version",
                    "change_eid",
                    "created_date",
                    "thumbnail_url",
                    "size",
                    "digest",
                    "file_eid",
                ]
            )
Пример #15
0
    def test_view(self):
        
        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/foobar.gif", filepath, u"this is a new change")
        self.flush()
        
        #no user logged in. Intentional
        r = self.get(url_for(controller='organization/file',
                             action='view',
                             project=project.eid,
                             file=change.entity.eid),
                     sub_domain=project.organization.subdomain)
        
        assert r
        assert 'file_' + project.eid + '_' + change.entity.eid in r
        
        #rando
        rando = fh.create_user()
        self.flush()
        self.login(rando)
        r = self.get(url_for(controller='organization/file',
                             action='view',
                             project=project.eid,
                             file=change.entity.eid),
                     sub_domain=project.organization.subdomain)
        
        assert r
        assert 'file_' + project.eid + '_' + change.entity.eid in r
        
        #real user redirects
        self.login(user)
        r = self.follow(self.get(url_for(controller='organization/file',
                             action='view',
                             project=project.eid,
                             file=change.entity.eid),
                     sub_domain=project.organization.subdomain, status=302),
                    sub_domain=project.organization.subdomain)
        
        assert r
        assert 'project_' + project.slug + '_' + change.entity.name in r
        
Пример #16
0
    def test_get(self):
        
        noob = fh.create_user()
        user = fh.create_user()
        bot = fh.create_user()
        bot.role = users.ROLE_ROBOT
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()
        self.login(bot)

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/foobar.gif", filepath, u"this is a new change")
        self.flush()
        
        filepath = file_path('cs5.png')
        changepng = project.add_change(user, u"/cs5.png", filepath, u"this is a new change")
        self.flush()
        
        r = self.client_async(api_url('change', 'get', id=changepng.eid), {})
        
        assert r.results
        assert r.results.change_eid == changepng.eid
        assert r.results.parse_type == image.PARSE_TYPE_FIREWORKS_CS5
        assert r.results.parse_status == image.PARSE_STATUS_PENDING
        
        r = self.client_async(api_url('change', 'get'), {'parse_type': image.PARSE_TYPE_FIREWORKS_CS5})
        assert len(r.results) == 1
        assert r.results[0].change_eid == changepng.eid
        
        r = self.client_async(api_url('change', 'get'), {'parse_status': image.PARSE_STATUS_PENDING})
        assert len(r.results) == 1
        assert r.results[0].change_eid == changepng.eid
        
        r = self.client_async(api_url('change', 'get'), {'parse_type': image.PARSE_TYPE_FIREWORKS_CS5+','+image.PARSE_TYPE_IMAGEMAGICK})
        assert len(r.results) == 2
        assert r.results[0].change_eid == change.eid
        assert r.results[1].change_eid == changepng.eid
        
        self.login(user)
        r = self.client_async(api_url('change', 'get', id=changepng.eid), {})
        assert r.results.change_eid == changepng.eid
        self.logout()
        
        self.login(noob)
        self.post(api_url('change', 'get', id=changepng.eid), {}, status=400)
Пример #17
0
    def test_get(self):
        
        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/foobar.gif", filepath, u"this is a new change")
        self.flush()
        
        r, change = api.file.get(user, user, project.eid, path=u"/foobar.gif")
        #print r.results
        
        assert r.name
        assert r.eid
        assert change.version
        assert r.path
        assert change.change_extracts
Пример #18
0
 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
Пример #19
0
    def test_get(self):

        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/foobar.gif", filepath,
                                    u"this is a new change")
        self.flush()

        r, change = api.file.get(user, user, project.eid, path=u"/foobar.gif")
        #print r.results

        assert r.name
        assert r.eid
        assert change.version
        assert r.path
        assert change.change_extracts
Пример #20
0
    def test_edit(self):
        p = fh.create_project()
        u = p.creator
        assert p
        assert p.name
        assert p.description

        fetched_p = api.project.edit(u, u, p.eid, name=u"my new name")
        assert fetched_p.id == p.id
        assert p.name == u"my new name"

        # same name as before!
        fetched_p = api.project.edit(u, u, p.eid, name=u"my new name")
        assert fetched_p.id == p.id
        assert p.name == u"my new name"

        fetched_p = api.project.edit(u, u, p.eid, description=u"new desc!!!")
        assert fetched_p.id == p.id
        assert p.description == u"new desc!!!"
Пример #21
0
    def test_simple_project_methods(self):
        """
        Test the Project interface
        """
        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        current = project.last_modified_date
        assert current
        project.update_activity()
        assert project.last_modified_date > current

        assert project.get_entities(u"/") == []
        assert project.get_file(u"/foobrar") == None
        assert project.get_changes(u"/blah") == []

        try:
            project.get_file(u"/")
        except AppException, e:
            assert e.msg.startswith("Only one complete path is supported")
Пример #22
0
    def test_get(self):
        
        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()
        self.login(user)

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/foobar.gif", filepath, u"this is a new change")
        self.flush()
        
        r = self.client_async(api_url('file', 'get', project=project.eid), {'path': u"/foobar.gif"})
        #print r.results
        
        assert r.results
        assert r.results.name
        assert r.results.eid
        assert r.results.version
        assert r.results.path
        assert r.results.extracts
Пример #23
0
    def test_get_files(self):
        """
        Test the generation of the project files structure.
        """
        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()
        self.login(user)

        r = self.client_async(
            api_url('project', 'get_files', project=project.eid), {})
        assert r.results == {}

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/this/is/a/foobar.gif", filepath,
                                    u"this is a new change")
        self.flush()

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/this/is/a/foobar/too/foobar.gif",
                                    filepath, u"this is a new change")
        self.flush()

        r = self.client_async(
            api_url('project', 'get_files', project=project.eid), {})

        assert len(r.results) == 2
        assert set(r.results.keys()) == set(
            ['/this/is/a/foobar.gif', '/this/is/a/foobar/too/foobar.gif'])

        assert r.results.values()
        for value in r.results.values():
            assert set(value.keys()) == set(
                ["path", "changes", "eid", "full_path", "name"])
            changes = value['changes']
            assert len(changes) == 1
            assert set(changes[0].keys()) == set([
                "change_description", "number_comments_open", "creator", "url",
                "extracts", "number_comments", "version", "change_eid",
                "created_date", "thumbnail_url", "size", "digest", 'file_eid'
            ])
Пример #24
0
    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
Пример #25
0
    def test_filetree_creation_and_navigation(self):
        """
        Test that on file creation the entire directory structure
        is created and can be browsed.
        """
        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/main/project/arnold/foobar.gif", filepath, u"this is a new change")
        self.flush()

        assert project.get_entities(u"/")[0].name == u"main"
        assert project.get_entities(u"/main/")[0].name == u"project"
        assert project.get_entities(u"/main/project/")[0].name == u"arnold"
        assert project.get_entities(u"/main/project/arnold/")[0].name == u"foobar.gif"
        assert project.get_entities(u"/main/project/arnold/foobar.gif").name == u"foobar.gif"
        entity = project.get_entities(u"/main/project/arnold/foobar.gif")
        entity.delete()
        self.flush()
        assert entity.status == STATUS_REMOVED
        assert entity.name == "%s-%s" % (entity.eid, entity.readable_name)
        assert project.get_entities(u"/main/project/arnold/foobar.gif") == None
        assert project.get_entities(u"/main/project/arnold/%s" % (entity.name), only_status=None).readable_name == u"foobar.gif"

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/foobar2.gif", filepath, u"this is a new change")
        self.flush()

        for entity in project.get_entities(u'/'):
            assert entity.name # there can be no root.
            assert entity.path == u"/"

        assert project.get_entities(u'/')[0].name == 'foobar2.gif'
        assert project.get_entities(u'/', order_by_field='name')[0].name == 'main'
        assert project.get_entities(u'/', order_by_field='name', desc=False)[0].name == 'foobar2.gif'

        assert project.last_modified > project.last_modified_date
        self.flush()
Пример #26
0
 def test_edit(self):
     
     user = fh.create_user()
     bot = fh.create_user()
     bot.role = users.ROLE_ROBOT
     project = fh.create_project(user=user, name=u"helloooo")
     self.flush()
     self.login(bot)
     
     filepath = file_path('cs5.png')
     changepng = project.add_change(user, u"/cs5.png", filepath, u"this is a new change")
     self.flush()
     
     assert changepng.parse_status == image.PARSE_STATUS_PENDING
     
     r = self.client_async(api_url('change', 'edit', id=changepng.eid), {'parse_status':image.PARSE_STATUS_IN_PROGRESS})
     
     assert r.results.parse_status == image.PARSE_STATUS_IN_PROGRESS
     
     Session.refresh(changepng)
     
     assert changepng.parse_status == image.PARSE_STATUS_IN_PROGRESS
Пример #27
0
 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
     
     
     
Пример #28
0
 def test_comments(self):
     
     rando = fh.create_user()
     reader = fh.create_user()
     user = fh.create_user()
     guy_in_project = fh.create_user()
     project = fh.create_project(user=user, name=u"helloooo")
     self.flush()
     
     project.organization.attach_user(guy_in_project, status=STATUS_APPROVED)
     project.organization.attach_user(reader, status=STATUS_APPROVED)
     assert api.project.attach_user(user, user, project, guy_in_project, projects.APP_ROLE_WRITE)
     assert api.project.attach_user(user, user, project, reader, projects.APP_ROLE_READ)
     
     filepath = file_path('ffcc00.gif')
     change = project.add_change(user, u"/foobar.gif", filepath, u"this is a new change")
     self.flush()
     
     extract = change.change_extracts[0]
     
     _extract, comment = api.file.add_comment(user, user, 'My comment!', extract=extract.id, x=23, y=345, width=10, height=20)
     self.flush()
     
     assert _extract == extract
     assert comment.change == change
     assert comment.change_extract == extract
     
     assert comment.body == u'My comment!'
     assert comment.eid
     assert comment.x == 23
     assert comment.y == 345
     assert comment.width == 10
     assert comment.height == 20
     assert comment.completion_status.status == STATUS_OPEN
     
     #make sure comment completion statuses work
     api.file.set_comment_completion_status(user, user, comment, status=STATUS_COMPLETED)
     self.flush()
     assert comment.completion_status.status == STATUS_COMPLETED
     
     api.file.set_comment_completion_status(user, guy_in_project, comment, status=STATUS_OPEN)
     self.flush()
     assert comment.completion_status.status == STATUS_OPEN
     
     ex = self.throws_exception(lambda: api.file.set_comment_completion_status(user, user, None, status=STATUS_COMPLETED))
     assert ex.code == NOT_FOUND
     ex = self.throws_exception(lambda: api.file.set_comment_completion_status(user, user, comment))
     assert 'status' in ex.error_dict
     ex = self.throws_exception(lambda: api.file.set_comment_completion_status(reader, reader, comment, status=STATUS_COMPLETED))
     assert ex.code == FORBIDDEN
     
     _, reply = api.file.add_comment(user, user, 'My reply!', change=change.eid, in_reply_to=comment.eid)
     self.flush()
     
     assert reply
     assert reply.in_reply_to == comment
     assert reply.eid
     
     assert comment.replies
     assert len(comment.replies) == 1
     
     _change, comments = api.file.get_comments(user, user, change=change.eid)
     
     assert change == _change
     assert len(comments) == 2
     assert comments[0] == comment
     assert comments[1] == reply
     assert comments[0].replies[0] == reply
     
     _, guyscomment = api.file.add_comment(guy_in_project, guy_in_project, 'My comment!', extract=extract.id, x=23, y=345, width=10, height=20)
     _, guyscomment1 = api.file.add_comment(guy_in_project, guy_in_project, 'My comment!', extract=extract.id, x=23, y=345, width=10, height=20)
     self.flush()
     
     ex = self.throws_exception(lambda: api.file.remove_comment(guy_in_project, guy_in_project, comment.eid)).code == FORBIDDEN
     ex = self.throws_exception(lambda: api.file.remove_comment(rando, rando, guyscomment.eid)).code == FORBIDDEN
     
     _, comments = api.file.get_comments(user, user, change=change.eid)
     assert len(comments) == 4
     
     assert api.file.remove_comment(user, user, guyscomment.eid)
     assert api.file.remove_comment(guy_in_project, guy_in_project, guyscomment1.eid)
     self.flush()
     
     _, comments = api.file.get_comments(user, user, change=change.eid)
     assert len(comments) == 2
     
     ex = self.throws_exception(lambda: api.file.get_comments(user, user))
     assert ex.exceptions[0].code == NOT_FOUND
Пример #29
0
    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
Пример #30
0
    def test_invite(self):
        t = (AppException,)
        
        uorg = fh.create_user()
        uproj = fh.create_user()
        ufile = fh.create_user()
        
        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()
        org = project.organization

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/main/project/arnold/foobar.gif", filepath, u"this is a new change")
        entity = change.entity
        
        def fu(email):
            return Session.query(users.User).filter_by(email=email).first()
        
        #invite non-user to org
        email = '*****@*****.**'
        inv = users.Invite.create(user, email, org, users.APP_ROLE_WRITE)
        self.flush()
        
        act = activity.get_activities()
        assert act[0].type == activity.InviteEvent.TYPE
        assert act[0].get_message()
        
        assert inv.invited_email == email
        assert inv.invited_user == None
        assert inv.user == user
        assert inv.role == users.APP_ROLE_WRITE
        assert inv.type == users.INVITE_TYPE_ORGANIZATION
        assert inv.object_id == org.id
        assert inv.status == STATUS_PENDING
        
        assert inv.object == org
        
        assert self.throws_exception(lambda: inv.accept(), types=t).code == err.INVALID #no user
        assert self.throws_exception(lambda: inv.accept(uorg), types=t).code == err.INVALID #email no match
        
        iu = fh.create_user(username=email, email=email)
        self.flush()
        
        assert org.get_role(iu) == None
        
        inv.accept(iu)
        self.flush()
        Session.refresh(inv)
        
        act = activity.get_activities()
        assert act[0].type == activity.InviteAccept.TYPE
        assert org.name in act[0].get_message()
        
        assert inv.invited_email == email
        assert inv.invited_user == iu
        assert inv.user == user
        assert inv.type == users.INVITE_TYPE_ORGANIZATION
        assert inv.object_id == org.id
        assert inv.status == STATUS_APPROVED
        
        assert inv.object == org
        assert org.get_role(iu) == users.APP_ROLE_WRITE
        
        assert self.throws_exception(lambda: users.Invite.create(user, email, org, users.APP_ROLE_WRITE), types=t).code == err.DUPLICATE
        
        #invite non-user to project
        email = '*****@*****.**'
        inv = users.Invite.create(user, email, project, users.APP_ROLE_ADMIN)
        self.flush()
        
        act = activity.get_activities()
        assert act[0].type == activity.InviteEvent.TYPE
        assert project.name in act[0].get_message()
        
        assert inv.role == users.APP_ROLE_ADMIN
        assert inv.type == users.INVITE_TYPE_PROJECT
        assert inv.object_id == project.id
        assert inv.object == project
        
        iu = fh.create_user(username=email, email=email)
        self.flush()
        
        assert project.get_role(iu) == None
        
        inv.accept(iu)
        self.flush()
        Session.refresh(inv)
        
        act = activity.get_activities()
        assert act[0].type == activity.InviteAccept.TYPE
        assert project.name in act[0].get_message()
        
        assert inv.invited_user == iu
        assert project.get_role(iu) == users.APP_ROLE_ADMIN
        assert org.get_role(iu) == None
        
        #invite non-user to entity
        email = '*****@*****.**'
        inv = users.Invite.create(user, email, entity, users.APP_ROLE_READ)
        self.flush()
        
        act = activity.get_activities()
        assert act[0].type == activity.InviteEvent.TYPE
        assert entity.name in act[0].get_message()
        
        assert inv.type == users.INVITE_TYPE_ENTITY
        assert inv.object_id == entity.id
        assert inv.object == entity
        
        iu = fh.create_user(username=email, email=email)
        self.flush()
        
        assert entity.get_role(iu) == None
        
        inv.accept(iu)
        self.flush()
        Session.refresh(inv)
        
        act = activity.get_activities()
        assert act[0].type == activity.InviteAccept.TYPE
        assert entity.name in act[0].get_message()
        
        assert inv.invited_user == iu
        assert entity.get_role(iu) == users.APP_ROLE_READ
        assert org.get_role(iu) == None
        assert project.get_role(iu) == None
        
Пример #31
0
 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
Пример #32
0
 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
     
Пример #33
0
 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()
Пример #34
0
 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()
Пример #35
0
    def test_interested_users_file(self):
        """
        Test basic changes functionality
        """
        user = fh.create_user()
        user2 = fh.create_user()
        user3 = fh.create_user()
        user4 = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()
        
        project.organization.attach_user(user2)
        project.organization.attach_user(user3)
        project.organization.attach_user(user4)
        self.flush()
        
        filepath = file_path('ffcc00.gif')
        change = project.add_change(user4, u"/foobar.gif", filepath, u"this is a new change")
        self.flush()
        file = change.entity
        
        #user created it
        users = file.interested_users
        assert user4 in users
        assert user3 not in users
        assert user2 not in users
        assert user not in users
        
        #attach user3
        file.attach_user(user3)
        self.flush()
        
        users = file.interested_users
        assert user4 in users
        assert user3 in users
        assert user2 not in users
        assert user not in users

        
        
        #user2 added a comment
        comment = change.add_comment(user2, u'foobar')
        self.flush()
        
        users = file.interested_users
        assert user4 in users
        assert user3 in users
        assert user2 in users
        assert user not in users
        
        #user 2 interested in his own comment
        users = comment.interested_users
        assert user4 not in users
        assert user3 not in users
        assert user2 in users
        assert user not in users
        
        #user added a reply
        reply = change.add_comment(user, u'foobar', in_reply_to=comment)
        self.flush()
        
        users = file.interested_users
        assert user4 in users
        assert user3 in users
        assert user2 in users
        assert user in users
        
        print user, user2, user3, user4
        
        users = comment.interested_users
        assert user4 not in users
        assert user3 not in users
        assert user2 in users
        assert user in users
Пример #36
0
    def test_changes(self):
        """
        Test basic changes functionality
        """
        user = fh.create_user()
        user2 = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/foobar.gif", filepath, u"this is a new change")
        self.flush()
        assert change.version == 1
        assert change.parse_status == image.PARSE_STATUS_COMPLETED
        assert change.parse_type == image.PARSE_TYPE_IMAGEMAGICK

        assert project.get_changes(u"/foobar.gif") == [change]
        assert change.url and change.diff_url and change.thumbnail_url

        filepath = file_path('ffcc00.gif')
        change2 = project.add_change(user, u"/foobar.gif", filepath, u"this is a new new change")
        self.flush()
        assert change2.version == 2

        assert project.get_changes(u"/foobar.gif") == [change2, change]
        
        comment = change.add_comment(user, u'foobar')
        comment1 = change.add_comment(user, u'foobar', 1, 2)
        comment2 = change.add_comment(user, u'foobar', 1, 2, 3, 4)
        comment3 = change.add_comment(user, u'foobar', 1, 2, 3, 4)
        comment3.delete()
        self.flush()
        assert change.get_comments() == [comment, comment1, comment2]
        
        comment_status = comment.completion_status
        assert comment_status
        assert comment_status.comment == comment
        assert comment_status.user == user
        assert comment_status.status == STATUS_OPEN
        assert comment_status.id
        
        cs = comment.set_completion_status(user2, STATUS_OPEN)
        self.flush()
        cs = comment.set_completion_status(user2, STATUS_COMPLETED)
        self.flush()
        cs = comment.set_completion_status(user2, STATUS_OPEN)
        self.flush()
        cs = comment.set_completion_status(user2, STATUS_COMPLETED)
        self.flush()
        assert cs
        assert cs.comment == comment
        assert cs.user == user2
        assert cs.status == STATUS_COMPLETED
        assert cs.id
        
        comment_status = comment.completion_status
        assert comment_status
        assert comment_status.comment == comment
        assert comment_status.user == user2
        assert comment_status.status == STATUS_COMPLETED
        assert comment_status.id
        
        num = change.get_number_comments(status=STATUS_COMPLETED)
        assert num == 1
        
        num = change.get_number_comments(status=STATUS_OPEN)
        assert num == 2
        self.flush()
        
        
        #makesure a fireworks png gets the right parse status and type
        filepath = file_path('cs5.png')
        change = project.add_change(user, u"/cs5.png", filepath, u"this is a new change")
        self.flush()
        assert change.version == 1
        assert change.parse_status == image.PARSE_STATUS_PENDING
        assert change.parse_type == image.PARSE_TYPE_FIREWORKS_CS5
Пример #37
0
    def test_invite(self):
        t = (AppException, )

        uorg = fh.create_user()
        uproj = fh.create_user()
        ufile = fh.create_user()

        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()
        org = project.organization

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/main/project/arnold/foobar.gif",
                                    filepath, u"this is a new change")
        entity = change.entity

        def fu(email):
            return Session.query(users.User).filter_by(email=email).first()

        #invite non-user to org
        email = '*****@*****.**'
        inv = users.Invite.create(user, email, org, users.APP_ROLE_WRITE)
        self.flush()

        act = activity.get_activities()
        assert act[0].type == activity.InviteEvent.TYPE
        assert act[0].get_message()

        assert inv.invited_email == email
        assert inv.invited_user == None
        assert inv.user == user
        assert inv.role == users.APP_ROLE_WRITE
        assert inv.type == users.INVITE_TYPE_ORGANIZATION
        assert inv.object_id == org.id
        assert inv.status == STATUS_PENDING

        assert inv.object == org

        assert self.throws_exception(lambda: inv.accept(),
                                     types=t).code == err.INVALID  #no user
        assert self.throws_exception(
            lambda: inv.accept(uorg),
            types=t).code == err.INVALID  #email no match

        iu = fh.create_user(username=email, email=email)
        self.flush()

        assert org.get_role(iu) == None

        inv.accept(iu)
        self.flush()
        Session.refresh(inv)

        act = activity.get_activities()
        assert act[0].type == activity.InviteAccept.TYPE
        assert org.name in act[0].get_message()

        assert inv.invited_email == email
        assert inv.invited_user == iu
        assert inv.user == user
        assert inv.type == users.INVITE_TYPE_ORGANIZATION
        assert inv.object_id == org.id
        assert inv.status == STATUS_APPROVED

        assert inv.object == org
        assert org.get_role(iu) == users.APP_ROLE_WRITE

        assert self.throws_exception(lambda: users.Invite.create(
            user, email, org, users.APP_ROLE_WRITE),
                                     types=t).code == err.DUPLICATE

        #invite non-user to project
        email = '*****@*****.**'
        inv = users.Invite.create(user, email, project, users.APP_ROLE_ADMIN)
        self.flush()

        act = activity.get_activities()
        assert act[0].type == activity.InviteEvent.TYPE
        assert project.name in act[0].get_message()

        assert inv.role == users.APP_ROLE_ADMIN
        assert inv.type == users.INVITE_TYPE_PROJECT
        assert inv.object_id == project.id
        assert inv.object == project

        iu = fh.create_user(username=email, email=email)
        self.flush()

        assert project.get_role(iu) == None

        inv.accept(iu)
        self.flush()
        Session.refresh(inv)

        act = activity.get_activities()
        assert act[0].type == activity.InviteAccept.TYPE
        assert project.name in act[0].get_message()

        assert inv.invited_user == iu
        assert project.get_role(iu) == users.APP_ROLE_ADMIN
        assert org.get_role(iu) == None

        #invite non-user to entity
        email = '*****@*****.**'
        inv = users.Invite.create(user, email, entity, users.APP_ROLE_READ)
        self.flush()

        act = activity.get_activities()
        assert act[0].type == activity.InviteEvent.TYPE
        assert entity.name in act[0].get_message()

        assert inv.type == users.INVITE_TYPE_ENTITY
        assert inv.object_id == entity.id
        assert inv.object == entity

        iu = fh.create_user(username=email, email=email)
        self.flush()

        assert entity.get_role(iu) == None

        inv.accept(iu)
        self.flush()
        Session.refresh(inv)

        act = activity.get_activities()
        assert act[0].type == activity.InviteAccept.TYPE
        assert entity.name in act[0].get_message()

        assert inv.invited_user == iu
        assert entity.get_role(iu) == users.APP_ROLE_READ
        assert org.get_role(iu) == None
        assert project.get_role(iu) == None
Пример #38
0
    def test_edit(self):

        user = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/wowza/foobar.gif", filepath,
                                    u"this is a new change")
        self.flush()
        filepath = file_path('ffcc00.gif')
        change2 = project.add_change(user, u"/wowza/kittens.gif", filepath,
                                     u"this is a new change")
        self.flush()

        r, change = api.file.get(user,
                                 user,
                                 project.eid,
                                 path=u"/wowza/foobar.gif")
        kittens, change2 = api.file.get(user,
                                        user,
                                        project.eid,
                                        path=u"/wowza/kittens.gif")
        directory = Session.query(projects.Entity).filter_by(
            name='wowza', project=project).first()

        assert directory
        assert r.name == 'foobar.gif'
        eid = r.eid

        r = api.file.edit(user, user, eid, name=u"somethingelse.gif")
        self.flush()

        assert r.name == 'somethingelse.gif'

        r, change = api.file.get(user,
                                 user,
                                 project.eid,
                                 path=u"/wowza/somethingelse.gif")

        assert r.name == 'somethingelse.gif'
        assert eid == r.eid

        #change again to same thing...
        r = api.file.edit(user, user, eid, name=u"somethingelse.gif")
        assert r

        r = self.throws_exception(lambda: api.file.edit(
            user, user, kittens.eid, name=u"somethingelse.gif"))
        assert 'name' in r.error_dict

        self.login(user)
        r = self.client_async(api_url('file', 'edit', id=kittens.eid),
                              {'name': 'cats.gif'})
        assert r.results
        assert r.results.name == 'cats.gif'

        r = self.client_async(api_url('file', 'edit', id=kittens.eid), {
            'key': 'name',
            'value': 'meow.gif'
        })
        assert r.results
        assert r.results.name == 'meow.gif'

        r = self.client_async(api_url('file', 'edit', id=directory.eid), {
            'key': 'name',
            'value': 'omg'
        })
        assert r.results
        assert r.results.name == 'omg'

        r, change = api.file.get(user,
                                 user,
                                 project.eid,
                                 path=u"/omg/meow.gif")
        assert r.eid == kittens.eid
Пример #39
0
    def test_comments(self):

        rando = fh.create_user()
        reader = fh.create_user()
        user = fh.create_user()
        guy_in_project = fh.create_user()
        project = fh.create_project(user=user, name=u"helloooo")
        self.flush()

        project.organization.attach_user(guy_in_project,
                                         status=STATUS_APPROVED)
        project.organization.attach_user(reader, status=STATUS_APPROVED)
        assert api.project.attach_user(user, user, project, guy_in_project,
                                       projects.APP_ROLE_WRITE)
        assert api.project.attach_user(user, user, project, reader,
                                       projects.APP_ROLE_READ)

        filepath = file_path('ffcc00.gif')
        change = project.add_change(user, u"/foobar.gif", filepath,
                                    u"this is a new change")
        self.flush()

        extract = change.change_extracts[0]

        _extract, comment = api.file.add_comment(user,
                                                 user,
                                                 'My comment!',
                                                 extract=extract.id,
                                                 x=23,
                                                 y=345,
                                                 width=10,
                                                 height=20)
        self.flush()

        assert _extract == extract
        assert comment.change == change
        assert comment.change_extract == extract

        assert comment.body == u'My comment!'
        assert comment.eid
        assert comment.x == 23
        assert comment.y == 345
        assert comment.width == 10
        assert comment.height == 20
        assert comment.completion_status.status == STATUS_OPEN

        #make sure comment completion statuses work
        api.file.set_comment_completion_status(user,
                                               user,
                                               comment,
                                               status=STATUS_COMPLETED)
        self.flush()
        assert comment.completion_status.status == STATUS_COMPLETED

        api.file.set_comment_completion_status(user,
                                               guy_in_project,
                                               comment,
                                               status=STATUS_OPEN)
        self.flush()
        assert comment.completion_status.status == STATUS_OPEN

        ex = self.throws_exception(
            lambda: api.file.set_comment_completion_status(
                user, user, None, status=STATUS_COMPLETED))
        assert ex.code == NOT_FOUND
        ex = self.throws_exception(
            lambda: api.file.set_comment_completion_status(
                user, user, comment))
        assert 'status' in ex.error_dict
        ex = self.throws_exception(
            lambda: api.file.set_comment_completion_status(
                reader, reader, comment, status=STATUS_COMPLETED))
        assert ex.code == FORBIDDEN

        _, reply = api.file.add_comment(user,
                                        user,
                                        'My reply!',
                                        change=change.eid,
                                        in_reply_to=comment.eid)
        self.flush()

        assert reply
        assert reply.in_reply_to == comment
        assert reply.eid

        assert comment.replies
        assert len(comment.replies) == 1

        _change, comments = api.file.get_comments(user,
                                                  user,
                                                  change=change.eid)

        assert change == _change
        assert len(comments) == 2
        assert comments[0] == comment
        assert comments[1] == reply
        assert comments[0].replies[0] == reply

        _, guyscomment = api.file.add_comment(guy_in_project,
                                              guy_in_project,
                                              'My comment!',
                                              extract=extract.id,
                                              x=23,
                                              y=345,
                                              width=10,
                                              height=20)
        _, guyscomment1 = api.file.add_comment(guy_in_project,
                                               guy_in_project,
                                               'My comment!',
                                               extract=extract.id,
                                               x=23,
                                               y=345,
                                               width=10,
                                               height=20)
        self.flush()

        ex = self.throws_exception(lambda: api.file.remove_comment(
            guy_in_project, guy_in_project, comment.eid)).code == FORBIDDEN
        ex = self.throws_exception(lambda: api.file.remove_comment(
            rando, rando, guyscomment.eid)).code == FORBIDDEN

        _, comments = api.file.get_comments(user, user, change=change.eid)
        assert len(comments) == 4

        assert api.file.remove_comment(user, user, guyscomment.eid)
        assert api.file.remove_comment(guy_in_project, guy_in_project,
                                       guyscomment1.eid)
        self.flush()

        _, comments = api.file.get_comments(user, user, change=change.eid)
        assert len(comments) == 2

        ex = self.throws_exception(lambda: api.file.get_comments(user, user))
        assert ex.exceptions[0].code == NOT_FOUND
Пример #40
0
    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()
Пример #41
0
    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