def client_process1(self, q): try: from dataclay.api import init, finish logger.debug('**Starting init 1**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI """ Test. From now on, the Functional Test itself. """ web_sites_ids_str = list() for i in range(0, 10): alias = "bsc%s" % str(i) web_site = WebSite(alias) try: web_site.make_persistent(alias=alias) except: traceback.print_exc() web_sites_ids_str.append(str(web_site.get_object_id())) finish() q.put(["OK", web_sites_ids_str]) except: q.put("FAIL")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI self.session_initialized = True """ Test. From now on, the Functional Test itself. """ host = "bsc.es" web_site = WebSite(host) web_page = WebPage(host + "/page.html") # Verify object_iD is not null object_id = web_site.get_object_id() self.assertTrue(object_id != None) web_site.add_web_page(web_page) alias = uuid.uuid4().__str__() web_site.make_persistent(alias) # Clone the web_site web_site_copy = web_site.dc_clone() self.assertTrue(len(web_site_copy.pages) == len(web_site.pages)) # Add a web page to cloned web_site web_page2 = WebPage(host + "/page2.html") web_site_copy.add_web_page(web_page2) # Update original web_site WebSite.dc_update_by_alias(alias, web_site_copy) self.assertFalse(web_site_copy.is_persistent()) self.assertTrue(len(web_site_copy.pages) == len(web_site.pages)) logger.debug("Test OK!")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI from dataclay import getRuntime self.session_initialized = True """ Test. From now on, the Functional Test itself. """ host = "bsc.es" web_site = WebSite(host) environments_ids = list(getRuntime().get_execution_environments_info().keys()) self.assertEqual(len(environments_ids), 2) environment1_id = environments_ids[0] environment2_id = environments_ids[1] # MakePersistent in location1 web_site.make_persistent(backend_id=environment1_id) web_site.new_replica(backend_id=environment2_id, recursive=True) object_id = web_site.get_object_id() all_locations_ids = web_site.get_all_locations().keys() self.assertTrue(web_site.is_persistent()) self.assertIsNotNone(object_id) # All_locations contains environment1_id and environment2_id self.assertIn(environment1_id, all_locations_ids) self.assertIn(environment2_id, all_locations_ids) self.assertEqual(len(all_locations_ids), 2) logger.debug("Test OK!")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI from dataclay import getRuntime self.session_initialized = True """ Test. From now on, the Functional Test itself. """ host = "bsc.es" web_page = WebPage(host + "/foo/bsc.html") web_page.make_persistent(alias=web_page.uri.host) host = "fsf.org" web_site = WebSite(host) web_site.add_web_page(web_page) # added persistent object to a volatile web_page.add_link(web_site) # send volatile self.assertTrue(web_site.is_persistent()) self.assertTrue(web_site.uri.is_persistent()) self.assertTrue(web_page.is_persistent()) self.assertTrue(web_page.uri.is_persistent()) object_id = web_site.get_object_id() backend_id = web_site.get_location() # Assert that backend_id of volatile object is the hint self.assertIsNotNone(object_id) self.assertEqual(backend_id, web_site.get_hint()) logger.debug("Test OK!")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI self.session_initialized = True """ Test. From now on, the Functional Test itself. """ host = "bsc.es" web_site = WebSite(host) web_page = WebPage(host + "/page.html") web_page2 = WebPage(host + "/page2.html") # Verify object_iD is not null object_id = web_site.get_object_id() self.assertTrue(object_id != None) web_site.add_web_page(web_page) self.assertEqual(len(web_site.pages), 1) # Test make_persistent web_site.make_persistent(recursive=False) self.assertTrue(web_site.is_persistent()) # TODO: Test better this # Add another page after persistence but web_site.uri.host is not persistent # (See add_we_page method in model/classes.py) self.assertRaises(Exception, web_site.add_web_page, web_page2) logger.debug("Test OK!")
def client_process2(self, q, web_sites_ids_str): try: from dataclay.api import init, finish logger.debug('**Starting init 2 **') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI for i in range(0, 10): web_site_2 = WebSite.get_by_alias("bsc%s" % str(i)) self.assertEqual(web_sites_ids_str[i], str(web_site_2.get_object_id())) finish() q.put("OK") except: q.put("FAIL")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage from dataclay import getRuntime self.session_initialized = True """ Test. From now on, the Functional Test itself. """ execs_info = getRuntime().get_execution_environments_info() exec_env_info_1 = execs_info[list(execs_info.keys())[0]] exec_env_info_2 = execs_info[list(execs_info.keys())[1]] host = "bsc.es" web_site = WebSite(host) web_site.make_persistent(alias=web_site.uri.host, backend_id=exec_env_info_1.dataClayID) web_page = WebPage(host + "/page.html") web_page.make_persistent(backend_id=exec_env_info_2.dataClayID) web_site.add_web_page(web_page) self.assertTrue(web_site.is_persistent()) self.assertTrue(web_site.uri.is_persistent()) self.assertTrue(web_page.is_persistent()) # volatile is persistent self.assertTrue(web_page.uri.is_persistent()) # volatile is persistent logger.debug("Test OK!")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI self.session_initialized = True """ Test. From now on, the Functional Test itself. """ # Create source object host = "bsc.es" web_site = WebSite(host) web_page = WebPage(host + "/page.html") web_site.add_web_page(web_page) web_site.make_persistent("clone_by_alias") # Test clone by alias recursive web_site_copy = WebSite.dc_clone_by_alias(alias="clone_by_alias", recursive=True) self.assertFalse(web_site_copy.is_persistent()) self.assertTrue(web_site_copy.get_hint() is None) # Test reference is not persistent since clonse is recursive for p in web_site_copy.pages: self.assertFalse(p.is_persistent()) self.assertTrue(p.get_hint() is None) self.assertTrue(len(web_site_copy.pages) == len(web_site.pages)) logger.debug("Test OK!")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI self.session_initialized = True """ Test. From now on, the Functional Test itself. """ host = "bsc.es" web_site = WebSite(host + "/foo/bsc.html") web_site.make_persistent(alias=web_site.uri.host) cur_host = "volatile_web" web_page = WebPage(cur_host) logger.debug("web page oid = %s", web_page.get_object_id()) logger.debug("uri oid = %s", web_page.uri.get_object_id()) web_site.add_web_page(web_page) """ Sleep enough time to allow GC action """ print("Waiting for GC action...") time.sleep(5) """ Modify web page """ web_page.uri.host = "new_volatile_web" """ Sleep enough time to allow GC action """ print("Waiting for GC action...") time.sleep(5) """ Get web page """ self.assertEquals(web_page.uri.host, "new_volatile_web") logger.debug("Test OK!")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI from dataclay import getRuntime self.session_initialized = True """ Test. From now on, the Functional Test itself. """ # Test recursive makePersistent without circular dependencies host = "bsc.es" web_site = WebSite(host) web_page = WebPage(host + "/page.html") web_site.add_web_page(web_page) environments_ids = list( getRuntime().get_execution_environments_info().keys()) environment1_id = environments_ids[0] environment2_id = environments_ids[1] environment3_id = environments_ids[2] self.assertEqual(len(environments_ids), 3) web_site.make_persistent(alias=web_site.uri.host, backend_id=environment1_id) ws_locations = web_site.get_all_locations() ws_uri_locations = web_site.uri.get_all_locations() wp_locations = web_page.get_all_locations() wp_uri_locations = web_page.uri.get_all_locations() # Check Persistence self.assertTrue(web_site.is_persistent()) self.assertEqual(len(ws_locations), 1) self.assertIn(environment1_id, ws_locations) self.assertTrue(web_site.uri.is_persistent()) self.assertEqual(len(ws_uri_locations), 1) self.assertIn(environment1_id, ws_uri_locations) self.assertTrue(web_page.is_persistent()) self.assertEqual(len(wp_locations), 1) self.assertIn(environment1_id, wp_locations) self.assertTrue(web_page.uri.is_persistent()) self.assertEqual(len(wp_uri_locations), 1) self.assertIn(environment1_id, wp_uri_locations) # Move in the second location getRuntime().move_object(web_site, environment1_id, environment2_id, True) ws_locations = web_site.get_all_locations() ws_uri_locations = web_site.uri.get_all_locations() wp_locations = web_page.get_all_locations() wp_uri_locations = web_page.uri.get_all_locations() # Check that the object and associated ones are now in the second location self.assertEqual(len(ws_locations), 1) self.assertIn(environment2_id, ws_locations) self.assertEqual(len(ws_uri_locations), 1) self.assertIn(environment2_id, ws_uri_locations) self.assertEqual(len(wp_locations), 1) self.assertIn(environment2_id, wp_locations) self.assertEqual(len(wp_uri_locations), 1) self.assertIn(environment2_id, wp_uri_locations) # Move in the third location getRuntime().move_object(web_site, environment2_id, environment3_id, True) ws_locations = web_site.get_all_locations() ws_uri_locations = web_site.uri.get_all_locations() wp_locations = web_page.get_all_locations() wp_uri_locations = web_page.uri.get_all_locations() # Check that the object and associated ones are now in the third location self.assertEqual(len(ws_locations), 1) self.assertIn(environment3_id, ws_locations) self.assertEqual(len(ws_uri_locations), 1) self.assertIn(environment3_id, ws_uri_locations) self.assertEqual(len(wp_locations), 1) self.assertIn(environment3_id, wp_locations) self.assertEqual(len(wp_uri_locations), 1) self.assertIn(environment3_id, wp_uri_locations) logger.debug("Test OK!")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI self.session_initialized = True """ Test. From now on, the Functional Test itself. """ # Test recursive makePersistent without circular dependencies host = "bsc1.es" web_site = WebSite(host) web_site.make_persistent(alias=web_site.uri.host) uri = URI(host + "/volatilepage.html") # Volatile web_site.uri = uri # param of setter is volatile self.assertTrue(uri.is_persistent()) self.assertTrue(web_site.is_persistent()) self.assertTrue(web_site.uri.is_persistent()) # Test recursive with one circular dependency host = "bsc2.es" web_page = WebPage(host + "/foo/bsc.html") web_page.make_persistent(alias=web_page.uri.host) host = "fsf.org" web_site = WebSite(host) web_site.add_web_page( web_page) # added persistent object to a volatile web_page.add_link(web_site) # send volatile self.assertTrue(web_site.is_persistent()) self.assertTrue(web_site.uri.is_persistent()) self.assertTrue(web_page.is_persistent()) self.assertTrue(web_page.uri.is_persistent()) logger.debug("Test OK!")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI from dataclay import getRuntime self.session_initialized = True """ Test. From now on, the Functional Test itself. """ environments_ids = list( getRuntime().get_execution_environments_info().keys()) environment1_id = environments_ids[0] environment2_id = environments_ids[1] host = "bsc.es" web_site = WebSite(host) web_page = WebPage(host + "/page.html") # Verify object_iD is not null object_id = web_site.get_object_id() self.assertTrue(object_id != None) web_site.add_web_page(web_page) web_site.make_persistent(backend_id=environment1_id) web_site.new_replica(backend_id=environment2_id) ws_locations = web_site.get_all_locations() self.assertEqual(len(ws_locations), 2) # Clone the web_site web_site_copy = web_site.dc_clone() self.assertEqual(len(web_site_copy.pages), len(web_site.pages)) nondefaultvalue = "notfoo" web_site_copy.replyme = nondefaultvalue # Add a web page to cloned web_site web_page2 = WebPage(host + "/page2.html") web_site_copy.add_web_page(web_page2) # Update original web_site web_site.dc_update(web_site_copy) self.assertFalse(web_site_copy.is_persistent()) # Check updates self.assertEqual(len(web_site_copy.pages), len(web_site.pages)) wrong = False from dataclay.DataClayObjProperties import DCLAY_GETTER_PREFIX for ws_location in ws_locations: value = web_site.run_remote(ws_location, DCLAY_GETTER_PREFIX + "replyme", None) if value != nondefaultvalue: wrong = True self.assertFalse(wrong) logger.debug("Test OK!")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI self.session_initialized = True """ Test. From now on, the Functional Test itself. """ host = "bsc.es" web_site = WebSite(host) # Verify object_iD is not null object_id = web_site.get_object_id() self.assertTrue(object_id != None) # Test make_persistent web_site.make_persistent() self.assertTrue(web_site.is_persistent) web_site.make_persistent("testAlias") web_site2 = WebSite.get_by_alias("testAlias") self.assertEqual(web_site, web_site2) web_site.make_persistent("otherAlias") web_site3 = WebSite.get_by_alias("otherAlias") web_site4 = WebSite.get_by_alias("testAlias") self.assertEqual(web_site3, web_site4) self.assertEqual(web_site3, web_site) self.assertEqual(web_site3, web_site2) logger.debug("Test OK!")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI self.session_initialized = True """ Test. From now on, the Functional Test itself. """ host = "bsc.es" host2 = "bsc.en" web_site = WebSite(host) web_page = WebPage(host + "/main.html") web_page2 = WebPage(host2 + "/who.html") uri1 = URI(host2 + "/where.html") uri2 = URI(host + "/why.html") # Verify object_iD is not null object_id = web_site.get_object_id() self.assertIsNotNone(object_id) # Execute method locally web_site.add_web_page(web_page) self.assertTrue(len(web_site.pages) > 0) # Execute setter and getter locally web_site.uri = uri1 self.assertEqual(web_site.uri.host, host2) # Test make_persistent web_site.make_persistent() self.assertTrue(web_site.is_persistent()) # Execute method remotely web_site.add_web_page(web_page2) self.assertEqual(len(web_site.pages), 2) # Execute setter and getter locally web_site.uri = uri2 # Get of get on volatiles cause exception self.assertEqual(web_site.uri.host, host) logger.debug("Test OK!")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI self.session_initialized = True """ Test. From now on, the Functional Test itself. """ # Init source host = "bsc.es" web_site = WebSite(host) web_page = WebPage(host + "/page.html") web_site.add_web_page(web_page) web_site.make_persistent() # Init target host2 = "bsc2.es" web_site2 = WebSite(host2) web_site2.make_persistent() web_site2.copy_pages(web_site) self.assertTrue(len(web_site2.pages) == len(web_site.pages)) logger.debug("Test OK!")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI self.session_initialized = True """ Test. From now on, the Functional Test itself. """ host = "bsc.es" web_site = WebSite(host) web_page = WebPage(host + "/page.html") # Add web_page to web_site and make it persistent web_site.add_web_page(web_page) self.assertIs(web_page, web_site.pages[0]) web_site.make_persistent() self.assertTrue(web_site.is_persistent()) self.assertEqual(len(web_site.get_all_locations()), 1) self.assertTrue(web_site.uri.is_persistent()) self.assertEqual(len(web_site.uri.get_all_locations()), 1) # NewVersion for WebSite version_info, unloaded_version_info = web_site.new_version( list(web_site.get_all_locations().keys())[0]) logger.debug(version_info) versionOID = version_info.versionOID web_site_version = WebSite.get_object_by_id(versionOID) self.assertNotEqual(web_site.get_object_id(), web_site_version.get_object_id()) self.assertTrue(web_site_version.is_persistent()) self.assertEqual(len(web_site_version.get_all_locations()), 1) self.assertTrue(web_site_version.uri.is_persistent()) self.assertEqual(len(web_site_version.uri.get_all_locations()), 1) web_page_version = web_site_version.pages[0] self.assertEqual(len(web_site_version.pages), 1) self.assertNotEqual(web_page.get_object_id(), web_page_version.get_object_id()) self.assertNotEqual(web_page, web_page_version) # Remove WebPage to version pages and consolidate web_site_version.remove_last_web_page() self.assertEqual(len(web_site_version.pages), 0) self.assertEqual(len(web_site.pages), 1) web_site.consolidate_version(unloaded_version_info) self.assertEqual(len(web_site.pages), 0) logger.debug("Test OK!")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI self.session_initialized = True """ Test. From now on, the Functional Test itself. """ host = "bsc.es" web_site = WebSite(host) web_page = WebPage(host + "/page.html") # Add web_page to web_site and make it persistent web_site.add_web_page(web_page) self.assertIs(web_page, web_site.pages[0]) web_site.make_persistent() self.assertTrue(web_site.is_persistent()) self.assertEqual(len(web_site.get_all_locations()), 1) self.assertTrue(web_site.uri.is_persistent()) self.assertEqual(len(web_site.uri.get_all_locations()), 1) # Create new version for WebSite version_info, unloaded_version_info = web_site.new_version( list(web_site.get_all_locations().keys())[0]) logger.debug(version_info) versionOID = version_info.versionOID web_site_version = WebSite.get_object_by_id(versionOID) self.assertNotEqual(web_site.get_object_id(), web_site_version.get_object_id()) self.assertTrue(web_site_version.is_persistent()) self.assertEqual(len(web_site_version.get_all_locations()), 1) self.assertTrue(web_site_version.uri.is_persistent()) self.assertEqual(len(web_site_version.uri.get_all_locations()), 1) web_page_version = web_site_version.pages[0] self.assertEqual(len(web_site_version.pages), 1) self.assertNotEqual(web_page.get_object_id(), web_page_version.get_object_id()) self.assertNotEqual(web_page, web_page_version) # Modifying uri and num of WebSite version's page and consolidate new_host = "bsc.cat" new_uri = URI(new_host + "/page.html") # FIXME: New URI is consolidated just if is maked Persistent before # FIXME: If I change the uri with modify_uri_str (passing a string) object is not consolidated (Object not registered) new_uri.make_persistent() web_page_version.modify_uri(new_uri) web_page_version.modify_num(2) self.assertNotEqual(web_site.pages[0].uri.host, web_site_version.pages[0].uri.host) self.assertEqual(web_site.pages[0].uri.path, web_site_version.pages[0].uri.path) self.assertEqual(web_site.pages[0].uri.host, host) self.assertIsNone(web_site.pages[0].num) self.assertTrue(web_page_version.uri.is_persistent()) web_site.consolidate_version(unloaded_version_info) self.assertEqual(web_site.pages[0].uri.host, new_host) self.assertEqual(web_site.pages[0].num, 2) logger.debug("Test OK!")
def test(self): """Test. note that all test method names must begin with 'test.'""" """WARNING: IT IS HIGHLY RECOMMENDED TO HAVE ONE TEST ONLY TO ISOLATE FUNCTIONAL TESTS FROM EACH OTHER. i.e. Start a new Python Interpreter and JVM for each test. In the end, it means only one test in this class. """ from dataclay.api import init logger.debug('**Starting init**') init() """ Imports. Imports must be located here in order to simulate "import" order in a real scenario. VERY IMPORTANT: Imports must be located AFTER init """ from model.classes import WebSite, WebPage, URI self.session_initialized = True """ Test. From now on, the Functional Test itself. """ host = "bsc.es" web_site = WebSite(host) web_page = WebPage(host + "/page.html") web_page2 = WebPage(host + "/page2.html") web_page3 = WebPage(host + "/page3.html") web_page4 = WebPage(host + "/page4.html") # Verify object_iD is not null object_id = web_site.get_object_id() self.assertTrue(object_id != None) web_site.add_web_page(web_page) # Test make_persistent web_site.make_persistent("BSCwebsite") # Not added (yet!) to the web_site web_page3.make_persistent("page3") web_page4.make_persistent("page4") self.assertTrue(web_site.is_persistent()) # Add another page after persistence web_site.add_web_page(web_page2) self.assertEqual(len(web_site.pages), 2) web_site_bis = WebSite.get_by_alias("BSCwebsite") self.assertEqual(len(web_site_bis.pages), 2) web_site_bis.add_web_page(WebPage.get_by_alias("page3")) web_site_bis.add_web_page(WebPage.get_by_alias("page4")) self.assertEqual(len(web_site.pages), 4) self.assertEqual(len(web_site_bis.pages), 4) # Test recursive make_persistent for page in web_site.pages: self.assertTrue(page.is_persistent()) self.assertTrue(page.uri.is_persistent()) self.assertTrue(web_site.uri.is_persistent()) logger.debug("Test OK!")