Пример #1
0
    def api_request(self,
                    method,
                    action,
                    data=(),
                    authenticate=True,
                    context=None):
        if context is None:
            context = self.layer['portal']
        if authenticate:
            browser.login(SITE_OWNER_NAME)
        else:
            browser.logout()

        with verbose_logging():
            if method.lower() == 'get':
                browser.visit(context,
                              view='upgrades-api/{0}?{1}'.format(
                                  action, urllib.urlencode(data)))

            elif method.lower() == 'post':
                if not data:
                    data = {'enforce': 'post'}
                browser.visit(context,
                              view='upgrades-api/{0}'.format(action),
                              data=data)

            else:
                raise Exception(
                    'Unsupported request method {0}'.format(method))
Пример #2
0
    def api_request(self, method, action, data=(), authenticate=True,
                    context=None):
        if context is None:
            context = self.layer['portal']
        if authenticate:
            browser.login(SITE_OWNER_NAME)
        else:
            browser.logout()

        with verbose_logging():
            if method.lower() == 'get':
                browser.visit(context, view='upgrades-api/{0}?{1}'.format(
                        action,
                        urllib.urlencode(data)))

            elif method.lower() == 'post':
                if not data:
                    data = {'enforce': 'post'}
                browser.visit(context, view='upgrades-api/{0}'.format(action),
                              data=data)

            else:
                raise Exception('Unsupported request method {0}'.format(method))