class AddTicket(TestCase): def setUp(self): self.conf_struct = [ ConfigItem("site", "site1", []), ConfigItem("site", "site2", []), ConfigItem("arbitrator", "arbitrator1", []), ConfigItem("ticket", "ticketA", []), ] self.conf = ConfigFacade(self.conf_struct[:]) def test_add_no_options(self): self.conf.add_ticket("ticketB", {}) self.assertEqual( self.conf.config, self.conf_struct + [ ConfigItem("ticket", "ticketB", []), ], ) def test_add_with_options(self): self.conf.add_ticket("ticketB", {"timeout": "10"}) self.assertEqual( self.conf.config, self.conf_struct + [ ConfigItem("ticket", "ticketB", [ConfigItem("timeout", "10", [])]), ], )
class HasTicket(TestCase): def setUp(self): self.conf_struct = [ ConfigItem("site", "site1", []), ConfigItem("site", "site2", []), ConfigItem("arbitrator", "arbitrator1", []), ConfigItem("ticket", "ticketA", []), ConfigItem( "ticket", "ticketB", [ConfigItem("timeout", "10", [])] ), ] self.conf = ConfigFacade(self.conf_struct[:]) def test_ticket_exists(self): self.assertTrue(self.conf.has_ticket("ticketA")) self.assertTrue(self.conf.has_ticket("ticketB")) def test_ticket_missing(self): self.assertFalse(self.conf.has_ticket("ticketX")) def test_not_a_ticket(self): self.assertFalse(self.conf.has_ticket("site1")) self.assertFalse(self.conf.has_ticket("arbitrator1")) self.assertFalse(self.conf.has_ticket("timeout"))
def setUp(self): self.conf_struct = [ ConfigItem("site", "site1", []), ConfigItem("site", "site2", []), ConfigItem("arbitrator", "arbitrator1", []), ConfigItem("ticket", "ticketA", []), ] self.conf = ConfigFacade(self.conf_struct[:])
def test_add_authfile(self): conf = ConfigFacade(self.conf_struct_base + self.conf_struct_tickets) conf.set_authfile("/path/to/auth.file") self.assertEqual( conf.config, ([ConfigItem("authfile", "/path/to/auth.file", [])] + self.conf_struct_base + self.conf_struct_tickets), )
def setUp(self): self.conf_struct_base = [ ConfigItem("site", "site1", []), ConfigItem("site", "site2", []), ConfigItem("arbitrator", "arbitrator1", []), ] self.conf_struct_ticket_a = [ ConfigItem("ticket", "ticketA", []), ] self.conf_struct_ticket_b = [ ConfigItem("ticket", "ticketB", []), ] self.conf_struct = (self.conf_struct_base + self.conf_struct_ticket_a + self.conf_struct_ticket_b) self.conf = ConfigFacade(self.conf_struct[:])
def setUp(self): self.conf = ConfigFacade([ ConfigItem("site", "site1", []), ConfigItem("site", "site2", []), ConfigItem("arbitrator", "arbitrator1", []), ConfigItem("ticket", "ticketA", []), ConfigItem("ticket", "ticketB", []), ])
def test_read_failure(self, mock_read): key_name = "my_booth.key" mock_read.side_effect = RawFileError("mock file type", RawFileError.ACTION_READ, "some error") path = os.path.join(settings.booth_config_dir, key_name) conf = ConfigFacade.create([], []) conf.set_authfile(path) with self.assertRaises(RawFileError): config_files.get_authfile_name_and_data(conf)
def test_success(self, mock_read): key_data = "some key data".encode("utf-8") key_name = "my_booth.key" mock_read.return_value = key_data path = os.path.join(settings.booth_config_dir, key_name) conf = ConfigFacade.create([], []) conf.set_authfile(path) self.assertEqual( (key_name, key_data, []), config_files.get_authfile_name_and_data(conf), )
class RemoveTicket(TestCase): def setUp(self): self.conf_struct_base = [ ConfigItem("site", "site1", []), ConfigItem("site", "site2", []), ConfigItem("arbitrator", "arbitrator1", []), ] self.conf_struct_ticket_a = [ ConfigItem("ticket", "ticketA", []), ] self.conf_struct_ticket_b = [ ConfigItem("ticket", "ticketB", []), ] self.conf_struct = (self.conf_struct_base + self.conf_struct_ticket_a + self.conf_struct_ticket_b) self.conf = ConfigFacade(self.conf_struct[:]) def test_existing_ticket(self): self.conf.remove_ticket("ticketA") self.assertEqual(self.conf.config, self.conf_struct_base + self.conf_struct_ticket_b) def test_missing_ticket(self): self.conf.remove_ticket("ticketX") self.assertEqual(self.conf.config, self.conf_struct) def test_not_a_ticket(self): self.conf.remove_ticket("site1") self.assertEqual(self.conf.config, self.conf_struct)
def test_change_authfile(self): conf = ConfigFacade( self.conf_struct_base + [ ConfigItem("authfile", "/old/path/to/auth1.file", []), ConfigItem("authfile", "/old/path/to/auth2.file", []), ] + self.conf_struct_tickets ) conf.set_authfile("/path/to/auth.file") self.assertEqual( conf.config, ( [ConfigItem("authfile", "/path/to/auth.file", [])] + self.conf_struct_base + self.conf_struct_tickets ) )
def assert_path_check(self, path): conf = ConfigFacade.create([], []) conf.set_authfile(path) result = config_files.get_authfile_name_and_data(conf) self.assertEqual(result[0], None) self.assertEqual(result[1], None) assert_report_item_list_equal( result[2], [ fixture.warn( report_codes.BOOTH_UNSUPPORTED_FILE_LOCATION, file_type_code=file_type_codes.BOOTH_KEY, file_path=path, expected_dir=settings.booth_config_dir, ), ], )
def test_no_auth_file(self): conf = ConfigFacade.create([], []) self.assertEqual((None, None, []), config_files.get_authfile_name_and_data(conf))
def test_no_addrs(self): sites = [] arbitrators = [] conf = ConfigFacade.create(sites, arbitrators) self.assertEqual(sites, conf.get_sites()) self.assertEqual(arbitrators, conf.get_arbitrators())
def test_both(self): sites = ["1.1.1.1", "2.2.2.2", "3.3.3.3"] arbitrators = ["4.4.4.4", "5.5.5.5"] conf = ConfigFacade.create(sites, arbitrators) self.assertEqual(sites, conf.get_sites()) self.assertEqual(arbitrators, conf.get_arbitrators())
def test_arbitrators(self): sites = [] arbitrators = ["4.4.4.4", "5.5.5.5"] conf = ConfigFacade.create(sites, arbitrators) self.assertEqual(sites, conf.get_sites()) self.assertEqual(arbitrators, conf.get_arbitrators())