Ejemplo n.º 1
0
import nose
import sys

if sys.version_info[0] == 2 and sys.version_info[1] == 6:
    # This can be removed when we can use latest Httpretty again
    def mock_sqs(func):
        def wrapped(*args):
            raise nose.SkipTest("No moto support for python2.6 atm")
        return wrapped
else:
    from moto import mock_sqs

describe BespinCase, "Decode Message":
    it "successfully decode a valid message":
        raw_message = "success:i-aaaaaaa:rca_contract-628-3b55f412b3016a2b955c49677e89f7e010f7fdc8"
        decoded_message = Message.decode(raw_message)
        self.assertEqual(decoded_message.result, "success")
        self.assertEqual(decoded_message.instance_id, "i-aaaaaaa")
        self.assertEqual(decoded_message.output, "rca_contract-628-3b55f412b3016a2b955c49677e89f7e010f7fdc8")

    it "can not decode a valid message":
        raw_message = "success:i-aaaaaaadsfsdfsdontract-628-3b55f412b3016a2b955c49677e89f7e010f7fdc8"
        with self.fuzzyAssertRaisesError(BadSQSMessage, "Less than two colons", msg=raw_message):
            Message.decode(raw_message)

describe BespinCase, "SQS":
    describe "get_all_deployment_messages":
        it "times out and returns nothing if we never get any messages":
            sqs = SQS()
            conn = mock.Mock(name="conn")
            conn.get_queue.return_value = mock.Mock(name="queue", count=lambda: 0)
Ejemplo n.º 2
0
import nose
import sys

if sys.version_info[0] == 2 and sys.version_info[1] == 6:
    # This can be removed when we can use latest Httpretty again
    def mock_sqs_deprecated(func):
        def wrapped(*args):
            raise nose.SkipTest("No moto support for python2.6 atm")
        return wrapped
else:
    from moto import mock_sqs_deprecated

describe BespinCase, "Decode Message":
    it "successfully decode a valid message":
        raw_message = "success:i-aaaaaaa:rca_contract-628-3b55f412b3016a2b955c49677e89f7e010f7fdc8"
        decoded_message = Message.decode(raw_message)
        self.assertEqual(decoded_message.result, "success")
        self.assertEqual(decoded_message.instance_id, "i-aaaaaaa")
        self.assertEqual(decoded_message.output, "rca_contract-628-3b55f412b3016a2b955c49677e89f7e010f7fdc8")

    it "can not decode a valid message":
        raw_message = "success:i-aaaaaaadsfsdfsdontract-628-3b55f412b3016a2b955c49677e89f7e010f7fdc8"
        with self.fuzzyAssertRaisesError(BadSQSMessage, "Less than two colons", msg=raw_message):
            Message.decode(raw_message)

describe BespinCase, "SQS":
    describe "get_all_deployment_messages":
        it "times out and returns nothing if we never get any messages":
            sqs = SQS()
            conn = mock.Mock(name="conn")
            conn.get_queue.return_value = mock.Mock(name="queue", count=lambda: 0)
Ejemplo n.º 3
0
            self.assertEqual(sleeps, [15] * 3)

        it "raises BadStack if it timesout":
            requests_get = mock.Mock(name="get", side_effect=lambda url: mock.Mock(name="response", text="whatever"))
            sleep = mock.Mock(name='sleep', side_effect=lambda amount: None)

            with self.fuzzyAssertRaisesError(BadStack, "Timedout waiting for the app to give back the correct version"):
                with mock.patch("time.sleep", sleep):
                    with mock.patch("requests.get", requests_get):
                        checker = self.make_checker(expect="blah*", endpoint="http://somewhere.com/", check_url="/diagnostic/version", timeout_after=0)
                        checker.wait({})

describe BespinCase, "SNSConfirmation":
    describe "wait":
        it "succeeds if we get messages for all the instances with the correct version":
            message1 = Message.decode("success:i-1:blah-9")
            message2 = Message.decode("success:i-2:blah-9")
            message3 = Message.decode("success:i-3:blah-9")
            message4 = Message.decode("success:i-4:blah-9")
            messages = [message1, message2, message3, message4]

            sqs = mock.Mock(name="sqs")
            sqs.get_all_deployment_messages.return_value = messages
            queue = mock.Mock(name="queue")
            queue.format.return_value = queue

            confirmation = SNSConfirmation(version_message="{VAR}*", deployment_queue=queue)
            confirmation.wait(["i-1", "i-2", "i-3", "i-4"], {"VAR": "blah"}, sqs)

            sqs.get_all_deployment_messages.assert_called_once_with(queue)