コード例 #1
0
    def test_invalid(self, monkeypatch):
        class FakeMessageVerifier:
            @staticmethod
            @pretend.call_recorder
            def __init__(topics, session):
                self.topics = topics
                self.session = session

            @staticmethod
            @pretend.call_recorder
            def verify(message):
                raise views.sns.InvalidMessage("This is an Invalid Message")

        monkeypatch.setattr(views.sns, "MessageVerifier", FakeMessageVerifier)

        request = pretend.stub(
            http=pretend.stub(),
            registry=pretend.stub(settings={
                "mail.topic": "this is a topic",
            }, ),
        )
        message = pretend.stub()

        with pytest.raises(HTTPBadRequest, match="This is an Invalid Message"):
            views._verify_sns_message(request, message)

        assert FakeMessageVerifier.__init__.calls == [
            pretend.call(topics=["this is a topic"], session=request.http),
        ]
        assert FakeMessageVerifier.verify.calls == [pretend.call(message)]
コード例 #2
0
ファイル: test_views.py プロジェクト: mbacchi/warehouse
    def test_invalid(self, monkeypatch):
        class FakeMessageVerifier:

            @staticmethod
            @pretend.call_recorder
            def __init__(topics, session):
                self.topics = topics
                self.session = session

            @staticmethod
            @pretend.call_recorder
            def verify(message):
                raise views.sns.InvalidMessage("This is an Invalid Message")

        monkeypatch.setattr(views.sns, "MessageVerifier", FakeMessageVerifier)

        request = pretend.stub(
            http=pretend.stub(),
            registry=pretend.stub(
                settings={
                    "mail.topic": "this is a topic",
                },
            ),
        )
        message = pretend.stub()

        with pytest.raises(HTTPBadRequest, match="This is an Invalid Message"):
            views._verify_sns_message(request, message)

        assert FakeMessageVerifier.__init__.calls == [
            pretend.call(topics=["this is a topic"], session=request.http),
        ]
        assert FakeMessageVerifier.verify.calls == [pretend.call(message)]
コード例 #3
0
ファイル: test_views.py プロジェクト: anzhaozhong/warehouse
    def test_valid(self, monkeypatch):
        class FakeMessageVerifier:
            @staticmethod
            @pretend.call_recorder
            def __init__(topics, session):
                self.topics = topics
                self.session = session

            @staticmethod
            @pretend.call_recorder
            def verify(message):
                pass

        monkeypatch.setattr(views.sns, "MessageVerifier", FakeMessageVerifier)

        request = pretend.stub(
            http=pretend.stub(),
            registry=pretend.stub(settings={"mail.topic": "this is a topic"}),
        )
        message = pretend.stub()

        views._verify_sns_message(request, message)

        assert FakeMessageVerifier.__init__.calls == [
            pretend.call(topics=["this is a topic"], session=request.http)
        ]
        assert FakeMessageVerifier.verify.calls == [pretend.call(message)]
コード例 #4
0
ファイル: test_views.py プロジェクト: craig5/warehouse
    def test_valid(self, monkeypatch):
        class FakeMessageVerifier:
            @staticmethod
            @pretend.call_recorder
            def __init__(topics, session):
                self.topics = topics
                self.session = session

            @staticmethod
            @pretend.call_recorder
            def verify(message):
                pass

        monkeypatch.setattr(views.sns, "MessageVerifier", FakeMessageVerifier)

        request = pretend.stub(
            http=pretend.stub(),
            registry=pretend.stub(settings={"mail.topic": "this is a topic"}),
        )
        message = pretend.stub()

        views._verify_sns_message(request, message)

        assert FakeMessageVerifier.__init__.calls == [
            pretend.call(topics=["this is a topic"], session=request.http)
        ]
        assert FakeMessageVerifier.verify.calls == [pretend.call(message)]