Beispiel #1
0
    def test_get_connections(self):
        """
        TESTS: sadface.get_connections()
        """
        sf.initialise()

        # Test with a non-existant ID
        results = sf.get_connections("TESTID")
        self.assertEqual([], results)

        # Test with existing ID that we create with no connections
        source_atom = sf.add_atom("SOURCE")
        results = sf.get_connections(source_atom.get("id"))
        self.assertEqual([], results)

        # Test with existing ID + known added connections
        target_atom = sf.add_atom("TARGET")
        edge = sf.add_edge(source_atom.get("id"), target_atom.get("id"))

        results = sf.get_connections(source_atom.get("id"))
        self.assertNotEqual([], results)
        self.assertEqual(len(results), 1)
        self.assertEqual(edge.get("id"), results[0].get("id"))
        self.assertEqual(source_atom.get("id"), results[0].get("source_id"))
        self.assertEqual(target_atom.get("id"), results[0].get("target_id"))
Beispiel #2
0
    def test_get_edge(self):
        """
        TESTS: sadface.get_edge()
        """
        sf.initialise()
        source = sf.add_atom("source")
        target = sf.add_atom("target")
        edge = sf.add_edge(source.get("id"), target.get("id"))

        retrieved_edge = sf.get_edge(edge.get("id"))
        self.assertEqual(retrieved_edge.get("source_id"), source.get("id"))
        self.assertEqual(retrieved_edge.get("target_id"), target.get("id"))
        self.assertEqual(retrieved_edge.get("id"), edge.get("id"))
Beispiel #3
0
    def test_get_source(self):
        """
        TESTS: sadface.get_source()
        """
        sf.initialise()

        # Add an atom
        text = "DAKA DAKA"
        atom = sf.add_atom(text)
        atom_id = sf.contains_atom(text)

        # Add a resource
        resource_text = "test resource"
        resource = sf.add_resource(resource_text)
        resource_id = resource.get("id")

        s = sf.get_source(atom_id, resource_id)
        self.assertEqual(s, None)

        # Add source to the atom, referencing the resource
        offset = 5
        length = len(resource_text)
        sf.add_source(atom_id, resource_id, resource_text, offset, length)

        # Now retrieve the source and test it
        s = sf.get_source(atom_id, resource_id)
        self.assertEqual(s.get("resource_id"), resource_id)
        self.assertEqual(s.get("text"), resource_text)
        self.assertEqual(s.get("offset"), offset)
        self.assertEqual(s.get("length"), length)
Beispiel #4
0
    def test_add_atom_metadata(self):
        """
        TESTS: sadface.add_atom_metadata()
        """
        sf.initialise()

        # Add an atom
        atom_text = "test atom"
        atom = sf.add_atom(atom_text)
        atom_id = atom.get("id")

        # Check atom metadata is empty
        atom = sf.get_atom(atom_id)
        self.assertEqual(atom_id, atom.get("id"))
        meta = atom.get("metadata").get("core")
        self.assertEqual(0, len(meta))

        # add core metadata
        sf.add_atom_metadata(atom_id, "core", "KEY1", "VALUE1")
        atom = sf.get_atom(atom_id)
        meta = atom.get("metadata").get("core")
        self.assertNotEqual(0, len(meta))
        self.assertEqual("VALUE1", meta.get("KEY1"))

        # add metadata to new namespace
        sf.add_atom_metadata(atom_id, "META1", "KEY1", "VALUE1")
        atom = sf.get_atom(atom_id)
        meta = atom.get("metadata").get("META1")
        self.assertNotEqual(0, len(meta))
        self.assertEqual("VALUE1", meta.get("KEY1"))
Beispiel #5
0
    def test_get_atom_metadata(self):
        """
        TESTS: sadface.get_atom_metadata(atom_id, namespace=None, key=None)
        """
        sf.initialise()

        a = sf.add_atom("ATOM")
        sf.add_atom_metadata(a.get("id"), "TEST_NS", "TEST_KEY", "TEST_VAL")
        sf.add_atom_metadata(a.get("id"), "TEST_NS", "TEST_KEY2", "TEST_VA2")
        sf.add_atom_metadata(a.get("id"), "core", "TEST_KEY3", "TEST_VA3")

        expected = {
            'core': {
                'TEST_KEY3': 'TEST_VA3'
            },
            'TEST_NS': {
                'TEST_KEY': 'TEST_VAL',
                'TEST_KEY2': 'TEST_VA2'
            }
        }
        m = sf.get_atom_metadata(a.get("id"))
        self.assertEqual(expected, m)

        expected = {'TEST_KEY3': 'TEST_VA3'}
        m = sf.get_atom_metadata(a.get("id"), "core")
        self.assertEqual(expected, m)

        expected = {'TEST_KEY': 'TEST_VAL', 'TEST_KEY2': 'TEST_VA2'}
        m = sf.get_atom_metadata(a.get("id"), "TEST_NS")
        self.assertEqual(expected, m)

        expected = "TEST_VA2"
        m = sf.get_atom_metadata(a.get("id"), "TEST_NS", "TEST_KEY2")
        self.assertEqual(expected, m)
Beispiel #6
0
    def test_set_atom_text(self):
        """
        TESTS: sadface.set_atom_text()
        """
        sf.initialise()

        atom = sf.add_atom("DAKA DAKA")
        atom_id = atom.get("id")
        sf.set_atom_text(atom_id, "MORE DAKA")
        self.assertEqual(sf.get_atom_text(atom_id), "MORE DAKA")
Beispiel #7
0
    def test_delete_edge(self):
        """
        TESTS: sadface.delete_edge(edge_id)
        """
        sf.initialise()

        # Remove non-existing edge
        with self.assertRaises(ValueError):
            sf.delete_edge("TESTID")

        # Remove known existing atom
        source_atom = sf.add_atom("SOURCE")
        target_atom = sf.add_atom("TARGET")
        edge = sf.add_edge(source_atom.get("id"), target_atom.get("id"))
        retrieved = sf.get_edge(edge.get("id"))
        self.assertEqual(edge, retrieved)

        sf.delete_edge(edge.get("id"))
        retrieved = sf.get_edge(edge.get("id"))
        self.assertEqual(None, retrieved)
Beispiel #8
0
    def test_set_claim(self):
        """
        TESTS: sadface.set_claim()
        """
        sf.initialise()
        self.assertEqual(sf.get_claim(), None)

        atom = sf.add_atom("DAKA DAKA")
        atom_id = atom.get("id")
        sf.set_claim(atom_id)
        self.assertEqual(sf.get_claim(), atom_id)
Beispiel #9
0
def addPrompt(prompt):
    #set metadata
    #create sf doc
    sf.initialise()
    #add prompt statement
    sf.add_atom(prompt)
    #set prompt as claim
    sf.set_claim(sf.get_atom_id(prompt))
    #set title
    sf.set_title(prompt)

    #create file
    sfJSON = sf.export_json()
    fm.createFile(sfJSON)

    return None


#add vote
#argument = array with title and argument voted for
#returns status
Beispiel #10
0
    def test_get_atom(self):
        """
        TESTS: sadface.get_atom()
        """
        sf.initialise()
        self.assertEqual(sf.get_atom("unknown-id"), None)

        text = "DAKA DAKA"
        atom = sf.add_atom(text)
        atom_id = atom.get("id")
        result = sf.get_atom(atom_id)
        result_id = result.get("id")
        self.assertEqual(result_id, atom_id)
Beispiel #11
0
    def test_get_node(self):
        """
        TESTS: sadface.get_node()
        """
        sf.initialise()

        # Test with a non-existant ID
        result = sf.get_node("TEST")
        self.assertEqual(None, result)

        # Test with existin ID that we create
        atom = sf.add_atom("TESTATOM")
        result = sf.get_node(atom.get("id"))
        self.assertEqual(atom.get("id"), result.get("id"))
Beispiel #12
0
    def test_get_atom_text(self):
        """
        TESTS: sadface.get_atom_text()
        """
        sf.initialise()

        # Check behaviour when no atom to match against
        self.assertEqual(sf.get_atom_text("unknown-id"), None)

        # Add an atom, retrieve it by text content, and compare
        text = "DAKA DAKA"
        atom = sf.add_atom(text)
        atom_id = atom.get("id")
        retrieved_text = sf.get_atom_text(atom_id)
        self.assertEqual(retrieved_text, text)
Beispiel #13
0
    def test_contains_atom(self):
        """
        TESTS: sadface.contains_atom(atom_text)
        """
        sf.initialise()

        # Test Retrieving atom that doesn't exist
        self.assertEqual(None, sf.contains_atom("DAKA DAKA"))

        # Add new atom then test retrieving by text
        text = "DAKA DAKA"
        atom = sf.add_atom(text)
        atom_id = sf.contains_atom(text)
        retrieved_atom = sf.get_atom(atom_id)
        self.assertEqual(atom, retrieved_atom)
Beispiel #14
0
    def test_delete_atom(self):
        """
        TESTS: sadface.delete_atom(atom_id)
        """
        sf.initialise()

        # Remove non-existing atom
        with self.assertRaises(ValueError):
            sf.delete_atom("TESTID")

        # Remove known existing atom
        atom = sf.add_atom("TESTATOM")
        retrieved = sf.get_atom(atom.get("id"))
        self.assertEqual(atom, retrieved)
        sf.delete_atom(atom.get("id"))
        retrieved = sf.get_atom(atom.get("id"))
        self.assertEqual(None, retrieved)
Beispiel #15
0
    def test_delete_source(self):
        """
        TESTS: sadface.delete_source(atom_id, resource_id)
        """
        sf.initialise()

        # setup
        a = sf.add_atom("ATOM")
        r = sf.add_resource("hello")
        s = sf.add_source(a.get("id"), r.get("id"), "TEXT", 10, 4)

        # verify existing source
        retrieved = sf.get_source(a.get("id"), r.get("id"))
        self.assertEqual(s.get("id"), retrieved.get("id"))
        self.assertEqual(s, retrieved)

        # Delete source
        sf.delete_source(a.get("id"), r.get("id"))
        retrieved = sf.get_source(a.get("id"), r.get("id"))
        self.assertEqual(None, retrieved)
Beispiel #16
0
    def test_add_atom(self):
        """
        Tests: sadface.add_atom()
        """
        sf.initialise()

        # Check we have no atoms in the default document
        num_atoms = len(sf.list_atoms())
        self.assertEqual(num_atoms, 0)

        # Add an atom then check how many atoms we have
        atom_text = "test atom"
        atom = sf.add_atom(atom_text)
        atom_id = atom.get("id")
        num_atoms = len(sf.list_atoms())
        self.assertEqual(num_atoms, 1)

        # Retrieve the new atom and check that it
        # contains the expected text
        atom = sf.get_atom(atom_id)
        self.assertEqual(atom.get("text"), atom_text)