示例#1
0
    def testCSVImport(self):
        from zope.component import queryUtility
        from upfront.shorturl.interfaces import IShortURLStorage
        storage = queryUtility(IShortURLStorage)
        
        member = self.portal.restrictedTraverse('@@plone_portal_state').member()
        z2.setRoles(self.portal.acl_users, member.getId(),
            member.getRoles() + ['Manager'])
        addview = self.portal.restrictedTraverse('@@add-shorturl')
        f = StringIO("10,http://wasabishop\n22,http://was12\n")
        error = addview._import(f)
        self.assertTrue(len(storage)==2, "CSV import failed to import 2 items")
        self.assertTrue(error is None, "Upload returned an error")

        g = StringIO("101,http://apeaceprize\n22_11_2,http://theend\n")
        error = addview._import(g)
        self.assertTrue(error is not None, "Upload should return an error")
示例#2
0
    def testAddAndRemove(self):
        """ Test that the browser views are there and work correctly. """
        from zExceptions import Unauthorized
        from zope.component import queryUtility
        from upfront.shorturl.interfaces import IShortURLStorage
        storage = queryUtility(IShortURLStorage)
        request = self.layer['request']
        request["form.submitted"] = "1"
        request["shortcode"] = "aaaaa"
        request["target"] = "http://aaaaa"
        request['ACTUAL_URL'] = request['SERVER_URL']

        # You can't do this unless you have ManagePortal
        self.assertRaises(
            Unauthorized,
            lambda: self.portal.restrictedTraverse('@@add-shorturl'))

        member = self.portal.restrictedTraverse('@@plone_portal_state').member()
        roles = member.getRoles()
        z2.setRoles(self.portal.acl_users, member.getId(),
            roles + ['Manager'])
        addview = self.portal.restrictedTraverse('@@add-shorturl')
        addview()
        self.assertTrue(len(request.get('errors', {}))==0,
            "Adding a short url raised errors")

        # Add it again, it should return an error
        addview()
        self.assertTrue(len(request.get('errors', {}))!=0,
            "Adding a duplicate shortcode should raise an error.")

        self.assertTrue(len(storage)==1, "Adding mapping failed.")

        # Delete it
        request.clear()
        request["remove"] = ["aaaaa"]
        self.portal.restrictedTraverse('@@manage-shorturls').update()
        self.assertTrue(len(storage)==0, "Deleting mapping failed.")
示例#3
0
def setRoles(portal, userId, roles):
    """Set the given user's roles to a tuple of roles.
    """

    userFolder = portal['acl_users']
    z2.setRoles(userFolder, userId, roles)
示例#4
0
def setRoles(portal, userId, roles):
    """Set the given user's roles to a tuple of roles.
    """

    userFolder = portal['acl_users']
    z2.setRoles(userFolder, userId, roles)
示例#5
0
def setRoles(silvaroot, userId, roles):
    """Set the given user's roles to a tuple of roles.
    """

    userFolder = silvaroot.acl_users
    z2.setRoles(userFolder, userId, roles)
 def setRoles(self, roles):
     userFolder = self.portal['acl_users']
     z2.setRoles(userFolder, user_name, roles)