class TestAWSBasePlugin(BaseTestCase):
    def afterSetUp(self):
        from ZenPacks.zenoss.AWS.dsplugins import AWSBasePlugin
        self.plugin = AWSBasePlugin()

    def test_params_empty(self):
        ds = Mock()
        # method will rise TypeError when called with two args
        ds.talesEval = lambda x: None

        self.assertEquals(self.plugin.params(ds, Mock()), {})

    def test_params_region(self):
        ds = Mock()
        ds.talesEval = lambda x, y: sentinel.region

        self.assertEquals(
            self.plugin.params(ds, Mock()),
            {'region': sentinel.region}
        )

    def test_onSuccess(self):
        result = self.plugin.new_data()
        result['values'] = {'c1': 1, 'c2': 2}
        result['events'] = []

        res = self.plugin.onSuccess(result, sentinel.any_value)

        self.assertEquals(len(result['events']), 2)
        self.assertEquals(
            result['events'][0]['severity'],
            ZenEventClasses.Clear
        )
        self.assertEquals(result['events'][1]['eventClass'], '/Status')

    @patch('ZenPacks.zenoss.AWS.dsplugins.log')
    def test_onError(self, log):
        error = Mock()
        error.type = "test"
        e = self.plugin.onError(error, sentinel.anything)

        self.assertEquals(len(e['events']), 1)
        self.assertEquals(e['events'][0]['severity'], ZenEventClasses.Error)

    @patch('ZenPacks.zenoss.AWS.dsplugins.log')
    def test_onErrorMessage(self, log):
        config = Mock()
        ds = Mock()
        config.datasources = [ds]
        self.plugin.component = 'world'

        e = self.plugin.onError('<Message>Hello</Message> world', config)

        self.assertEquals(len(e['events']), 1)
        e = e['events'][0]
        self.assertEquals(e['severity'], ZenEventClasses.Info)
 def afterSetUp(self):
     from ZenPacks.zenoss.AWS.dsplugins import AWSBasePlugin
     self.plugin = AWSBasePlugin()