Пример #1
0
def test_queue_swap_task_item(client, add_sample, add_task):
    """Test if we can swap tasks in a sample in queue. Two tasks are added with a different param and then swaped and tested"""
    rv = client.get("/mxcube/api/v0.1/queue")
    assert rv.status_code == 200 and len(json.loads(rv.data).get("1:05")["tasks"]) == 1

    queue_id = json.loads(rv.data).get("1:05")["queueID"]
    task_to_add = copy.deepcopy(test_task)
    task_to_add["queueID"] = queue_id
    task_to_add["tasks"][0]["sampleQueueID"] = queue_id
    task_to_add["tasks"][0]["parameters"]["kappa"] = 90

    rv = client.post(
        "/mxcube/api/v0.1/queue",
        data=json.dumps([task_to_add]),
        content_type="application/json",
    )
    assert rv.status_code == 200

    rv = client.get("/mxcube/api/v0.1/queue")
    assert rv.status_code == 200 and len(json.loads(rv.data).get("1:05")["tasks"]) == 2

    rv = client.post(
        ("/mxcube/api/v0.1/queue/{}/{}/{}/swap").format("1:05", 0, 1),
        content_type="application/json",
    )
    assert rv.status_code == 200

    rv = client.get("/mxcube/api/v0.1/queue")
    assert (
        rv.status_code == 200
        and json.loads(rv.data).get("1:05")["tasks"][0]["parameters"]["kappa"] == 90
    )
Пример #2
0
def test_queue_move_task_item(client):
    """Test if we can move tasks in a sample in queue.
    Three tasks are added with a different param and then moved and tested."""
    resp = client.get("/mxcube/api/v0.1/queue")
    assert (
        resp.status_code == 200 and len(json.loads(resp.data).get("1:05")["tasks"]) == 1
    )

    queue_id = json.loads(resp.data).get("1:05")["queueID"]
    task_to_add = copy.deepcopy(test_task)
    task_to_add["queueID"] = queue_id
    task_to_add["tasks"][0]["sampleQueueID"] = queue_id
    task_to_add["tasks"][0]["parameters"]["kappa"] = 90

    resp = client.post(
        "/mxcube/api/v0.1/queue",
        data=json.dumps([task_to_add]),
        content_type="application/json",
    )
    assert resp.status_code == 200

    resp = client.get("/mxcube/api/v0.1/queue")
    assert (
        resp.status_code == 200 and len(json.loads(resp.data).get("1:05")["tasks"]) == 2
    )

    task_to_add = copy.deepcopy(test_task)
    task_to_add["queueID"] = queue_id
    task_to_add["tasks"][0]["sampleQueueID"] = queue_id
    task_to_add["tasks"][0]["parameters"]["kappa"] = 180

    resp = client.post(
        "/mxcube/api/v0.1/queue",
        data=json.dumps([task_to_add]),
        content_type="application/json",
    )
    assert resp.status_code == 200

    resp = client.get("/mxcube/api/v0.1/queue")
    assert (
        resp.status_code == 200 and len(json.loads(resp.data).get("1:05")["tasks"]) == 3
    )

    resp = client.post(
        ("/mxcube/api/v0.1/queue/{}/{}/{}/move").format("1:05", 0, 2),
        content_type="application/json",
    )
    assert resp.status_code == 200

    resp = client.get("/mxcube/api/v0.1/queue")
    assert (
        resp.status_code == 200
        and json.loads(resp.data).get("1:05")["tasks"][2]["parameters"]["kappa"] == 0
    )
Пример #3
0
def test_set_group_folder(client):
    """Test if we can set group folder."""
    resp = client.post(
        "/mxcube/api/v0.1/queue/group_folder",
        data=json.dumps({"path": "tmp/"}),
        content_type="application/json",
    )
    assert resp.status_code == 200 and json.loads(resp.data).get("path") == "tmp/"
Пример #4
0
def test_set_group_folder(client):
    """Test if we can set group folder."""
    rv = client.post(
        "/mxcube/api/v0.1/queue/group_folder",
        data=json.dumps({"path": "tmp/"}),
        content_type="application/json",
    )
    assert rv.status_code == 200 and json.loads(rv.data).get("path") == "tmp/"
Пример #5
0
def test_set_automount(client):
    """Test if we can set automount for samples."""
    rv = client.post(
        "/mxcube/api/v0.1/queue/automount",
        data=json.dumps(True),
        content_type="application/json",
    )
    assert rv.status_code == 200 and json.loads(rv.data).get("automount") == True
Пример #6
0
def test_queue_add_item(client):
    """Test if we can add a sample."""
    rv = client.post(
        "/mxcube/api/v0.1/queue",
        data=json.dumps([test_sample_5]),
        content_type="application/json",
    )
    assert rv.status_code == 200
Пример #7
0
def test_queue_move_task_item_fail(client, add_sample, add_task):
    """Test if we can move tasks in a sample in queue with boundry condition.
    Three tasks are added with a different param and then moved and tested."""
    rv = client.get("/mxcube/api/v0.1/queue")
    assert rv.status_code == 200 and len(json.loads(rv.data).get("1:05")["tasks"]) == 1

    queue_id = json.loads(rv.data).get("1:05")["queueID"]
    task_to_add = test_task
    task_to_add["queueID"] = queue_id
    task_to_add["tasks"][0]["sampleQueueID"] = queue_id
    task_to_add["tasks"][0]["parameters"]["kappa"] = 90
    rv = client.post(
        "/mxcube/api/v0.1/queue",
        data=json.dumps([task_to_add]),
        content_type="application/json",
    )
    assert rv.status_code == 200

    rv = client.get("/mxcube/api/v0.1/queue")
    assert rv.status_code == 200 and len(json.loads(rv.data).get("1:05")["tasks"]) == 2

    task_to_add = test_task
    task_to_add["queueID"] = queue_id
    task_to_add["tasks"][0]["sampleQueueID"] = queue_id
    task_to_add["tasks"][0]["parameters"]["kappa"] = 180
    rv = client.post(
        "/mxcube/api/v0.1/queue",
        data=json.dumps([task_to_add]),
        content_type="application/json",
    )
    assert rv.status_code == 200

    rv = client.get("/mxcube/api/v0.1/queue")
    assert rv.status_code == 200 and len(json.loads(rv.data).get("1:05")["tasks"]) == 3

    rv = client.post(
        ("/mxcube/api/v0.1/queue/{}/{}/{}/move").format("1:05", 2, 2),
        content_type="application/json",
    )
    rv = client.get("/mxcube/api/v0.1/queue")

    assert (
        rv.status_code == 200
        and json.loads(rv.data).get("1:05")["tasks"][2]["parameters"]["kappa"] == 180
    )
Пример #8
0
def test_set_automount(client):
    """Test if we can set automount for samples."""

    resp = client.post(
        "/mxcube/api/v0.1/queue/automount",
        data=json.dumps(True),
        content_type="application/json",
    )
    assert resp.status_code == 200 and json.loads(resp.data).get("automount") == True
Пример #9
0
def test_set_autoadd(client, add_sample):

    rv = client.post(
        "/mxcube/api/v0.1/queue/auto_add_diffplan",
        data=json.dumps(True),
        content_type="application/json",
    )
    assert (
        rv.status_code == 200 and json.loads(rv.data).get("auto_add_diffplan") == True
    )
Пример #10
0
def test_set_autoadd(client):
    resp = client.post(
        "/mxcube/api/v0.1/queue/auto_add_diffplan",
        data=json.dumps(True),
        content_type="application/json",
    )
    assert (
        resp.status_code == 200
        and json.loads(resp.data).get("auto_add_diffplan") == True
    )
Пример #11
0
def test_queue_set_sample_order(client, add_sample):
    """Test if we can set the sample order in the queue."""
    sample_to_add = test_sample_6
    rv = client.post(
        "/mxcube/api/v0.1/queue",
        data=json.dumps([sample_to_add]),
        content_type="application/json",
    )
    assert rv.status_code == 200

    new_sample_order = {"sampleOrder": ["1:01", "1:06", "1:05"]}
    rv = client.post(
        "/mxcube/api/v0.1/queue/sample-order",
        data=json.dumps(new_sample_order),
        content_type="application/json",
    )
    assert rv.status_code == 200

    rv = client.get("/mxcube/api/v0.1/queue")
    assert (
        rv.status_code == 200 and json.loads(rv.data).get("sample_order")[1] == "1:06"
    )
Пример #12
0
def test_queue_set_sample_order(client):
    """Test if we can set the sample order in the queue."""
    sample_to_add = test_sample_6
    resp = client.post(
        "/mxcube/api/v0.1/queue",
        data=json.dumps([sample_to_add]),
        content_type="application/json",
    )
    assert resp.status_code == 200

    new_sample_order = {"sampleOrder": ["1:01", "1:06", "1:05"]}
    resp = client.post(
        "/mxcube/api/v0.1/queue/sample-order",
        data=json.dumps(new_sample_order),
        content_type="application/json",
    )
    assert resp.status_code == 200

    resp = client.get("/mxcube/api/v0.1/queue")
    assert (
        resp.status_code == 200
        and json.loads(resp.data).get("sample_order")[1] == "1:06"
    )
Пример #13
0
def test_queue_delete_item(client, add_sample, add_task):
    """Test if we can delete a task from sample in the queue."""
    rv = client.get("/mxcube/api/v0.1/queue")
    assert rv.status_code == 200 and len(json.loads(rv.data).get("1:05")["tasks"]) == 1

    task_to_delete = ["1:05", 0]
    rv = client.post(
        "/mxcube/api/v0.1/queue/delete",
        data=json.dumps([task_to_delete]),
        content_type="application/json",
    )
    assert rv.status_code == 200

    rv = client.get("/mxcube/api/v0.1/queue")
    assert rv.status_code == 200 and len(json.loads(rv.data).get("1:05")["tasks"]) == 0
Пример #14
0
def test_queue_enable_item(client, add_sample):
    """Test if we can disable a task in the sample in queue."""
    rv = client.get("/mxcube/api/v0.1/queue")
    queue_id = json.loads(rv.data).get("1:05")["queueID"]

    test_disable = {"qidList": [queue_id], "enabled": False}

    rv = client.post(
        "/mxcube/api/v0.1/queue/set_enabled",
        data=json.dumps(test_disable),
        content_type="application/json",
    )
    assert rv.status_code == 200

    rv = client.get("/mxcube/api/v0.1/queue")
    assert rv.status_code == 200 and json.loads(rv.data).get("1:05")["checked"] == False
Пример #15
0
def test_queue_delete_item(client):
    """Test if we can delete a task from sample in the queue."""
    resp = client.get("/mxcube/api/v0.1/queue")
    assert (
        resp.status_code == 200 and len(json.loads(resp.data).get("1:05")["tasks"]) == 1
    )

    task_to_delete = ["1:05", 0]
    resp = client.post(
        "/mxcube/api/v0.1/queue/delete",
        data=json.dumps([task_to_delete]),
        content_type="application/json",
    )
    assert resp.status_code == 200

    resp = client.get("/mxcube/api/v0.1/queue")
    assert (
        resp.status_code == 200 and len(json.loads(resp.data).get("1:05")["tasks"]) == 0
    )
Пример #16
0
def test_queue_enable_item(client):
    """Test if we can disable a task in the sample in queue."""
    resp = client.get("/mxcube/api/v0.1/queue")
    queue_id = json.loads(resp.data).get("1:05")["queueID"]

    test_disable = {"qidList": [queue_id], "enabled": False}

    resp = client.post(
        "/mxcube/api/v0.1/queue/set_enabled",
        data=json.dumps(test_disable),
        content_type="application/json",
    )
    assert resp.status_code == 200

    resp = client.get("/mxcube/api/v0.1/queue")
    assert (
        resp.status_code == 200
        and json.loads(resp.data).get("1:05")["checked"] == False
    )
Пример #17
0
def test_add_and_edit_task(client, add_sample, add_task):
    """Test if we can add edit a task i the sample in the queue."""
    rv = client.get("/mxcube/api/v0.1/queue")
    queue_id = json.loads(rv.data).get("1:05")["queueID"]
    task_queue_id = json.loads(rv.data).get("1:05")["tasks"][0]["queueID"]
    assert rv.status_code == 200 and len(json.loads(rv.data).get("1:05")["tasks"]) == 1

    task_to_update = copy.deepcopy(test_edit_task)
    parameter_to_update = "num_images"
    parameter_update_value = 10
    task_to_update["parameters"][parameter_to_update] = parameter_update_value
    rv = client.post(
        ("/mxcube/api/v0.1/queue/{}/{}").format(queue_id, task_queue_id),
        data=json.dumps(task_to_update),
        content_type="application/json",
    )
    assert (
        rv.status_code == 200
        and json.loads(rv.data).get("parameters")[parameter_to_update]
        == parameter_update_value
    )
Пример #18
0
def test_add_and_edit_task(client):
    """Test if we can add edit a task i the sample in the queue."""
    resp = client.get("/mxcube/api/v0.1/queue")
    queue_id = json.loads(resp.data).get("1:05")["queueID"]
    task_queue_id = json.loads(resp.data).get("1:05")["tasks"][0]["queueID"]

    assert (
        resp.status_code == 200 and len(json.loads(resp.data).get("1:05")["tasks"]) == 1
    )

    task_to_update = copy.deepcopy(test_edit_task)
    parameter_to_update = "num_images"
    parameter_update_value = 10
    task_to_update["parameters"][parameter_to_update] = parameter_update_value
    resp = client.post(
        ("/mxcube/api/v0.1/queue/{}/{}").format(queue_id, task_queue_id),
        data=json.dumps(task_to_update),
        content_type="application/json",
    )
    assert (
        resp.status_code == 200
        and json.loads(resp.data).get("parameters")[parameter_to_update]
        == parameter_update_value
    )