Beispiel #1
0
    def test_confirms(self, monkeypatch):
        data = {
            "Type": "SubscriptionConfirmation",
            "TopicArn": "This is a Topic!",
            "Token": "This is My Token",
        }

        aws_client = pretend.stub(
            confirm_subscription=pretend.call_recorder(lambda *a, **kw: None))
        aws_session = pretend.stub(
            client=pretend.call_recorder(lambda c, region_name: aws_client))

        request = pretend.stub(
            json_body=data,
            find_service=lambda name: {"aws.session": aws_session}[name],
            registry=pretend.stub(settings={"mail.region": "us-west-2"}),
        )

        verify_sns_message = pretend.call_recorder(lambda *a, **kw: None)
        monkeypatch.setattr(views, "_verify_sns_message", verify_sns_message)

        response = views.confirm_subscription(request)

        assert response.status_code == 200
        assert verify_sns_message.calls == [pretend.call(request, data)]
        assert aws_session.client.calls == [
            pretend.call("sns", region_name="us-west-2")
        ]
        assert aws_client.confirm_subscription.calls == [
            pretend.call(
                TopicArn=data["TopicArn"],
                Token=data["Token"],
                AuthenticateOnUnsubscribe="true",
            )
        ]
Beispiel #2
0
    def test_confirms(self, monkeypatch):
        data = {
            "Type": "SubscriptionConfirmation",
            "TopicArn": "This is a Topic!",
            "Token": "This is My Token",
        }

        aws_client = pretend.stub(
            confirm_subscription=pretend.call_recorder(lambda *a, **kw: None),
        )
        aws_session = pretend.stub(
            client=pretend.call_recorder(lambda c, region_name: aws_client),
        )

        request = pretend.stub(
            json_body=data,
            find_service=lambda name: {"aws.session": aws_session}[name],
            registry=pretend.stub(
                settings={
                    "mail.region": "us-west-2",
                },
            ),
        )

        verify_sns_message = pretend.call_recorder(lambda *a, **kw: None)
        monkeypatch.setattr(views, "_verify_sns_message", verify_sns_message)

        response = views.confirm_subscription(request)

        assert response.status_code == 200
        assert verify_sns_message.calls == [pretend.call(request, data)]
        assert aws_session.client.calls == [
            pretend.call("sns", region_name="us-west-2"),
        ]
        assert aws_client.confirm_subscription.calls == [
            pretend.call(
                TopicArn=data["TopicArn"],
                Token=data["Token"],
                AuthenticateOnUnsubscribe="true",
            ),
        ]
Beispiel #3
0
    def test_raises_when_invalid_type(self):
        request = pretend.stub(json_body={"Type": "Notification"})

        with pytest.raises(HTTPBadRequest):
            views.confirm_subscription(request)
Beispiel #4
0
    def test_raises_when_invalid_type(self):
        request = pretend.stub(json_body={"Type": "Notification"})

        with pytest.raises(HTTPBadRequest):
            views.confirm_subscription(request)