def setUp(self): # Build up a mocked extension self.extension = Mock() self.extension.registration = Mock() self.test_dict = { 'test_key1': 'test_value1', 'test_key2': 'test_value2', } self.extension.registration.settings = self.test_dict self.settings = Settings(self.extension)
def setUp(self): # Build up a mocked extension self.extension = Mock() self.extension.registration = Mock() self.test_dict = {"test_key1": "test_value1", "test_key2": "test_value2"} self.extension.registration.settings = self.test_dict self.settings = Settings(self.extension)
class SettingsTest(TestCase): def setUp(self): # Build up a mocked extension self.extension = Mock() self.extension.registration = Mock() self.test_dict = { 'test_key1': 'test_value1', 'test_key2': 'test_value2', } self.extension.registration.settings = self.test_dict self.settings = Settings(self.extension) def test_constructor(self): """Testing the Extension's Settings constructor""" # Build the Settings objects self.assertEqual(self.extension, self.settings.extension) # Ensure that the registration settings dict gets # added to this Settings self.assertEqual(self.test_dict['test_key1'], self.settings['test_key1']) def test_load_updates_dict(self): """Testing that Settings.load correctly updates core dict""" new_dict = { 'test_new_key': 'test_new_value', 'test_key1': 'new_value', } self.extension.registration.settings = new_dict self.settings.load() # Should have added test_new_key, and modified test_key1 self.assertEqual(new_dict['test_new_key'], self.settings['test_new_key']) self.assertEqual(new_dict['test_key1'], self.settings['test_key1']) # Should have left test_key2 alone self.assertEqual(self.test_dict['test_key2'], self.settings['test_key2']) def test_load_silently_discards(self): """Testing that Settings.load silently ignores invalid settings""" some_string = 'This is a string' self.extension.registration.settings = some_string try: self.settings.load() except Exception: self.fail("Shouldn't have raised an exception") def test_save_updates_database(self): """Testing that Settings.save will correctly update registration""" registration = self.extension.registration self.settings['test_new_key'] = 'Test new value' generated_dict = dict(self.settings) self.settings.save() self.assertTrue(registration.save.called) self.assertEqual(generated_dict, registration.settings)