Beispiel #1
0
    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)
Beispiel #2
0
    def test_instantiate_from_RsParameters(self):
        paras = RsParameters()
        paras.metadata_dir = "test_instantiate_from_RsParameters"

        rs = ResourceSync(**paras.__dict__)
        self.assertEquals("test_instantiate_from_RsParameters",
                          rs.metadata_dir)
Beispiel #3
0
    def test_set_with_reflection(self):
        rsp = RsParameters()

        name = "resource_dir"
        try:
            setattr(rsp, name, "blaat")
        except ValueError as err:
            print(err)

        rsp.metadata_dir = "md1"
        name = "metadata_dir"
        x = getattr(rsp, name)
        print(x)
Beispiel #4
0
    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"
        )