Example #1
0
    def Xtest_get_user(self):
        """
        Verify that calling get_current_user while logged in provides you
        with a logout url and your login info
        """

        self.set_user(User(is_admin=True))
        # Verify no owner exists before call
        self.assertEqual(None, self.db.user_owners.get(self.user, None))
        num_owners = len(self.db.owners)

        url = 'http://www.domain.com/some/extra/path/'
        user = self.rpc.get_current_user(url)

        # Verify correct user details are returned
        base = get_base_url(url)
        goodbye = '{}/#Goodbye:'.format(base)
        self.assertEqual(self.ae.create_logout_url(goodbye), user.logout_url)
        self.assertEqual(self.user.nickname(), user.nickname)
        self.assertEqual(self.user.email(), user.email)
        self.assertEqual(None, user.login_url)

        # Verify owner was created correctly
        owner = self.db.user_owners.get(self.user)
        self.assertEqual(num_owners + 1, len(self.db.owners))
        self.assertEqual(self.user, owner.user)
        self.assertEqual(owner.key().id(), user.owner_id)
        self.assertEqual(self.user.nickname(), owner.nickname)
        self.assertEqual(self.user.email(), owner.email)
        self.assertEqual(extract_name(self.user.email()), owner.name)
Example #2
0
    def Xtest_get_user(self):
        """
        Verify that calling get_current_user while logged in provides you
        with a logout url and your login info
        """

        self.set_user(User(is_admin=True))
        # Verify no owner exists before call
        self.assertEqual(None, self.db.user_owners.get(self.user, None))
        num_owners = len(self.db.owners)

        url = 'http://www.domain.com/some/extra/path/'
        user = self.rpc.get_current_user(url)

        # Verify correct user details are returned
        base = get_base_url(url)
        goodbye = '{}/#Goodbye:'.format(base)
        self.assertEqual(self.ae.create_logout_url(goodbye), user.logout_url)
        self.assertEqual(self.user.nickname(), user.nickname)
        self.assertEqual(self.user.email(), user.email)
        self.assertEqual(None, user.login_url)

        # Verify owner was created correctly
        owner = self.db.user_owners.get(self.user)
        self.assertEqual(num_owners + 1, len(self.db.owners))
        self.assertEqual(self.user, owner.user)
        self.assertEqual(owner.key().id(), user.owner_id)
        self.assertEqual(self.user.nickname(), owner.nickname)
        self.assertEqual(self.user.email(), owner.email)
        self.assertEqual(extract_name(self.user.email()), owner.name)
Example #3
0
    def test_get_current(self):
        """
        get_current gives currently logged in user and a logout URL
        """
        self.user.is_admin = True

        # Verify no owner exists before call
        self.assertEqual(None, self.db.user_owners.get(self.user, None))
        num_owners = len(self.db.owners)

        # make the API Call
        self.resource.get_current()
        user = self.resource.get_last_response()

        # Verify correct user details are returned
        logout_url = self.ae.create_logout_url('/')
        self.assertEqual(logout_url, user.logout_url)
        self.assertEqual(self.user.nickname(), user.nickname)
        self.assertEqual(self.user.email(), user.email)

        # Verify owner was created correctly
        owner = self.db.user_owners.get(self.user)
        self.assertEqual(num_owners + 1, len(self.db.owners))
        self.assertEqual(self.user, owner.user)
        self.assertEqual(owner.key().id(), user.owner_id)
        self.assertEqual(self.user.nickname(), owner.nickname)
        self.assertEqual(self.user.email(), owner.email)
        self.assertEqual(extract_name(self.user.email()), owner.name)
Example #4
0
    def test_get_current(self):
        """
        get_current gives currently logged in user and a logout URL
        """
        self.user.is_admin = True

        # Verify no owner exists before call
        self.assertEqual(None, self.db.user_owners.get(self.user, None))
        num_owners = len(self.db.owners)

        # make the API Call
        self.resource.get_current()
        user = self.resource.get_last_response()

        # Verify correct user details are returned
        logout_url = self.ae.create_logout_url('/')
        self.assertEqual(logout_url, user.logout_url)
        self.assertEqual(self.user.nickname(), user.nickname)
        self.assertEqual(self.user.email(), user.email)

        # Verify owner was created correctly
        owner = self.db.user_owners.get(self.user)
        self.assertEqual(num_owners + 1, len(self.db.owners))
        self.assertEqual(self.user, owner.user)
        self.assertEqual(owner.key().id(), user.owner_id)
        self.assertEqual(self.user.nickname(), owner.nickname)
        self.assertEqual(self.user.email(), owner.email)
        self.assertEqual(extract_name(self.user.email()), owner.name)
Example #5
0
 def __init__(self, user, **kwargs):
     super(ListOwner, self).__init__(**kwargs)
     self.user = user
     self.name = extract_name(user.email())
     self.nickname = user.nickname()
     self.email = user.email()
     self.groups = []
     self.memberships = []
     self.lists = []
Example #6
0
 def __init__(self, user, **kwargs):
     super(ListOwner, self).__init__(**kwargs)
     self.user = user
     self.name = extract_name(user.email())
     self.nickname = user.nickname()
     self.email = user.email()
     self.groups = []
     self.memberships = []
     self.lists = []
Example #7
0
    def approve_request(self, req_id):
        '''
        Approve the given AccessRequestDb
        '''
        if not self.db.user.is_admin:
            raise PermissionDeniedError()

        req = self.db.get_req(req_id)
        self.db.add_owner(req.user)
        self.db.delete(req)
        to = req.user.email()
        subject = 'Account Activated'
        body = self.ae.APPROVE_TEMPLATE % extract_name(to)
        self.ae.send_mail(to, subject, body)
        return []
Example #8
0
    def approve_request(self, req_id):
        '''
        Approve the given AccessRequestDb
        '''
        if not self.db.user.is_admin:
            raise PermissionDeniedError()

        req = self.db.get_req(req_id)
        self.db.add_owner(req.user)
        self.db.delete(req)
        to = req.user.email()
        subject = 'Account Activated'
        body = self.ae.APPROVE_TEMPLATE % extract_name(to)
        self.ae.send_mail(to, subject, body)
        return []
Example #9
0
    def deny(self, req_id):
        """Deny the given request"""
        if not self.user.is_admin:
            raise PermissionDeniedError()

        req = self.db.get_req(int(req_id))
        if req is None:
            self.abort(404)

        req.denied = True
        req.put()
        to = req.user.email()
        subject = 'Account Not Activated'
        body = self.ae.DENY_TEMPLATE % extract_name(to)
        self.ae.send_mail(to, subject, body)
        self.dump(JsSuccess())
Example #10
0
    def approve(self, req_id):
        """Approve the given request"""
        if not self.user.is_admin:
            raise PermissionDeniedError()

        req = self.db.get_req(int(req_id))
        if req is None:
            self.abort(404)

        self.db.add_owner(req.user)
        self.db.delete(req)
        to = req.user.email()
        subject = 'Account Activated'
        body = self.ae.APPROVE_TEMPLATE % extract_name(to)
        self.ae.send_mail(to, subject, body)
        self.dump(JsSuccess())
Example #11
0
    def deny_request(self, req_id):
        '''
        Deny the given AccessRequestDb
        '''

        if not self.db.user.is_admin:
            raise PermissionDeniedError()

        req = self.db.get_req(req_id)
        req.denied = True
        req.put()
        to = req.user.email()
        subject = 'Account Not Activated'
        body = self.ae.DENY_TEMPLATE % extract_name(to)
        self.ae.send_mail(to, subject, body)
        return []
Example #12
0
    def deny_request(self, req_id):
        '''
        Deny the given AccessRequestDb
        '''

        if not self.db.user.is_admin:
            raise PermissionDeniedError()

        req = self.db.get_req(req_id)
        req.denied = True
        req.put()
        to = req.user.email()
        subject = 'Account Not Activated'
        body = self.ae.DENY_TEMPLATE % extract_name(to)
        self.ae.send_mail(to, subject, body)
        return []
Example #13
0
    def test_approve(self):
        """Approve creates Owner"""
        self.user.is_admin = True
        user = User(email='*****@*****.**')
        req = self.db.add_req(user)
        self.assertEqual({}, self.ae.msg)

        self.resource.approve(req.key().id())

        self.assertEqual(0, len(self.db.request_ids))
        owner = self.db.owners.values()[0]
        self.assertEqual(user, owner.user)
        msg = self.ae.msg
        self.assertEqual(self.ae.FROM_ADDRESS, msg['f'])
        self.assertEqual(owner.email, msg['t'])
        self.assertEqual('Account Activated', msg['s'])
        body = self.ae.APPROVE_TEMPLATE % extract_name(owner.email)
        self.assertEqual(body, msg['b'])
Example #14
0
    def test_deny(self):
        """Deny doesn't create owner"""
        self.user.is_admin = True
        user = User(email='*****@*****.**')
        req = self.db.add_req(user)
        self.assertFalse(req.denied)
        self.assertEqual({}, self.ae.msg)

        self.resource.deny(req.key().id())

        self.assertTrue(req.denied)
        self.assertEqual(1, len(self.db.request_ids))
        self.assertEqual(0, len(self.db.owners))

        msg = self.ae.msg
        self.assertEqual(self.ae.FROM_ADDRESS, msg['f'])
        self.assertEqual(user.email(), msg['t'])
        self.assertEqual('Account Not Activated', msg['s'])
        body = self.ae.DENY_TEMPLATE % extract_name(user.email())
        self.assertEqual(body, msg['b'])
Example #15
0
    def test_approve_request(self):
        '''
        Confirm approving a request for access to all i want
        '''
        self.set_user(User(is_admin=True))
        user = User(email='*****@*****.**')
        req = self.db.add_req(user)
        self.assertEqual({}, self.ae.msg)

        self.rpc.approve_request(req.key().id())

        self.assertEqual(0, len(self.db.request_ids))
        owner = self.db.owners.values()[0]
        self.assertEqual(user, owner.user)
        msg = self.ae.msg
        self.assertEqual(self.ae.FROM_ADDRESS, msg['f'])
        self.assertEqual(owner.email, msg['t'])
        self.assertEqual('Account Activated', msg['s'])
        body = self.ae.APPROVE_TEMPLATE % extract_name(owner.email)
        self.assertEqual(body, msg['b'])
Example #16
0
    def test_approve_request(self):
        '''
        Confirm approving a request for access to all i want
        '''
        self.set_user(User(is_admin=True))
        user = User(email='*****@*****.**')
        req = self.db.add_req(user)
        self.assertEqual({}, self.ae.msg)

        self.rpc.approve_request(req.key().id())

        self.assertEqual(0, len(self.db.request_ids))
        owner = self.db.owners.values()[0]
        self.assertEqual(user, owner.user)
        msg = self.ae.msg
        self.assertEqual(self.ae.FROM_ADDRESS, msg['f'])
        self.assertEqual(owner.email, msg['t'])
        self.assertEqual('Account Activated', msg['s'])
        body = self.ae.APPROVE_TEMPLATE % extract_name(owner.email)
        self.assertEqual(body, msg['b'])
Example #17
0
 def test_extract_name(self):
     """Confirm extraction of a name from an email address"""
     self.assertEqual(util.extract_name('*****@*****.**'),
                      'First Last')
Example #18
0
 def test_extract_name(self):
     """Confirm extraction of a name from an email address"""
     self.assertEqual(util.extract_name('*****@*****.**'),
                      'First Last')