Beispiel #1
0
 def test_timer_proxy(self):
     u = fh.create_user()
     self.flush()
     self.login(u)
     
     response = self.post(self.form_url, {
         'a_number': 32,
         'a_string': 'aodij'
     })
     
     assert response.tmpl_context.show_debug == False
     assert response.tmpl_context.queries == ''
     
     u = fh.create_user(is_admin=True)
     self.flush()
     self.login(u)
     
     response = self.post(self.form_url, {
         'a_number': 32,
         'a_string': 'aodij'
     })
     
     assert response.tmpl_context.show_debug == True
     assert len(response.tmpl_context.queries) == 3
     assert response.tmpl_context.querie_time > 0.0
     
     for q, t in response.tmpl_context.queries:
         assert q
         assert t > 0.0
Beispiel #2
0
    def test_edit(self):
        own = fh.create_user()
        rando = fh.create_user()
        a = fh.create_user(is_admin=True)
        self.flush()

        u = api.user.edit(own,
                          own,
                          own,
                          first_name='omgwow',
                          default_timezone=0,
                          is_active='f',
                          role='admin')

        assert u.id == own.id
        assert u.first_name == 'omgwow'
        assert u.is_active == True
        assert u.role == 'user'
        assert 'London' in u.default_timezone or 'UTC' in u.default_timezone

        u = api.user.edit(a, a, own, last_name='yeah')
        assert u.id == own.id

        u = api.user.edit(a, a, own, is_active='f', role='admin')
        assert u.id == own.id
        assert u.is_active == False
        assert u.role == 'admin'

        assert self.throws_exception(lambda: api.user.edit(
            rando, rando, own, first_name='m')).code == NOT_FOUND
        assert self.throws_exception(lambda: api.user.edit(
            a, a, None, first_name='s')).code == NOT_FOUND
Beispiel #3
0
    def test_auth_role(self):
        u = fh.create_user()
        adm = fh.create_user(is_admin=True)

        assert auth_role_fn(adm, u)
        assert self.throws_exception(
            lambda: auth_role_fn(u, u)).code == FORBIDDEN
Beispiel #4
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()
Beispiel #5
0
    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
Beispiel #6
0
    def test_timer_proxy(self):
        u = fh.create_user()
        self.flush()
        self.login(u)

        response = self.post(self.form_url, {
            'a_number': 32,
            'a_string': 'aodij'
        })

        assert response.tmpl_context.show_debug == False
        assert response.tmpl_context.queries == ''

        u = fh.create_user(is_admin=True)
        self.flush()
        self.login(u)

        response = self.post(self.form_url, {
            'a_number': 32,
            'a_string': 'aodij'
        })

        assert response.tmpl_context.show_debug == True
        assert len(response.tmpl_context.queries) == 3
        assert response.tmpl_context.querie_time > 0.0

        for q, t in response.tmpl_context.queries:
            assert q
            assert t > 0.0
Beispiel #7
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
Beispiel #8
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)
Beispiel #9
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
Beispiel #10
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
Beispiel #11
0
    def test_get(self):
        u, _ = fh.create_user(), fh.create_user()

        o = {
            'subdomain': u'mycompany',
            'company_name': u'My company',
            'url': u'http://heyman.com',
        }
        org1 = api.organization.create(u, u, **o)

        o = {
            'subdomain': u'meh',
            'company_name': u'WOWZA',
            'url': u'http://heyman.com',
        }
        org2 = api.organization.create(_, _, **o)
        self.flush()

        #test api
        orgs = api.organization.get(u, u)

        assert len(orgs) == 1
        assert orgs[0] == org1

        #test serialized
        self.login(u)
        response = self.client_async(api_url('organization', 'get'), {})
        assert len(response.results) == 1
        assert response.results[0].eid == org1.eid

        org2.attach_user(u, status=STATUS_APPROVED)
        self.flush()

        #test multiple
        orgs = api.organization.get(u, u)
        assert len(orgs) == 2
        orgs = set([o.eid for o in orgs])

        assert org1.eid in orgs
        assert org2.eid in orgs

        response = self.client_async(api_url('organization', 'get'), {})
        assert len(response.results) == 2

        #test grab single
        orgs = api.organization.get(u, u, organization=org1.eid)
        assert orgs.eid == org1.eid

        response = self.client_async(api_url('organization', 'get'),
                                     {'organization': org1.eid})
        assert response.results.eid == org1.eid
Beispiel #12
0
 def test_get(self):
     u, _ = fh.create_user(), fh.create_user()
     
     o = {
         'subdomain': u'mycompany',
         'company_name': u'My company',
         'url': u'http://heyman.com',
     }
     org1 = api.organization.create(u,u, **o)
     
     o = {
         'subdomain': u'meh',
         'company_name': u'WOWZA',
         'url': u'http://heyman.com',
     }
     org2 = api.organization.create(_,_, **o)
     self.flush()
     
     #test api
     orgs = api.organization.get(u,u);
     
     assert len(orgs) == 1
     assert orgs[0] == org1
     
     #test serialized
     self.login(u)
     response = self.client_async(api_url('organization', 'get'), {})
     assert len(response.results) == 1
     assert response.results[0].eid == org1.eid
     
     org2.attach_user(u, status=STATUS_APPROVED)
     self.flush()
     
     #test multiple
     orgs = api.organization.get(u,u);
     assert len(orgs) == 2
     orgs = set([o.eid for o in orgs])
     
     assert org1.eid in orgs
     assert org2.eid in orgs
     
     response = self.client_async(api_url('organization', 'get'), {})
     assert len(response.results) == 2
     
     #test grab single
     orgs = api.organization.get(u,u, organization=org1.eid);
     assert orgs.eid == org1.eid
     
     response = self.client_async(api_url('organization', 'get'), {'organization': org1.eid})
     assert response.results.eid == org1.eid
Beispiel #13
0
 def test_auth_owns_pretend(self):
     u, p = self._create_ad_user()
     
     rando = fh.create_user()
     u2 = fh.create_user()
     adm = fh.create_user(is_admin=True)
     
     assert auth_owns_fn_user(u, u, p)
     assert auth_owns_fn_actual_user(u, u, p)
     assert auth_enforce_owns_fn(u, u, p)
     assert auth_owns_fn_user(adm, u, p)
     
     assert self.throws_exception(lambda: auth_owns_fn_user(u2, u2, p)).code == FORBIDDEN
     assert self.throws_exception(lambda: auth_enforce_owns_fn(u2, u2, p)).code == FORBIDDEN
Beispiel #14
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
Beispiel #15
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"
Beispiel #16
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()
Beispiel #17
0
 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
Beispiel #18
0
    def test_auth_owns_pretend(self):
        u, p = self._create_ad_user()

        rando = fh.create_user()
        u2 = fh.create_user()
        adm = fh.create_user(is_admin=True)

        assert auth_owns_fn_user(u, u, p)
        assert auth_owns_fn_actual_user(u, u, p)
        assert auth_enforce_owns_fn(u, u, p)
        assert auth_owns_fn_user(adm, u, p)

        assert self.throws_exception(
            lambda: auth_owns_fn_user(u2, u2, p)).code == FORBIDDEN
        assert self.throws_exception(
            lambda: auth_enforce_owns_fn(u2, u2, p)).code == FORBIDDEN
Beispiel #19
0
    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
Beispiel #20
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
Beispiel #21
0
 def test_bool(self):
     u2 = fh.create_user(is_admin=True)
     self.flush()
     self.login(u2)
     
     r = self.client_async(self.url,{'abool': 'on'})
     assert r.results.abool == True
Beispiel #22
0
 def test_api_prologue_exception(self):
     """
     Verifies that an ApiPrologueException is handled properly
     """
     user = fh.create_user()
     self.flush()
     
     self.login(user)
     
     # The bad version in this url will force an ApiPrologueException in the dispatcher
     bad_url = '/api/vA/user/set_pref'
     params = {'key': 'asd', 'value': 'omgwow'}
     
     response = self.client_async(bad_url, params, status=501, assert_success=False)
     assert 'Invalid version' in response.results.errors[0].message
     
     # no function!
     url = '/api/v1/user/meow'
     params = {}
     response = self.client_async(url, params, status=501, assert_success=False)
     assert 'user.meow not implemented' in response.results.errors[0].message
     
     # no module!
     url = '/api/v1/rawr/meow'
     params = {}
     response = self.client_async(url, params, status=501, assert_success=False)
     assert 'rawr.meow not implemented' in response.results.errors[0].message
Beispiel #23
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
Beispiel #24
0
    def test_bool(self):
        u2 = fh.create_user(is_admin=True)
        self.flush()
        self.login(u2)

        r = self.client_async(self.url, {'abool': 'on'})
        assert r.results.abool == True
Beispiel #25
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()
Beispiel #26
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"
Beispiel #27
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
        
Beispiel #28
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)
Beispiel #29
0
    def test_auth(self):

        # not an admin
        u = fh.create_user()
        self.flush()
        self.login(u)

        r = self.client_async(self.url, {}, status=403, assert_success=False)
        assert r.errors[0].code == FORBIDDEN
Beispiel #30
0
    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()
Beispiel #31
0
    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()
Beispiel #32
0
    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()
Beispiel #33
0
 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
Beispiel #34
0
 def test_auth(self):
     
     # not an admin
     u = fh.create_user()
     self.flush()
     self.login(u)
     
     r = self.client_async(self.url,{}, status=403, assert_success=False)
     assert r.errors[0].code == FORBIDDEN
     
Beispiel #35
0
 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
Beispiel #36
0
    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()
Beispiel #37
0
    def test_create(self):
        u = fh.create_user()

        o = {
            'subdomain': u'mycompany',
            'company_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['company_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

        o = {
            'subdomain': u'SomeCompany',
            'company_name': u'My company',
        }
        org = api.organization.create(u, u, **o)
        assert org.subdomain == 'somecompany'

        o = {
            'subdomain': u'mycompany2',
            'company_name': u'My company',
        }
        org = api.organization.create(u, u, **o)
        self.flush()
        assert org.name

        #same subdomain
        o = {
            'subdomain': u'mycompany2',
            'company_name': u'My company',
        }
        assert 'subdomain' in self.throws_exception(
            lambda: api.organization.create(u, u, **o)).error_dict

        #no user
        o = {
            'subdomain': u'mycompany7',
            'company_name': u'My company',
        }
        err = self.throws_exception(
            lambda: api.organization.create(None, None, o))
        assert err.code
Beispiel #38
0
 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
Beispiel #39
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
Beispiel #40
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
Beispiel #41
0
    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)
Beispiel #42
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()
Beispiel #43
0
 def test_create(self):
     u = fh.create_user()
     
     o = {
         'subdomain': u'mycompany',
         'company_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['company_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
     
     o = {
         'subdomain': u'SomeCompany',
         'company_name': u'My company',
     }
     org = api.organization.create(u,u, **o)
     assert org.subdomain == 'somecompany'
     
     o = {
         'subdomain': u'mycompany2',
         'company_name': u'My company',
     }
     org = api.organization.create(u,u, **o)
     self.flush()
     assert org.name
     
     #same subdomain
     o = {
         'subdomain': u'mycompany2',
         'company_name': u'My company',
     }
     assert 'subdomain' in self.throws_exception(lambda: api.organization.create(u,u, **o)).error_dict
     
     #no user
     o = {
         'subdomain': u'mycompany7',
         'company_name': u'My company',
     }
     err = self.throws_exception(lambda: api.organization.create(None, None, o))
     assert err.code
Beispiel #44
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
Beispiel #45
0
 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)
Beispiel #46
0
 def test_value_error(self):
     """
     Verifies that a ValueError is handled properly
     """
     # we cant create a new user because of the rollback when there is an error.
     user = fh.create_user(is_admin=True)
     self.flush()
     
     self.login(user)
     
     # Force a ValueError with a bad budget value
     params = {'anint': 'not an int'}
     response = self.client_async(self.url, params, status=500, assert_success=False)
     assert 'int()' in response.results.errors[0].message
Beispiel #47
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
Beispiel #48
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
Beispiel #49
0
 def test_edit(self):
     own = fh.create_user()
     rando = fh.create_user()
     a = fh.create_user(is_admin=True)
     self.flush()
     
     u = api.user.edit(own, own, own, first_name='omgwow', default_timezone=0, is_active='f', role='admin')
     
     assert u.id == own.id
     assert u.first_name == 'omgwow'
     assert u.is_active == True
     assert u.role == 'user'
     assert 'London' in u.default_timezone or 'UTC' in u.default_timezone
     
     u = api.user.edit(a, a, own, last_name='yeah')
     assert u.id == own.id
     
     u = api.user.edit(a, a, own, is_active='f', role='admin')
     assert u.id == own.id
     assert u.is_active == False
     assert u.role == 'admin'
     
     assert self.throws_exception(lambda: api.user.edit(rando, rando, own, first_name='m')).code == NOT_FOUND
     assert self.throws_exception(lambda: api.user.edit(a, a, None, first_name='s')).code == NOT_FOUND   
Beispiel #50
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:]
     
     
     
     
Beispiel #51
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()
Beispiel #52
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",
                ]
            )
Beispiel #53
0
    def test_value_error(self):
        """
        Verifies that a ValueError is handled properly
        """
        # we cant create a new user because of the rollback when there is an error.
        user = fh.create_user(is_admin=True)
        self.flush()

        self.login(user)

        # Force a ValueError with a bad budget value
        params = {'anint': 'not an int'}
        response = self.client_async(self.url,
                                     params,
                                     status=500,
                                     assert_success=False)
        assert 'int()' in response.results.errors[0].message
Beispiel #54
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
Beispiel #55
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")
Beispiel #56
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
Beispiel #57
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'
            ])
Beispiel #58
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