Ejemplo n.º 1
0
def thirdparty_mockup_server():
    class Root(RegexRouteController):
        def __init__(self):
            super().__init__([
                ('/apiv1/issues', self.handler),
            ])

        @json(verbs=['sent', 'mentioned'])
        def handler(self):
            if context.query['roomId'] == 'bad':
                raise HTTPBadRequest()

            raise HTTPNoContent()

    app = MockupApplication('mockup-thirdparty', Root())
    with mockup_http_server(app) as (server, url):
        settings.merge(f'''
          webhooks:
            sent:
              url: {url}
            mentioned:
              url: {url}
        ''')

        yield app
Ejemplo n.º 2
0
def maestro_mockup_server():
    class Root(RegexRouteController):
        def __init__(self):
            super().__init__([
                ('/apiv1/issues', self.send),
            ])

        @json(verbs=['send', 'mention'])
        def send(self):
            time.sleep(0.5)

    app = MockupApplication('maestro-mockup', Root())
    with mockup_http_server(app) as (server, url):
        settings.merge(f'''
          webhooks:
            sent:
              url: {url}/apiv1/issues
              verb: send

            mentioned:
              url: {url}/apiv1/issues
              verb: mention
        ''')

        yield app
Ejemplo n.º 3
0
def alfacoins_mockup_gateway(root_controller):
    app = Application(root_controller)
    with mockup_http_server(app) as (server, url):
        yield ALFACoins(
            name='test-shop',
            password='******',
            secret_key='d53974471e9b555554f5c318e07e9f23',
            base_url=urljoin(url, '/api/'),
        )
Ejemplo n.º 4
0
def oauth_mockup_server():
    class Root(RegexRouteController):
        def __init__(self):
            super().__init__([
                ('/apiv1/accesstokens', self.create),
                ('/apiv1/members/me', self.get),
            ])

        @json
        def create(self):
            code = context.form.get('code')
            if _cas_server_status != 'idle':
                raise HTTPStatus(_cas_server_status)

            if not code.startswith('authorization code'):
                return dict(accessToken='token is damage', memberId=1)

            return dict(accessToken='access token', memberId=1)

        @json
        def get(self):
            access_token = context.environ['HTTP_AUTHORIZATION']
            if _cas_server_status != 'idle':
                raise HTTPStatus(_cas_server_status)

            if 'access token' in access_token:
                return dict(
                    id=1,
                    title='manager1',
                    email='*****@*****.**',
                    avatar='avatar1',
                )

            raise HTTPForbidden()

    app = MockupApplication('root', Root())
    with mockup_http_server(app) as (server, url):
        settings.merge(f'''
            tokenizer:
              url: {url}
            oauth:
              secret: oauth2-secret
              application_id: 1
              url: {url}
        ''')
        yield app
Ejemplo n.º 5
0
def cas_mockup_server():
    class Root(RegexRouteController):
        def __init__(self):
            super().__init__([
                ('/apiv1/members/me', self.get),
            ])

        @json
        def get(self):
            access_token = context.environ['HTTP_AUTHORIZATION']
            if _cas_server_status != 'idle':
                raise HTTPStatus(_cas_server_status)

            if 'access token1' in access_token:
                return dict(
                    id=2,
                    email='*****@*****.**',
                    title='user1',
                    avatar='avatar2',
                )

            if 'access token2' in access_token:
                return dict(
                    id=3,
                    email='*****@*****.**',
                    title='user2',
                    avatar='avatar3',
                )

            if 'access token3' in access_token:
                return dict(
                    id=4,
                    email='*****@*****.**',
                    title='blocked1',
                    avatar='avatar4',
                )

            if 'access token4' in access_token:
                return dict(
                    id=5,
                    email='*****@*****.**',
                    title='blocker',
                    avatar='avatar5',
                )

            return dict(
                id=1,
                email='*****@*****.**',
                title='user',
                avatar='avatar1',
            )

    app = MockupApplication('cas-mockup', Root())
    with mockup_http_server(app) as (server, url):
        settings.merge(f'''
          tokenizer:
            url: {url}
          oauth:
              url: {url}
        ''')

        yield app
Ejemplo n.º 6
0
def unauthorized_alfacoins_mockup_gateway(root_controller):
    app = Application(root_controller)
    with mockup_http_server(app) as (server, url):
        yield ALFACoins(
            base_url=urljoin(url, '/api/'),
        )