Example #1
0
    def test_run_engine_sets_job_duration(self):
        """
        run_engine() sets the job duration.
        """
        def utcnow_mock():
            """Return 2 times that are 5 minutes apart."""
            utcnow_mock.call_count += 1
            if utcnow_mock.the_time is not None:
                return utcnow_mock.the_time + datetime.timedelta(seconds=300)
            else:
                utcnow_mock.the_time = datetime.datetime.utcnow()
                return utcnow_mock.the_time

        utcnow_mock.the_time = None
        utcnow_mock.call_count = 0

        with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
            mock_func.return_value = (-41, "__out__", "__err__")
            # Run the actual function that is to be tested.
            run_engine(self.job, utc_provider=utcnow_mock)
            self.assertEqual(300, self.job.duration)
            self.assertEqual(2, utcnow_mock.call_count)
    def test_run_engine_sets_job_duration(self):
        """
        run_engine() sets the job duration.
        """

        def utcnow_mock():
            """Return 2 times that are 5 minutes apart."""
            utcnow_mock.call_count += 1
            if utcnow_mock.the_time is not None:
                return utcnow_mock.the_time + datetime.timedelta(seconds=300)
            else:
                utcnow_mock.the_time = datetime.datetime.utcnow()
                return utcnow_mock.the_time
        utcnow_mock.the_time = None
        utcnow_mock.call_count = 0

        with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
            mock_func.return_value = (-41, "__out__", "__err__")
            # Run the actual function that is to be tested.
            run_engine(self.job, utc_provider=utcnow_mock)
            self.assertEqual(300, self.job.duration)
            self.assertEqual(2, utcnow_mock.call_count)
    def test_run_engine(self):
        """
        run_engine() passes the correct commands to run_cmd().
        """
        with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
            # Make all the calls pass.
            mock_func.return_value = (-42, "__out__", "__err__")

            # Run the actual function that is to be tested.
            results = run_engine(self.job)
            # run_engine() is passing through the run_cmd() return value.
            self.assertEqual(mock_func.return_value, results)
            # run_cmd() was called once.
            self.assertEqual(1, mock_func.call_count)
            # The arguments passed to run_cmd() are as follows:
            expected = (
                (["%s/bin/openquake" % settings.OQ_ENGINE_DIR, "--config_file",
                  "%s/config.gem" % self.job.path],),
                {"ignore_exit_code": True})
            self.assertEqual(expected, mock_func.call_args)
Example #4
0
    def test_run_engine(self):
        """
        run_engine() passes the correct commands to run_cmd().
        """
        with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
            # Make all the calls pass.
            mock_func.return_value = (-42, "__out__", "__err__")

            # Run the actual function that is to be tested.
            results = run_engine(self.job)
            # run_engine() is passing through the run_cmd() return value.
            self.assertEqual(mock_func.return_value, results)
            # run_cmd() was called once.
            self.assertEqual(1, mock_func.call_count)
            # The arguments passed to run_cmd() are as follows:
            expected = (([
                "%s/bin/openquake" % settings.OQ_ENGINE_DIR, "--config_file",
                "%s/config.gem" % self.job.path
            ], ), {
                "ignore_exit_code": True
            })
            self.assertEqual(expected, mock_func.call_args)