def test_metadata_dir(self): user_home = os.path.expanduser("~") # defaults to configuration defaults Configuration().core_clear() rsp = RsParameters() self.assertEquals("metadata", rsp.metadata_dir) self.assertEquals(rsp.abs_metadata_dir(), os.path.join(user_home, "metadata")) resource_dir = user_home rsp = RsParameters(metadata_dir=os.path.join("foo", "md1"), resource_dir=resource_dir) # print(rsp.abs_metadata_dir()) self.assertEquals(rsp.abs_metadata_dir(), os.path.join(resource_dir, "foo", "md1")) # @ToDo test for windows pathnames: 'foo\md1', 'C:foo\bar\baz' here = os.path.dirname(__file__) rsp.resource_dir = here self.assertEquals(rsp.abs_metadata_dir(), os.path.join(here, "foo", "md1")) # contamination test rsp2 = RsParameters(**rsp.__dict__) self.assertEquals(rsp2.abs_metadata_dir(), os.path.join(here, "foo", "md1")) with self.assertRaises(Exception) as context: rsp.metadata_dir = os.path.expanduser("~") # print(context.exception) self.assertEquals( "Invalid value for metadata_dir: path should not be absolute: " + os.path.expanduser("~"), context.exception.args[0]) self.assertIsInstance(context.exception, ValueError) with self.assertRaises(Exception) as context: rsp.metadata_dir = "/foo/bar" # print(context.exception) self.assertEquals( "Invalid value for metadata_dir: path should not be absolute: /foo/bar", context.exception.args[0]) self.assertIsInstance(context.exception, ValueError) # cannot check if metadata_dir will be a directory, because relative to resource_dir # this = os.path.basename(__file__) # with self.assertRaises(Exception) as context: # rsp.metadata_dir = this # #print(context.exception) # self.assertIsInstance(context.exception, ValueError) self.save_configuration_test(rsp)
def test_current_description_url(self): rsp = RsParameters(url_prefix="http://example.com/bla/foo/bar") rsp.has_wellknown_at_root = True self.assertEquals(rsp.description_url(), "http://example.com/.well-known/resourcesync") rsp.has_wellknown_at_root = False rsp.resource_dir = os.path.expanduser("~") rsp.metadata_dir = "some/path/md10" self.assertEquals( rsp.description_url(), "http://example.com/bla/foo/bar/some/path/md10/.well-known/resourcesync" )
def test_resource_dir(self): user_home = os.path.expanduser("~") # defaults to configuration defaults Configuration().core_clear() rsp = RsParameters() self.assertEquals(rsp.resource_dir, user_home + os.sep) resource_dir = user_home rsp = RsParameters(resource_dir=resource_dir) self.assertEquals(rsp.resource_dir, resource_dir + os.sep) # contamination test rsp2 = RsParameters(**rsp.__dict__) self.assertEquals(rsp2.resource_dir, resource_dir + os.sep) assert (rsp.__dict__ == rsp2.__dict__) with self.assertRaises(Exception) as context: rsp.resource_dir = "/foo/bar" #print(context.exception) self.assertIsInstance(context.exception, ValueError) self.save_configuration_test(rsp)