class EndpointTestCase(unittest.TestCase): def setUp(self): self.config = Config("local_test_config.ini", default_manager=ISQLWrapperTestManager()) def tearDown(self): self.config.save("local_test_config.ini")
def test_setted_value_saved(self): "Reproduce BUG: manually asigned values ares not saved to ini file." config = Config("fixtures/config1.ini") config.SectionA.new_var = "new_value" filename = "generated_config.ini" config.save(filename) saved_config = Config(filename) self.assertEqual("new_value", saved_config.SectionA.new_var)
class DataTestCase(unittest.TestCase): def setUp(self): self.config = Config("local_test_config.ini", default_manager=ISQLWrapperTestManager()) url = "http://%s:%s%s" url %= (self.config.host, self.config.endpoint_port, self.config.endpoint_path) self.endpoint = Endpoint(url) self.isql = ISQLWrapper(self.config.host, self.config.user, self.config.password) self.isql.execute_cmd("SPARQL CLEAR GRAPH <%s>" % self.config.graph) def assertGraphHasNumberOfTriples(self, n): sparql_query = "SELECT * FROM <%s> WHERE {?s ?p ?o}" % self.config.graph results = self.endpoint.query(sparql_query) self.assertEquals(results.total_rows, n) def assertGraphIsEmpty(self): self.assertGraphHasNumberOfTriples(0) def tearDown(self): self.config.save("local_test_config.ini") self.isql.execute_cmd("SPARQL CLEAR GRAPH <%s>" % self.config.graph) def test_delete_uri(self): "Inserts a triple into the triplestore" ns = Namespace("https://github.com/juanique/artichoke/ns#") graph = self.config.graph self.assertGraphIsEmpty() self.isql.insert(graph, ns["subject"], ns["predicate"], ns["object"]) self.isql.delete(graph, ns["subject"], ns["predicate"], ns["object"]) self.assertGraphIsEmpty() def test_delete_literal(self): "Inserts a triple into the triplestore" ns = Namespace("https://github.com/juanique/artichoke/ns#") graph = self.config.graph self.assertGraphIsEmpty() self.isql.insert(graph, ns["subject"], ns["predicate"], Literal("Hello")) self.isql.delete(graph, ns["subject"], ns["predicate"], Literal("Hello")) self.assertGraphIsEmpty() def test_insert(self): "Inserts a triple into the triplestore" ns = Namespace("https://github.com/juanique/artichoke/ns#") graph = self.config.graph self.isql.insert(graph, ns["subject"], ns["predicate"], ns["object"]) query = "SELECT * FROM <%s> WHERE {?s ?p ?o}" % graph results = self.endpoint.query(query) self.assertGraphHasNumberOfTriples(1) self.assertEquals(results[0]['s'].value, str(ns["subject"])) self.assertEquals(results[0]['p'].value, str(ns["predicate"])) self.assertEquals(results[0]['o'].value, str(ns["object"]))
class ConfigUnitTestCreatingConfig(unittest.TestCase): def setUp(self): self.config = Config("fixtures/config1.ini") def test_set_section_variable(self): "It allow to set new config options under a specific section" self.config.SectionA.set_var("value_b", 3) self.assertEqual(3, self.config.SectionA.value_b) def test_set_global_variable(self): "It allows to set a new config option under the global section" self.config.global_name = "global_val" self.assertEqual("global_val", self.config.global_name) def test_add_section(self): "It allows to add a new section." self.config.add_section("SectionB") self.config.SectionB.set_var("value_b", 4) self.assertEquals(4, self.config.SectionB.value_b) def test_set_variable(self): "Variables will be setted using ConfigVariable objects" self.config.SectionA.new_var = 5 self.assertTrue(isinstance(self.config.SectionA.get_var('new_var'), ConfigVariable)) self.assertEquals(5, self.config.SectionA.get_var("new_var").value) def test_set_variable_ci(self): "Variables can be set through a case insensitive name, and then properly retrieved" self.config.SectionA.NEW_VAR = 5 self.assertEquals(5, self.config.SectionA.get_var("new_var").value) self.assertEquals(5, self.config.SectionA.get_var("NEW_VAR").value) def test_del_variable(self): self.config.SectionA.NEW_VAR = 6 del self.config.SectionA.NEW_VAR self.assertRaises(KeyError, self.config.SectionA.get_var, "new_var") def test_save_config(self): "It saves its current state to a .ini file" filename = "generated_config.ini" self.config.save(filename) saved_config = Config(filename) self.assertEquals(self.config.db_name, saved_config.db_name) self.assertEquals(self.config.SectionA.value_a, saved_config.SectionA.value_a) os.remove("generated_config.ini") def test_modified_init(self): """It detects whether any changes where made since the object was constructed, should be False right after __init__""" self.assertEquals(False, self.config.modified) def test_modified_after_change(self): "modified should be True after changing the value of a variable" self.config.new_var = "new_value" self.assertEquals(True, self.config.modified) def test_modified_same_vaule(self): """Setting a variable to the same value it had should not be considered a modification""" self.config.db_name = "mysql" self.assertEquals(False, self.config.modified) def test_autosave_config(self): """It can be setted to automatically save changes to a given file.""" self.config.autosave("autosaved.ini") self.config.SectionA.set_var("value_b", 3) saved_config = Config("autosaved.ini") self.assertEquals(3, saved_config.SectionA.value_b) os.remove("autosaved.ini")