def test_publish_to_http():
    def callback(request):
        request.headers["Content-Type"].should.equal("application/json")
        json.loads.when.called_with(request.body).should_not.throw(Exception)
        return 200, {}, ""

    responses.add_callback(
        method="POST",
        url="http://example.com/foobar",
        callback=callback,
    )

    conn = boto3.client('sns', region_name='us-east-1')
    conn.create_topic(Name="some-topic")
    response = conn.list_topics()
    topic_arn = response["Topics"][0]['TopicArn']

    conn.subscribe(TopicArn=topic_arn,
                   Protocol="http",
                   Endpoint="http://example.com/foobar")

    response = conn.publish(TopicArn=topic_arn,
                            Message="my message",
                            Subject="my subject")
    message_id = response['MessageId']
Exemple #2
0
    def update_integration_mocks(self, stage_name):
        stage_url_lower = STAGE_URL.format(api_id=self.id.lower(),
            region_name=self.region_name, stage_name=stage_name)
        stage_url_upper = STAGE_URL.format(api_id=self.id.upper(),
            region_name=self.region_name, stage_name=stage_name)

        responses.add_callback(responses.GET, stage_url_lower,
                               callback=self.resource_callback)
        responses.add_callback(responses.GET, stage_url_upper,
                               callback=self.resource_callback)
Exemple #3
0
    def update_integration_mocks(self, stage_name):
        stage_url_lower = STAGE_URL.format(api_id=self.id.lower(),
            region_name=self.region_name, stage_name=stage_name)
        stage_url_upper = STAGE_URL.format(api_id=self.id.upper(),
            region_name=self.region_name, stage_name=stage_name)

        responses.add_callback(responses.GET, stage_url_lower,
                               callback=self.resource_callback)
        responses.add_callback(responses.GET, stage_url_upper,
                               callback=self.resource_callback)
Exemple #4
0
    def enable_patching(self):
        responses.start()
        for method in RESPONSES_METHODS:
            for backend in self.backends_for_urls.values():
                for key, value in backend.urls.items():
                    responses.add_callback(
                        method=method,
                        url=re.compile(key),
                        callback=convert_flask_to_responses_response(value),
                    )

        for pattern in responses.mock._urls:
            pattern['stream'] = True
Exemple #5
0
    def enable_patching(self):
        responses.start()
        for method in RESPONSES_METHODS:
            for backend in self.backends_for_urls.values():
                for key, value in backend.urls.items():
                    responses.add_callback(
                        method=method,
                        url=re.compile(key),
                        callback=convert_flask_to_responses_response(value),
                    )

        for pattern in responses.mock._urls:
            pattern['stream'] = True
def test_publish_to_http():
    def callback(request):
        request.headers["Content-Type"].should.equal("application/json")
        json.loads.when.called_with(request.body).should_not.throw(Exception)
        return 200, {}, ""

    responses.add_callback(
        method="POST",
        url="http://example.com/foobar",
        callback=callback,
    )

    conn = boto3.client('sns', region_name='us-east-1')
    conn.create_topic(Name="some-topic")
    response = conn.list_topics()
    topic_arn = response["Topics"][0]['TopicArn']

    conn.subscribe(TopicArn=topic_arn,
                   Protocol="http",
                   Endpoint="http://example.com/foobar")

    response = conn.publish(
        TopicArn=topic_arn, Message="my message", Subject="my subject")
    message_id = response['MessageId']