示例#1
0
    def test_add_scheme_metadata(self):
        """
        TESTS: sadface.add_scheme_metadata()
        """
        sf.initialise()

        # Add an scheme
        scheme_text = "test scheme"
        scheme = sf.add_scheme(scheme_text)
        scheme_id = scheme.get("id")

        # Check scheme metadata is empty
        scheme = sf.get_scheme(scheme_id)
        self.assertEqual(scheme_id, scheme.get("id"))
        meta = scheme.get("metadata").get("core")
        self.assertEqual(0, len(meta))

        # add core metadata
        sf.add_scheme_metadata(scheme_id, "core", "KEY1", "VALUE1")
        scheme = sf.get_scheme(scheme_id)
        meta = scheme.get("metadata").get("core")
        self.assertNotEqual(0, len(meta))
        self.assertEqual("VALUE1", meta.get("KEY1"))

        # add metadata to new namespace
        sf.add_scheme_metadata(scheme_id, "META1", "KEY1", "VALUE1")
        scheme = sf.get_scheme(scheme_id)
        meta = scheme.get("metadata").get("META1")
        self.assertNotEqual(0, len(meta))
        self.assertEqual("VALUE1", meta.get("KEY1"))
示例#2
0
    def test_get_scheme(self):
        """
        TESTS: sadface.get_scheme() after a scheme has been added
        """
        sf.initialise()
        scheme_node = sf.add_scheme("test-scheme")
        scheme_node_id = scheme_node.get("id")

        result = sf.get_scheme(scheme_node_id)
        self.assertEqual(result.get("id"), scheme_node_id)
        self.assertEqual(result.get("text"), scheme_node.get("text"))
示例#3
0
    def test_set_scheme_name(self):
        """
        """
        sf.initialise()

        # Test setting non-existent scheme
        with self.assertRaises(Exception) as context:
            sf.set_scheme_name("TEST_ID", "TEST_NAME")
        out = str(context.exception)
        expected = 'Could not set the name of scheme: TEST_ID'
        self.assertEqual(out, expected)

        test_name = "TEST_SCHEME"
        s = sf.add_scheme(test_name)
        retrieved = sf.get_scheme(s.get("id"))
        self.assertEqual(s.get("name"), retrieved.get("name"))

        new_scheme_name = "NEW_SCHEME_NAME"
        sf.set_scheme_name(s.get("id"), new_scheme_name)
        retrieved = sf.get_scheme(s.get("id"))
        self.assertEqual(new_scheme_name, retrieved.get("name"))
示例#4
0
    def test_delete_scheme(self):
        """
        """
        sf.initialise()

        # Remove non-existing scheme
        with self.assertRaises(ValueError):
            sf.delete_scheme("FAKE_ID")

        # Remove existing scheme
        s = sf.add_scheme("TEST_SCHEME_NAME")
        retrieved = sf.get_scheme(s.get("id"))
        self.assertEqual(s, retrieved)
示例#5
0
    def test_add_scheme(self):
        """
        TESTS: sadface.add_scheme() wit default values

        Add a scheme, retrieve it, ensure that the retrieved
        scheme matches that which was added
        """
        sf.initialise()
        scheme = sf.add_scheme("test scheme")
        scheme_id = scheme.get("id")
        result = sf.get_scheme(scheme_id)
        result_id = result.get("id")
        self.assertEqual(result_id, scheme_id)