예제 #1
0
def test_queue_start(client):
    """
    Test if we can start the queue.
    The queue requires a sample and a task to start which are added by fixtures.
    It also requires a 3d point to be saved before it move from paused state to running.
    Unpause is called to mimick that.
    """
    resp = client.get("/mxcube/api/v0.1/queue")
    assert (
        resp.status_code == 200 and len(json.loads(resp.data).get("1:05")["tasks"]) == 1
    )

    resp = client.put(
        "/mxcube/api/v0.1/queue/start",
        data=json.dumps({"sid": "1:05"}),
        content_type="application/json",
    )
    assert resp.status_code == 200

    resp = client.put("/mxcube/api/v0.1/queue/unpause")
    assert resp.status_code == 200

    time.sleep(1)
    resp = client.get("/mxcube/api/v0.1/queue_state")
    assert (
        resp.status_code == 200
        and json.loads(resp.data).get("queueStatus") == "QueueRunning"
    )
예제 #2
0
def test_queue_abort(client, add_sample, add_task):
    """Test if we can abort the queue. The queue is started and then aborted."""
    rv = client.put(
        "/mxcube/api/v0.1/queue/start",
        data=json.dumps({"sid": "1:05"}),
        content_type="application/json",
    )
    assert rv.status_code == 200

    rv = client.put("/mxcube/api/v0.1/queue/unpause")
    assert rv.status_code == 200

    rv = client.get("/mxcube/api/v0.1/queue_state")
    assert (
        rv.status_code == 200
        and json.loads(rv.data).get("queueStatus") == "QueueRunning"
    )

    rv = client.put("/mxcube/api/v0.1/queue/abort")
    assert rv.status_code == 200

    rv = client.get("/mxcube/api/v0.1/queue_state")
    assert (
        rv.status_code == 200
        and json.loads(rv.data).get("queueStatus") == "QueueStopped"
    )
예제 #3
0
def test_beamline_set_attribute(client):
    """
    Tests set on the writable attributes

    Basically only tests that the set command executes without unexpected
    errors. Reads the attributes current value and sets it to the same, so
    that the test can be safely executed on a beamline.
    """
    bl_attrs = [
        "resolution",
        "energy",
        "wavelength",
        "transmission",
        "safety_shutter",
        "beamstop",
        "fast_shutter",
        "detector_distance",
    ]

    for name in bl_attrs:
        resp = client.get("/mxcube/api/v0.1/beamline/%s" % name)
        data = json.loads(resp.data)

        new_value = data.get("value")

        resp = client.put(
            "/mxcube/api/v0.1/beamline/%s" % name,
            data=json.dumps({"name": name, "value": new_value}),
            content_type="application/json",
        )

        resp = client.get("/mxcube/api/v0.1/beamline/%s" % name)
        data = json.loads(resp.data)

        assert data.get("value", None) == new_value
def test_beamline_set_attribute(client):
    """
    Tests set on the writable attributes

    Basically only tests that the set command executes without unexpected
    errors. Reads the attributes current value and sets it to the same, so
    that the test can be safely executed on a beamline.
    """
    bl_attrs = [
        "resolution",
        "energy",
        "wavelength",
        "transmission",
        "safety_shutter",
        "beamstop",
        "fast_shutter",
        "detdist",
    ]

    for name in bl_attrs:
        resp = client.get("/mxcube/api/v0.1/beamline/%s" % name)
        data = json.loads(resp.data)

        new_value = data.get("value")

        resp = client.put(
            "/mxcube/api/v0.1/beamline/%s" % name,
            data=json.dumps({"name": name, "value": new_value}),
            content_type="application/json",
        )

        resp = client.get("/mxcube/api/v0.1/beamline/%s" % name)
        data = json.loads(resp.data)

        assert data.get("value", None) == new_value
예제 #5
0
def test_queue_start(client, add_sample, add_task):
    """
    Test if we can start the queue.
    The queue requires a sample and a task to start which are added by fixtures.
    It also requires a 3d point to be saved before it move from paused state to running.
    Unpause is called to mimick that.
    """
    rv = client.get("/mxcube/api/v0.1/queue")
    assert rv.status_code == 200 and len(json.loads(rv.data).get("1:05")["tasks"]) == 1

    rv = client.put(
        "/mxcube/api/v0.1/queue/start",
        data=json.dumps({"sid": "1:05"}),
        content_type="application/json",
    )
    assert rv.status_code == 200

    rv = client.put("/mxcube/api/v0.1/queue/unpause")
    assert rv.status_code == 200

    time.sleep(1)
    rv = client.get("/mxcube/api/v0.1/queue_state")
    assert (
        rv.status_code == 200
        and json.loads(rv.data).get("queueStatus") == "QueueRunning"
    )
예제 #6
0
def test_queue_abort(client):
    """Test if we can abort the queue. The queue is started and then aborted."""

    resp = client.put(
        "/mxcube/api/v0.1/queue/start",
        data=json.dumps({"sid": "1:05"}),
        content_type="application/json",
    )
    assert resp.status_code == 200

    resp = client.put("/mxcube/api/v0.1/queue/unpause")
    assert resp.status_code == 200

    resp = client.get("/mxcube/api/v0.1/queue_state")
    assert (
        resp.status_code == 200
        and json.loads(resp.data).get("queueStatus") == "QueueRunning"
    )

    resp = client.put("/mxcube/api/v0.1/queue/abort")
    assert resp.status_code == 200

    resp = client.get("/mxcube/api/v0.1/queue_state")
    assert (
        resp.status_code == 200
        and json.loads(resp.data).get("queueStatus") == "QueueStopped"
    )
예제 #7
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
    )
예제 #8
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
    )
예제 #9
0
def test_get_phase(client):
    """
    Checks if current phase is one of the phases in the phase list.
    """
    resp = client.get("/mxcube/api/v0.1/diffractometer/phaselist")
    data = json.loads(resp.data)

    phase_list = data["current_phase"]

    resp = client.get("/mxcube/api/v0.1/diffractometer/phase")
    data = json.loads(resp.data)

    phase = data["current_phase"]

    assert phase in phase_list
예제 #10
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
예제 #11
0
def test_queue_clear(client, add_sample, add_task):
    """Test if we can clear the queue. A sample and a task are added by fixtures and then cleared."""
    rv = client.put("/mxcube/api/v0.1/queue/clear")
    assert rv.status_code == 200

    rv = client.get("/mxcube/api/v0.1/queue")
    assert len(json.loads(rv.data)) == 0
예제 #12
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
def test_beamline_get_all_attribute(client):
    """
    Checks that the data returned has the right structure and if "all"
    beamline attributes are at least present
    """
    resp = client.get("/mxcube/api/v0.1/beamline")
    data = json.loads(resp.data)

    actual = list(data.get("attributes").keys())

    expected = ['beamstop',
                'cryo',
                'detdist',
                'energy',
                'fast_shutter',
                'flux',
                'machinfo',
                'resolution',
                'safety_shutter',
                'transmission',
                'wavelength']

    assert isinstance(data["attributes"], dict)
    assert isinstance(data["actionsList"], list)
    assert isinstance(data["path"], unicode)
    assert len(data["energyScanElements"]) == 31
    assert isinstance(data["availableMethods"], dict)
    assert len(actual) == len(expected)
def test_beamline_get_attribute(client):
    """
    Tests retrieval of all the beamline attributes (one by one), checks that
    the data returned at-least contain a minimal set of keys that make up a
    'beamline attribute'
    """
    bl_attrs = [
        "safety_shutter",
        "beamstop",
        "fast_shutter",
        "resolution",
        "energy",
        "flux",
        "cryo",
        "wavelength",
        "transmission",
        "machinfo",
        "detdist",
    ]

    for name in bl_attrs:
        resp = client.get("/mxcube/api/v0.1/beamline/%s" % name)

        data = json.loads(resp.data)

        # Check for minimal set of attributes
        keys = ["name", "state", "value"]

        for key in keys:
            assert key in data

        assert resp.status_code == 200
예제 #15
0
def test_beamline_get_all_attribute(client):
    """
    Checks that the data returned has the right structure and if "all"
    beamline attributes are at least present
    """

    resp = client.get("/mxcube/api/v0.1/beamline/")
    data = json.loads(resp.data)

    actual = list(data.get("attributes").keys())

    expected = [
        "beamstop",
        "capillary",
        "detector_distance",
        "energy",
        "fast_shutter",
        "flux",
        "machine_info",
        "resolution",
        "safety_shutter",
        "transmission",
        "wavelength",
    ]

    assert isinstance(data["attributes"], dict)
    assert isinstance(data["actionsList"], list)
    assert isinstance(data["path"], unicode)
    assert len(data["energyScanElements"]) == 31
    assert isinstance(data["availableMethods"], dict)
    assert len(actual) == len(expected)
예제 #16
0
def test_beamline_get_attribute(client):
    """
    Tests retrieval of all the beamline attributes (one by one), checks that
    the data returned at-least contain a minimal set of keys that make up a
    'beamline attribute'
    """

    bl_attrs = [
        "safety_shutter",
        "capillary",
        "beamstop",
        "fast_shutter",
        "resolution",
        "energy",
        "flux",
        "wavelength",
        "transmission",
        "machine_info",
        "detector_distance",
    ]

    for name in bl_attrs:
        resp = client.get("/mxcube/api/v0.1/beamline/%s" % name)

        data = json.loads(resp.data)

        # Check for minimal set of attributes
        keys = ["name", "state", "value"]

        for key in keys:
            assert key in data

        assert data["available"] == True
        assert resp.status_code == 200
예제 #17
0
def test_queue_clear(client):
    """Test if we can clear the queue. A sample and a task are added by fixtures and then cleared."""
    resp = client.put("/mxcube/api/v0.1/queue/clear")
    assert resp.status_code == 200

    resp = client.get("/mxcube/api/v0.1/queue")
    assert len(json.loads(resp.data)) == 0
예제 #18
0
def test_get_default_dc_params(client):
    """Test if we get the right default data collection params."""
    resp = client.get("/mxcube/api/v0.1/queue/dc")
    actual = json.loads(resp.data)

    # osc_start is taken from current omega which is random, so ignore it
    actual['acq_parameters'].pop('osc_start')
    assert resp.status_code == 200 and actual == default_dc_params
예제 #19
0
def test_get_sc_contents_view(client):
    """
    Checks retrieval of the sample changer contents
    """
    resp = client.get("/mxcube/api/v0.1/sample_changer/contents")
    data = json.loads(resp.data)
    resp = client.get("/mxcube/api/v0.1/sample_changer/capacity")
    capacity = json.loads(resp.data)["capacity"]

    assert isinstance(data["children"], list)
    assert len(data["children"]) == capacity["num_baskets"]  # pucks

    num_samples = 0
    for basket in data["children"]:
        num_samples += len(basket["children"])

    assert num_samples == capacity["num_samples"]  # samples
def test_get_data_path(client):
    """
    Retrieve data path, this is specific for each beamline.
    """
    resp = client.get("/mxcube/api/v0.1/beamline/datapath")
    data = json.loads(resp.data)
    assert isinstance(data["path"], unicode)
    assert len(data) > 0
예제 #21
0
def test_get_sc_state(client):
    """
    Checks retrieval of the sample changer state
    """
    resp = client.get("/mxcube/api/v0.1/sample_changer/state")
    data = json.loads(resp.data)

    assert isinstance(data["state"], unicode)
예제 #22
0
def test_get_maintenance_cmds(client):
    """
    Checks retrieval of the sample changer manteniance commands
    """
    resp = client.get("/mxcube/api/v0.1/sample_changer/get_maintenance_cmds")
    data = json.loads(resp.data)

    assert isinstance(data["cmds"], list)
예제 #23
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
    )
예제 #24
0
def test_get_sample_list(client):
    """
    Checks retrieval of the samples list from lims
    """
    resp = client.get("/mxcube/api/v0.1/sample_changer/samples_list")
    data = json.loads(resp.data)

    assert isinstance(data["sampleList"], dict)
    assert isinstance(data["sampleOrder"], list)
예제 #25
0
def test_get_aperture(client):
    """
    Checks if the data returned have is on the expected format
    """
    resp = client.get("/mxcube/api/v0.1/diffractometer/aperture")
    data = json.loads(resp.data)

    assert isinstance(data["currentAperture"], int)
    assert isinstance(data["apertureList"], list)
예제 #26
0
def test_get_loaded_sample(client):
    """
    Checks retrieval of the sample changer loaded sample
    """
    resp = client.get("/mxcube/api/v0.1/sample_changer/loaded_sample")
    data = json.loads(resp.data)

    assert isinstance(data["address"], unicode)
    assert isinstance(data["barcode"], unicode)
예제 #27
0
def test_get_phase_list(client):
    """
    Checks retrieval of phase list and if the returned data is list.
    Does not test if the actual phases in the list are correct
    """
    resp = client.get("/mxcube/api/v0.1/diffractometer/phaselist")
    data = json.loads(resp.data)

    assert isinstance(data["current_phase"], list)
예제 #28
0
def test_get_data_path(client):
    """
    Retrieve data path, this is specific for each beamline.
    """

    resp = client.get("/mxcube/api/v0.1/beamline/datapath")
    data = json.loads(resp.data)
    assert isinstance(data["path"], unicode)
    assert len(data) > 0
예제 #29
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
    )
예제 #30
0
def test_get_global_state(client):
    """
    Checks retrieval of the sample changer global state
    """
    resp = client.get("/mxcube/api/v0.1/sample_changer/get_global_state")
    data = json.loads(resp.data)

    assert isinstance(data["commands_state"], dict)
    assert isinstance(data["message"], unicode)
    assert isinstance(data["state"], dict)
예제 #31
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
    )
예제 #32
0
def test_get_default_char_acq_params(client):
    """Test if we get the right default characterisation acq params."""
    resp = client.get("/mxcube/api/v0.1/queue/char_acq")
    actual = json.loads(resp.data)

    # some values are taken from current value/position which is random, so ignore those
    actual["acq_parameters"].pop("osc_start")
    actual["acq_parameters"].pop("energy")
    actual["acq_parameters"].pop("resolution")
    actual["acq_parameters"].pop("transmission")
    assert resp.status_code == 200 and actual == default_char_acq_params
예제 #33
0
def test_get_beam_info(client):
    """
    Tests retrieval of information regarding the beam, and that the data is
    returned on the expected format
    """
    resp = client.get("/mxcube/api/v0.1/beam/info")
    data = json.loads(resp.data)

    assert isinstance(data["currentAperture"], int)
    assert len(data["apertureList"]) >= 0
    assert isinstance(data["position"][0], int)
    assert isinstance(data["position"][1], int)
    assert isinstance(data["size_x"], float)
    assert isinstance(data["size_y"], float)
예제 #34
0
def test_get_initial_state(client):
    """
    Checks retrieval of the sample changer initial state
    """
    resp = client.get("/mxcube/api/v0.1/sample_changer/get_initial_state")
    data = json.loads(resp.data)

    assert isinstance(data["cmds"], dict)
    assert isinstance(data["cmds"]["cmds"], list)
    assert isinstance(data["contents"], dict)
    assert isinstance(data["global_state"], dict)
    assert isinstance(data["loaded_sample"], dict)
    assert isinstance(data["msg"], unicode)
    assert isinstance(data["state"], unicode)
def test_get_beam_info(client):
    """
    Tests retrieval of information regarding the beam, and that the data is
    returned on the expected format
    """
    resp = client.get("/mxcube/api/v0.1/beam/info")
    data = json.loads(resp.data)

    assert isinstance(data["currentAperture"], int)
    assert len(data["apertureList"]) >= 0
    assert isinstance(data["position"][0], int)
    assert isinstance(data["position"][1], int)
    assert isinstance(data["size_x"], float)
    assert isinstance(data["size_y"], float)
예제 #36
0
def test_set_phase(client):
    """
    Sets phase to a phase P (any phase in the phase list), checks if the
    actual phase after set_phase is P.

    Moves the phase back to the original phase OP, and verifies that the
    current phase after the move is OP
    """
    # Get current phase
    resp = client.get("/mxcube/api/v0.1/diffractometer/phase")
    original_phase = json.loads(resp.data)["current_phase"]

    resp = client.get("/mxcube/api/v0.1/diffractometer/phaselist")
    data = json.loads(resp.data)
    phase_list = data["current_phase"]

    new_phase = phase_list[random.randint(0, len(phase_list) - 1)]

    # Set a phase (any in the phase list)
    resp = client.put(
        "/mxcube/api/v0.1/diffractometer/phase",
        data=json.dumps({"phase": new_phase}),
        content_type="application/json",
    )

    # Retrieve current phase
    resp = client.get("/mxcube/api/v0.1/diffractometer/phase")
    actual_phase = json.loads(resp.data)["current_phase"]

    # Move phase back to its original value
    resp = client.put(
        "/mxcube/api/v0.1/diffractometer/phase",
        data=json.dumps({"phase": original_phase}),
        content_type="application/json",
    )

    assert new_phase == actual_phase
예제 #37
0
def test_set_aperture(client):
    """
    Sets the aperture to an aperture AP belonging to the list of valid
    apertures and verifies that the aperture actually changed to AP.

    Moves the aperture back to its original value and verifies that the
    original value also is the current
    """

    resp = client.get("/mxcube/api/v0.1/diffractometer/aperture")
    data = json.loads(resp.data)

    original_aperture = data["currentAperture"]

    ap = data["apertureList"][random.randint(0, len(data["apertureList"]) - 1)]

    resp = client.put(
        "/mxcube/api/v0.1/diffractometer/aperture",
        data=json.dumps({"diameter": ap}),
        content_type="application/json",
    )

    resp = client.get("/mxcube/api/v0.1/diffractometer/aperture")
    actual_aperture = json.loads(resp.data)["currentAperture"]

    resp = client.put(
        "/mxcube/api/v0.1/diffractometer/aperture",
        data=json.dumps({"diameter": original_aperture}),
        content_type="application/json",
    )

    resp = client.get("/mxcube/api/v0.1/diffractometer/aperture")
    actual_original_aperture = json.loads(resp.data)["currentAperture"]

    assert ap == actual_aperture
    assert actual_original_aperture == original_aperture
예제 #38
0
def test_get_movables_state(client):
    """
    Checks if atleast the key elements ['sampx', 'sampy', 'phi', 'focus',
    'zoom', 'phiy', 'phiz', 'BackLight'] that can be assumed to exist on all
    diffractometers used with MXCuBE exists in the data returned.

    Does not check the structure of each movable
    """
    resp = client.get("/mxcube/api/v0.1/diffractometer/movables/state")
    data = json.loads(resp.data)

    keys = [
        "sampx", "sampy", "phi", "focus", "zoom", "phiy", "phiz", "BackLight"
    ]

    for key in keys:
        assert key in data
예제 #39
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
    )
예제 #40
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"
    )
예제 #41
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"
    )
예제 #42
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
    )
예제 #43
0
def test_add_and_get_task(client):
    """Test if we can add a task to the sample."""
    resp = client.get("/mxcube/api/v0.1/queue")
    assert (
        resp.status_code == 200 and len(json.loads(resp.data).get("1:05")["tasks"]) == 1
    )
예제 #44
0
def test_get_main(client):
    """Test if we can get the home page."""
    assert client.get("/").status_code == 200
예제 #45
0
def test_add_and_get_sample(client, add_sample):
    """Test if we can add a sample. The sample is added by a fixture."""
    rv = client.get("/mxcube/api/v0.1/queue")
    assert rv.status_code == 200 and json.loads(rv.data).get("1:05")
예제 #46
0
def test_queue_get(client):
    """Test if we can get the queue."""
    rv = client.get("/mxcube/api/v0.1/queue")
    assert rv.status_code == 200
예제 #47
0
def test_get_default_char_params(client):
    """Test if we get the right default characterisation params."""

    resp = client.get("/mxcube/api/v0.1/queue/char")
    actual = json.loads(resp.data)
    assert resp.status_code == 200 and actual == default_char_params
예제 #48
0
def test_get_default_xrf_parameters(client):
    """Test if we get the right default xrf params."""
    rv = client.get("/mxcube/api/v0.1/queue/xrf")
    assert rv.status_code == 200 and json.loads(rv.data) == default_xrf_parameters
예제 #49
0
def test_get_default_xrf_parameters(client):
    """Test if we get the right default xrf params."""

    resp = client.get("/mxcube/api/v0.1/queue/xrf")
    actual = json.loads(resp.data)
    assert resp.status_code == 200 and json.loads(resp.data) == default_xrf_parameters
예제 #50
0
def test_queue_get_item(client, add_sample):
    """Test if we the queue has the intial sample, only mockups hwobj."""
    rv = client.get("/mxcube/api/v0.1/queue")
    assert rv.status_code == 200 and json.loads(rv.data).get("1:01")
예제 #51
0
def test_get_default_char_params(client):
    """Test if we get the right default characterisation params."""
    resp = client.get("/mxcube/api/v0.1/queue/char")
    actual = json.loads(resp.data)
    assert resp.status_code == 200 and actual == default_char_params
예제 #52
0
def test_add_and_get_task(client, add_sample, add_task):
    """Test if we can add a task to the sample."""
    rv = client.get("/mxcube/api/v0.1/queue")
    assert rv.status_code == 200 and len(json.loads(rv.data).get("1:05")["tasks"]) == 1