1 """ this tests the file_settings.py module """
17 class TestFileSettings(unittest.TestCase):
19 self._file = StringIO.StringIO(DEFAULT)
20 self._settings = file_settings.Settings(self._file)
22 def test_get_accounts(self):
23 """ Tests the get_accounts method under normal operation """
24 expected = {"11111": "aaaaaaaaa", "22222": "bbbbbbbbb"}
25 self.assertEqual(self._settings.get_accounts(), expected)
27 def test_get_accounts_empty(self):
28 """ Tet the get_accounts method when the config file is empty """
29 empty_settings = file_settings.Settings(None)
31 self.assertEqual(empty_settings.get_accounts(), expected)
33 def test_get_api_key(self):
34 """ Tests get_api_key for an existing key """
35 self.assertEqual(self._settings.get_api_key('11111'), "aaaaaaaaa")
37 def test_get_api_key_invalid(self):
38 """ Tests get_api_key when trying to get the key for a non-existing uid."""
39 self.assertRaises(Exception, self._settings.get_api_key, 'foo')
42 def test_add_account(self):
43 """ Test that adding an account adds it to the configObj AND the config file """
44 self._file.seek(0) # we have to do this, because we are using a StringIO object instead of a real file
45 self._settings.add_account("33333", "ccccccc")
46 self.assertEqual(self._settings.get_api_key("33333"), "ccccccc")
47 self.assertTrue('[[account.33333]]' in self._file.getvalue())
49 def test_remove_account(self):
50 """ Test that removing an account removes it from the configObj AND the config file """
51 self._file.seek(0) # we have to do this, because we are using a StringIO object instead of a real file
52 self._settings.remove_account("22222")
53 self.assertRaises(Exception, self._settings.get_api_key, '22222')
54 self.assertTrue('22222' not in self._settings.get_accounts().keys())
55 self.assertTrue("[[account.22222]]" not in self._file.getvalue())