Exemplo n.º 1
0
    def test_parse(self):
        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse([{'ClusterStates': 'terminated'}])
        self.assertEqual(x[0].query(), {
            'Name': 'ClusterStates',
            'Values': ['terminated']
        })

        # Test consolidation of multiple values for query
        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse([{
            'ClusterStates': 'terminated'
        }, {
            'ClusterStates': 'running'
        }, {
            'ClusterStates': 'waiting'
        }])
        self.assertEqual(x[0].query(), {
            'Name': 'ClusterStates',
            'Values': ['terminated']
        })
        self.assertEqual(x[1].query(), {
            'Name': 'ClusterStates',
            'Values': ['running']
        })
        self.assertEqual(x[2].query(), {
            'Name': 'ClusterStates',
            'Values': ['waiting']
        })

        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse([{'CreatedBefore': 1470968567.05}])
        self.assertEqual(x[0].query(), {
            'Name': 'CreatedBefore',
            'Values': 1470968567.05
        })

        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse([{'CreatedAfter': 1470974021.557}])
        self.assertEqual(x[0].query(), {
            'Name': 'CreatedAfter',
            'Values': 1470974021.557
        })

        self.assertTrue(
            isinstance(
                QueryFilter.parse([{
                    'tag:ASV': 'REALTIMEMSG'
                }])[0], QueryFilter))

        self.assertRaises(ValueError, QueryFilter.parse, [{'tag:ASV': None}])

        self.assertRaises(ValueError, QueryFilter.parse, [{'foo': 'bar'}])

        self.assertRaises(ValueError, QueryFilter.parse, [{
            'too': 'many',
            'keys': 'error'
        }])

        self.assertRaises(ValueError, QueryFilter.parse, ['Not a dictionary'])
Exemplo n.º 2
0
    def test_parse(self):
        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse(
            [{'ClusterStates': 'terminated'}])
        self.assertEqual(
            x[0].query(),
            {'Name': 'ClusterStates', 'Values': ['terminated']})

        # Test consolidation of multiple values for query
        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse(
            [{'ClusterStates': 'terminated'},
             {'ClusterStates': 'running'},
             {'ClusterStates': 'waiting'}])
        self.assertEqual(
            x[0].query(),
            {'Name': 'ClusterStates', 'Values': ['terminated']})
        self.assertEqual(
            x[1].query(),
            {'Name': 'ClusterStates', 'Values': ['running']})
        self.assertEqual(
            x[2].query(),
            {'Name': 'ClusterStates', 'Values': ['waiting']})

        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse(
            [{'CreatedBefore': 1470968567.05}])
        self.assertEqual(
            x[0].query(),
            {'Name': 'CreatedBefore', 'Values': 1470968567.05})

        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse(
            [{'CreatedAfter': 1470974021.557}])
        self.assertEqual(
            x[0].query(),
            {'Name': 'CreatedAfter', 'Values': 1470974021.557})

        self.assertTrue(
            isinstance(
                QueryFilter.parse(
                    [{'tag:ASV': 'REALTIMEMSG'}])[0],
                QueryFilter))

        self.assertRaises(
            ValueError,
            QueryFilter.parse,
            [{'tag:ASV': None}])

        self.assertRaises(
            ValueError,
            QueryFilter.parse,
            [{'foo': 'bar'}])
Exemplo n.º 3
0
    def test_parse(self):
        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse([{"ClusterStates": "terminated"}])
        self.assertEqual(
            x[0].query(), {"Name": "ClusterStates", "Values": ["terminated"]}
        )

        # Test consolidation of multiple values for query
        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse(
            [
                {"ClusterStates": "terminated"},
                {"ClusterStates": "running"},
                {"ClusterStates": "waiting"},
            ]
        )
        self.assertEqual(
            x[0].query(), {"Name": "ClusterStates", "Values": ["terminated"]}
        )
        self.assertEqual(x[1].query(), {"Name": "ClusterStates", "Values": ["running"]})
        self.assertEqual(x[2].query(), {"Name": "ClusterStates", "Values": ["waiting"]})

        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse([{"CreatedBefore": 1470968567.05}])
        self.assertEqual(
            x[0].query(), {"Name": "CreatedBefore", "Values": 1470968567.05}
        )

        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse([{"CreatedAfter": 1470974021.557}])
        self.assertEqual(
            x[0].query(), {"Name": "CreatedAfter", "Values": 1470974021.557}
        )

        self.assertTrue(
            isinstance(QueryFilter.parse([{"tag:ASV": "REALTIMEMSG"}])[0], QueryFilter)
        )

        self.assertRaises(PolicyValidationError, QueryFilter.parse, [{"tag:ASV": None}])

        self.assertRaises(PolicyValidationError, QueryFilter.parse, [{"foo": "bar"}])

        self.assertRaises(
            PolicyValidationError, QueryFilter.parse, [{"too": "many", "keys": "error"}]
        )

        self.assertRaises(PolicyValidationError, QueryFilter.parse, ["Not a dictionary"])
Exemplo n.º 4
0
    def test_parse(self):
        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse([{"ClusterStates": "terminated"}])
        self.assertEqual(
            x[0].query(), {"Name": "ClusterStates", "Values": ["terminated"]}
        )

        # Test consolidation of multiple values for query
        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse(
            [
                {"ClusterStates": "terminated"},
                {"ClusterStates": "running"},
                {"ClusterStates": "waiting"},
            ]
        )
        self.assertEqual(
            x[0].query(), {"Name": "ClusterStates", "Values": ["terminated"]}
        )
        self.assertEqual(x[1].query(), {"Name": "ClusterStates", "Values": ["running"]})
        self.assertEqual(x[2].query(), {"Name": "ClusterStates", "Values": ["waiting"]})

        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse([{"CreatedBefore": 1470968567.05}])
        self.assertEqual(
            x[0].query(), {"Name": "CreatedBefore", "Values": 1470968567.05}
        )

        self.assertEqual(QueryFilter.parse([]), [])
        x = QueryFilter.parse([{"CreatedAfter": 1470974021.557}])
        self.assertEqual(
            x[0].query(), {"Name": "CreatedAfter", "Values": 1470974021.557}
        )

        self.assertTrue(
            isinstance(QueryFilter.parse([{"tag:ASV": "REALTIMEMSG"}])[0], QueryFilter)
        )

        self.assertRaises(PolicyValidationError, QueryFilter.parse, [{"tag:ASV": None}])

        self.assertRaises(PolicyValidationError, QueryFilter.parse, [{"foo": "bar"}])

        self.assertRaises(
            PolicyValidationError, QueryFilter.parse, [{"too": "many", "keys": "error"}]
        )

        self.assertRaises(PolicyValidationError, QueryFilter.parse, ["Not a dictionary"])