Exemplo n.º 1
0
    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!")
Exemplo n.º 2
0
    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]

        self.assertEqual(len(environments_ids), 2)

        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.assertTrue(web_site.uri.is_persistent())
        self.assertEqual(len(ws_uri_locations), 1)

        self.assertTrue(web_page.is_persistent())
        self.assertEqual(len(wp_locations), 1)

        self.assertTrue(web_page.uri.is_persistent())
        self.assertEqual(len(wp_uri_locations), 1)

        web_site.new_replica(backend_id=environment2_id, recursive=False)

        # Updates variables after replication
        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 object is replicated
        self.assertEqual(len(ws_locations), 2)
        self.assertIn(environment1_id, ws_locations)
        self.assertIn(environment2_id, ws_locations)

        # Check that associated objects are not replicated (Have just one environment)
        self.assertEqual(len(ws_uri_locations), 1)
        self.assertEqual(len(wp_locations), 1)
        self.assertEqual(len(wp_uri_locations), 1)

        logger.debug("Test OK!")
Exemplo n.º 3
0
    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!")