def test_task_are_in_task_to_json(self):
        task = Task(self.conn, "task-name")
        task.completion_ttl = "4.11:08:06"
        task.auto_delete = True
        json_task = task._to_json()

        assert json_task['completionTimeToLive'] == '4.11:08:06'
        assert json_task['autoDeleteOnCompletion'] == True
Beispiel #2
0
    def test_task_are_in_task_to_json(self, mock_conn):
        task = Task(mock_conn, "task-name")
        task.completion_ttl = "4.11:08:06"
        task.auto_delete = True
        json_task = task._to_json()  # pylint: disable=protected-access

        assert json_task['completionTimeToLive'] == '4.11:08:06'
        assert json_task['autoDeleteOnCompletion'] is True
Beispiel #3
0
    def test_advance_bucket_in_task_to_json(self, mock_conn):
        task = Task(mock_conn, "task-name", "profile")
        bucket = Bucket(mock_conn, "name", False)
        bucket2 = bucket.with_filtering(BucketPrefixFiltering(
            "prefix1")).with_resource_transformation(PrefixResourcesTransformation("prefix2"))

        task.resources.append(bucket2)
        json_task = task._to_json()
        json_bucket = json_task["advancedResourceBuckets"][0]
        assert "name" == json_bucket["bucketName"]
        assert "prefix1" == json_bucket["filtering"]["prefixFiltering"]["prefix"]
        assert "prefix2" == json_bucket["resourcesTransformation"]["stripPrefix"]["prefix"]
Beispiel #4
0
    def test_task_privileges(self, mock_conn):
        task = Task(mock_conn, "task-name")
        task.allow_credentials_to_be_exported_to_task_environment()
        assert task.privileges is not None
        assert task.privileges._exportApiAndStorageCredentialsInEnvironment == True

        json_task = task._to_json()
        assert json_task['privileges'] is not None
        assert json_task['privileges']['exportApiAndStorageCredentialsInEnvironment'] is True

        # fields that need to be non null for the deserialization to not fail
        json_task['creationDate'] = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
        json_task['uuid'] = str(uuid.uuid4())
        json_task['state'] = 'Submitted'
        json_task['runningCoreCount'] = 0
        json_task['runningInstanceCount'] = 0

        pool_from_json = Task(mock_conn, "task-name")
        pool_from_json._update(json_task)
        assert pool_from_json.privileges is not None
        assert pool_from_json.privileges._exportApiAndStorageCredentialsInEnvironment is True
Beispiel #5
0
    def create_task(self, name, profile, instancecount_or_range=1):
        """Create a new :class:`~qarnot.task.Task`.

        :param str name: given name of the task
        :param str profile: which profile to use with this task
        :param instancecount_or_range: number of instances, or ranges on which to run task. Defaults to 1.
        :type instancecount_or_range: int or str
        :rtype: :class:`~qarnot.task.Task`
        :returns: The created :class:`~qarnot.task.Task`.

        .. note:: See available profiles with :meth:`profiles`.
        """
        return Task(self, name, profile, instancecount_or_range)
Beispiel #6
0
 def test_task_property_update_value(self, mock_conn, property_name,  expected_value):
     task = Task(mock_conn, "task-name")
     task._update(default_json_task)
     assert getattr(task, property_name) == expected_value
Beispiel #7
0
 def test_task_completion_ttl_set_get(self, mock_conn):
     task = Task(mock_conn, "task-name")
     task.completion_ttl = datetime.timedelta(days=2, hours=33, minutes=66, seconds=66)
     assert "3.10:07:06" == task.completion_ttl
     task.completion_ttl = "4.11:08:06"
     assert "4.11:08:06" == task.completion_ttl
Beispiel #8
0
 def test_task_autodelete_set_get(self, mock_conn):
     task = Task(mock_conn, "task-name")
     task.auto_delete = False
     assert task.auto_delete is False
     task.auto_delete = True
     assert task.auto_delete is True
Beispiel #9
0
 def test_task_completion_ttl_default_value(self, mock_conn):
     task = Task(mock_conn, "task-name")
     assert "00:00:00" == task.completion_ttl
Beispiel #10
0
 def test_task_autodelete_default_value(self, mock_conn):
     task = Task(mock_conn, "task-name")
     assert task.auto_delete is False
 def test_task_autodelete_set_get(self):
     task = Task(self.conn, "task-name")
     task.auto_delete = False
     assert False == task.auto_delete
     task.auto_delete = True
     assert True == task.auto_delete
Beispiel #12
0
 def test_execution_attempt_count_in_completed_instances(self, mock_conn):
     task = Task(mock_conn, "task-name")
     task._update(default_json_task)
     assert task.completed_instances[0].execution_attempt_count == 43
Beispiel #13
0
 def test_execution_attempt_count_in_running_instances(self, mock_conn):
     task = Task(mock_conn, "task-name")
     task._update(task_with_running_instances)
     assert len(task.status.running_instances_info.per_running_instance_info) == 2
     assert task.status.running_instances_info.per_running_instance_info[0].execution_attempt_count == 1
     assert task.status.running_instances_info.per_running_instance_info[1].execution_attempt_count == 2
Beispiel #14
0
 def test_task_set_property_raise_exception_after_submitted(self, mock_conn, property_name, set_value, exception):
     task = Task(mock_conn, "task-name")
     self.submit_task(task)
     with pytest.raises(exception):
         setattr(task, property_name, set_value)
Beispiel #15
0
 def test_task_set_forbidden_property_raise_exception(self, mock_conn, property_name, set_value, exception):
     task = Task(mock_conn, "task-name")
     with pytest.raises(exception):
         setattr(task, property_name, set_value)
Beispiel #16
0
 def test_task_property_send_to_json_representation(self, mock_conn, property_name, expected_value):
     task = Task(mock_conn, "task-name")
     task._update(default_json_task)
     task_json = task._to_json()
     assert task_json[property_name] == expected_value
Beispiel #17
0
 def test_task_set_property_value(self, mock_conn, property_name, set_value, expected_value):
     task = Task(mock_conn, "task-name")
     setattr(task, property_name, set_value)
     assert getattr(task, property_name) == expected_value
 def test_task_autodelete_default_value(self):
     task = Task(self.conn, "task-name")
     assert False == task.auto_delete