def test_main(self, mock_cache, mock_failgracefully): #allow main to use getsitelist #Pontpandy shouldn't be found, and a message should be displayed saying so mock_cache.return_value.__enter__.return_value.get = Mock( side_effect=self.mock_get) mock_failgracefully.side_effect = lambda f: f self.xbmc.Keyboard.return_value.getText = Mock( return_value='Pontypandy') self.xbmc.Keyboard.return_value.isConfirmed = Mock(return_value=True) from metoffice import setlocation setlocation.main('ForecastLocation') self.assertTrue(self.xbmcgui.Dialog.return_value.ok.called) #Rosehearty Samos should be found given search text 'hearty' self.xbmc.Keyboard.return_value.getText = Mock(return_value='hearty') self.xbmcgui.Dialog.return_value.select = Mock(return_value=0) setlocation.main('ForecastLocation') self.assertTrue(self.xbmcgui.Dialog.return_value.select.called) expected = [(('ForecastLocation', 'Rosehearty Samos'), ), (('ForecastLocationID', '3094'), ), (('ForecastLocationLatitude', '57.698'), ), (('ForecastLocationLongitude', '-2.121'), )] self.assertEqual( expected, self.xbmcaddon.Addon.return_value.setSetting.call_args_list)
def test_noapikey(self, mock_failgracefully): mock_failgracefully.side_effect = lambda f: f from metoffice import setlocation setlocation.API_KEY = '' setlocation._ = lambda x : x with self.assertRaises(Exception) as cm: setlocation.main('ForecastLocation') self.assertEqual(('No API Key.', 'Enter your Met Office API Key under settings.',), cm.exception.args)
def test_noapikey(self, mock_failgracefully): mock_failgracefully.side_effect = lambda f: f from metoffice import setlocation setlocation.API_KEY = '' setlocation._ = lambda x: x with self.assertRaises(Exception) as cm: setlocation.main('ForecastLocation') self.assertEqual(( 'No API Key.', 'Enter your Met Office API Key under settings.', ), cm.exception.args)
def test_main(self, mock_cache, mock_failgracefully): #allow main to use getsitelist #Pontpandy shouldn't be found, and a message should be displayed saying so mock_cache.return_value.__enter__.return_value.get = Mock(side_effect=self.mock_get) mock_failgracefully.side_effect = lambda f: f self.xbmc.Keyboard.return_value.getText = Mock(return_value='Pontypandy') self.xbmc.Keyboard.return_value.isConfirmed = Mock(return_value=True) from metoffice import setlocation setlocation.main('ForecastLocation') self.assertTrue(self.xbmcgui.Dialog.return_value.ok.called) #Rosehearty Samos should be found given search text 'hearty' self.xbmc.Keyboard.return_value.getText = Mock(return_value='hearty') self.xbmcgui.Dialog.return_value.select = Mock(return_value = 0) setlocation.main('ForecastLocation') self.assertTrue(self.xbmcgui.Dialog.return_value.select.called) expected = [(('ForecastLocation', 'Rosehearty Samos'),), (('ForecastLocationID', '3094'),), (('ForecastLocationLatitude', '57.698'),), (('ForecastLocationLongitude', '-2.121'),)] self.assertEqual(expected, self.xbmcaddon.Addon.return_value.setSetting.call_args_list)