Exemplo n.º 1
0
    def test_create_tag_for_asg_deletion_delta_correct(self):
        # Python built-in types are immutable so we can't use @mock.patch
        class NewDateTime(datetime.datetime):
            """
            Stub class for mocking datetime.
            """
            @classmethod
            def utcnow(cls):
                """
                Stub method returning a UTC datetime.
                """
                return cls(2016, 5, 18, 1, 0, 0, 0)

        built_in_datetime = ec2.datetime

        # The instance of datetime becomes local to the module it's import in to. We must patch datetime using the
        # module instance that is imported in to the ec2 module.
        ec2.datetime = NewDateTime

        asg_name = "test-asg-tags"
        tag = ec2.create_tag_for_asg_deletion(asg_name, 10)
        self.assertEqual(
            tag.value,
            datetime.datetime(2016, 5, 18, 1, 0, 10, 0).isoformat())
        tag = ec2.create_tag_for_asg_deletion(asg_name, 300)
        self.assertEqual(
            tag.value,
            datetime.datetime(2016, 5, 18, 1, 5, 0, 0).isoformat())

        # Undo the monkey patch
        ec2.datetime = built_in_datetime
Exemplo n.º 2
0
    def test_create_tag_for_asg_deletion_delta_correct(self):
        # Python built-in types are immutable so we can't use @mock.patch
        class NewDateTime(datetime.datetime):
            """
            Stub class for mocking datetime.
            """
            @classmethod
            def utcnow(cls):
                """
                Stub method returning a UTC datetime.
                """
                return cls(2016, 5, 18, 01, 00, 00, 000000)
        built_in_datetime = ec2.datetime

        # The instance of datetime becomes local to the module it's import in to. We must patch datetime using the
        # module instance that is imported in to the ec2 module.
        ec2.datetime = NewDateTime

        asg_name = "test-asg-tags"
        tag = ec2.create_tag_for_asg_deletion(asg_name, 10)
        self.assertEqual(tag.value, datetime.datetime(2016, 5, 18, 01, 00, 10, 000000).isoformat())
        tag = ec2.create_tag_for_asg_deletion(asg_name, 300)
        self.assertEqual(tag.value, datetime.datetime(2016, 5, 18, 01, 05, 00, 000000).isoformat())

        # Undo the monkey patch
        ec2.datetime = built_in_datetime
Exemplo n.º 3
0
    def test_create_tag_for_asg_deletion(self):
        asg_name = "test-asg-tags"
        tag = ec2.create_tag_for_asg_deletion(asg_name, 1)

        self.assertEqual(tag.key, ec2.ASG_DELETE_TAG_KEY)
        self.assertEqual(tag.resource_id, asg_name)
        self.assertFalse(tag.propagate_at_launch)
        datetime.datetime.strptime(tag.value, ec2.ISO_DATE_FORMAT)
Exemplo n.º 4
0
    def test_create_tag_for_asg_deletion(self):
        asg_name = "test-asg-tags"
        tag = ec2.create_tag_for_asg_deletion(asg_name, 1)

        self.assertEqual(tag.key, ec2.ASG_DELETE_TAG_KEY)
        self.assertEqual(tag.resource_id, asg_name)
        self.assertFalse(tag.propagate_at_launch)
        datetime.datetime.strptime(tag.value, ec2.ISO_DATE_FORMAT)