Ejemplo n.º 1
0
def test_get_samples_using_description(test_client):
    """
    Test 'get_samples' method using a description
    """

    context = test_client

    sample_1, sample_2, _, patient_1 = load_test_samples()
    sample_3, sample_4, _, patient_2 = load_test_samples()

    with context:
        _, code = operations.add_patients(patient_1)
        assert code == 201
        _, code = operations.add_patients(patient_2)
        assert code == 201

        _, code = operations.add_samples(sample_1)
        assert code == 201
        _, code = operations.add_samples(sample_2)
        assert code == 201

        _, code = operations.add_samples(sample_3)
        assert code == 201
        _, code = operations.add_samples(sample_4)
        assert code == 201

        response, code = operations.get_samples(patient_1["patient_id"], description=sample_1["description"])
        assert code == 200
        assert response["patient_id"] == sample_1["patient_id"] 
Ejemplo n.º 2
0
def test_get_samples_with_tags(test_client):
    """
    Test 'get_samples' using tags
    """
    context = test_client
    sample_1, sample_2, patient_1 = load_test_samples_with_tags()
    patient_id = patient_1["patient_id"]
    tags = sample_1["tags"]

    with context:
        _, code = operations.add_patients(patient_1)
        assert code == 201

        _, code = operations.add_samples(sample_1)
        assert code == 201
        _, code = operations.add_samples(sample_2)
        assert code == 201

        response, code = operations.get_samples(patient_id, tags)
        assert code == 200
        assert response["patient_id"] == patient_id
        assert len(response["samples"]) == 2

        response, code = operations.get_samples(patient_id, ["Adult"])
        assert code == 200
        assert response["patient_id"] == patient_id
        assert len(response["samples"]) == 1

        response, code = operations.get_samples(
            patient_id, ["Non existent tag"]
        )
        assert code == 200
        assert not response
Ejemplo n.º 3
0
def test_get_samples(test_client):
    """
    Test 'get_samples' method
    """

    context = test_client

    sample_1, sample_2, _, patient_1 = load_test_samples()
    sample_3, sample_4, _, patient_2 = load_test_samples()

    with context:
        _, code = operations.add_patients(patient_1)
        assert code == 201
        _, code = operations.add_patients(patient_2)
        assert code == 201

        _, code = operations.add_samples(sample_1)
        assert code == 201
        _, code = operations.add_samples(sample_2)
        assert code == 201

        _, code = operations.add_samples(sample_3)
        assert code == 201
        _, code = operations.add_samples(sample_4)
        assert code == 201

        response, code = operations.get_samples(patient_1["patient_id"])
        samples = [s["sample_id"] for s in response["samples"]]
        descriptions = [s["description"] for s in response["samples"]]
        assert code == 200
        assert len(samples) == 2
        assert sample_1["sample_id"] in samples
        assert sample_1["description"] in descriptions
        assert sample_2["sample_id"] in samples
        assert sample_2["description"] in descriptions
Ejemplo n.º 4
0
def test_add_samples_with_tags(test_client):
    """
    Test adding samples with tags
    """
    context = test_client
    sample_1, sample_2, patient_1 = load_test_samples_with_tags()

    with context:
        _, code = operations.add_patients(patient_1)
        assert code == 201

        _, code = operations.add_samples(sample_1)
        assert code == 201
        _, code = operations.add_samples(sample_2)
        assert code == 201
Ejemplo n.º 5
0
def test_add_sample_twice(test_client):
    """
    Test adding the same sample twice
    """
    context = test_client
    sample_1, _, _, patient_1 = load_test_samples()

    with context:
        _, code = operations.add_patients(patient_1)
        assert code == 201

        response, code = operations.add_samples(sample_1)
        assert code == 201
        assert response["code"] == 201

        response, code = operations.add_samples(sample_1)
        assert code == 400
        assert response["code"] == 400
Ejemplo n.º 6
0
def test_add_sample_no_patient(test_client):
    """
    Test adding sample where no patient information
    is present on patient table 
    """

    context = test_client
    _, _, sample, _ = load_test_samples()

    with context:
        response, code = operations.add_samples(sample)
        assert code == 400
        assert response["code"] == 400
Ejemplo n.º 7
0
def test_add_samples(test_client):
    """
    Test 'add_samples' method
    """
    context = test_client
    sample_1, sample_2, _, patient_1 = load_test_samples()

    with context:
        _, code = operations.add_patients(patient_1)
        assert code == 201

        response, code = operations.add_samples(sample_1)
        assert code == 201
        assert response["code"] == 201
Ejemplo n.º 8
0
def test_get_samples_invalid_patient_id(test_client):
    """
    Test 'get_samples' when patient_id values are invalid
    """
    context = test_client
    sample_1, sample_2, _, patient_1 = load_test_samples()
    _, _, _, patient_2 = load_test_samples()

    with context:
        _, code = operations.add_patients(patient_1)
        assert code == 201

        _, code = operations.add_samples(sample_1)
        assert code == 201
        _, code = operations.add_samples(sample_2)
        assert code == 201

        _, code = operations.add_patients(patient_2)
        assert code == 201

        response, code = operations.get_samples(patient_2["patient_id"])
        assert code == 200
        assert not response
Ejemplo n.º 9
0
def test_add_samples_no_description(test_client):
    """
    Test adding sample with missing description
    """
    context = test_client
    sample_1, _, _, patient_1 = load_test_samples()
    del sample_1["description"]
 
    with context:
        _, code = operations.add_patients(patient_1)
        assert code == 201

        response, code = operations.add_samples(sample_1)
        assert code == 400
        assert response["code"] == 400    
Ejemplo n.º 10
0
def test_add_segments(test_client):
    """
    Test 'add_segments' method
    """

    context = test_client

    patient, sample, segment, _, _ = load_test_segment()

    with context:
        response, code = operations.add_patients(patient)
        assert code == 201
        assert response["code"] == 201

        response, code = operations.add_samples(sample)
        assert code == 201
        assert response["code"] == 201

        response, code = operations.add_segments(segment)
        assert code == 201
        assert response["code"] == 201
Ejemplo n.º 11
0
def test_add_segment_no_patient(test_client):
    """
    Test "add_segment" method when patient is not provided
    """

    context = test_client

    patient, sample, segment, _, _ = load_test_segment()

    segment["patient_id"] = ""

    with context:
        response, code = operations.add_patients(patient)
        assert code == 201
        assert response["code"] == 201

        response, code = operations.add_samples(sample)
        assert code == 201
        assert response["code"] == 201

        response, code = operations.add_segments(segment)
        assert code == 400
        assert response["code"] == 400
Ejemplo n.º 12
0
def test_get_segment(test_client):
    """
    Test 'get_segments' method
    """

    context = test_client

    patient_1, sample_1, segment_1, segment_2, segment_3 = load_test_segment()
    patient_2, sample_2, segment_4, segment_5, segment_6 = load_test_segment()

    patient_id = segment_1["patient_id"]
    sample_id = segment_1["sample_id"]
    chromosome_number = segment_1["segments"][0]["chromosome_number"]
    start_position = segment_1["segments"][0]["start_position"]
    end_position = segment_1["segments"][0]["end_position"]
    copy_number = segment_1["segments"][0]["copy_number"]
    copy_number_ploidy_corrected = segment_1["segments"][0][
        "copy_number_ploidy_corrected"
    ]

    with context:
        response, code = operations.add_patients(patient_1)
        assert code == 201
        assert response["code"] == 201
        response, code = operations.add_patients(patient_2)
        assert code == 201
        assert response["code"] == 201

        response, code = operations.add_samples(sample_1)
        assert code == 201
        assert response["code"] == 201
        response, code = operations.add_samples(sample_2)
        assert code == 201
        assert response["code"] == 201

        response, code = operations.add_segments(segment_1)
        assert code == 201
        assert response["code"] == 201

        response, code = operations.add_segments(segment_2)
        assert code == 201
        assert response["code"] == 201

        response, code = operations.add_segments(segment_3)
        assert code == 201
        assert response["code"] == 201

        response, code = operations.add_segments(segment_4)
        assert code == 201
        assert response["code"] == 201

        response, code = operations.add_segments(segment_5)
        assert code == 201
        assert response["code"] == 201

        response, code = operations.add_segments(segment_6)
        assert code == 201
        assert response["code"] == 201

        response, code = operations.get_segments(
            patient_id,
            sample_id,
            chromosome_number,
            start_position,
            end_position,
        )
        assert len(response) == 1
        assert code == 200

        assert response[0]["chromosome_number"] == chromosome_number
        assert response[0]["start_position"] == start_position
        assert response[0]["end_position"] == end_position
        assert response[0]["copy_number"] == copy_number
        assert (
            response[0]["copy_number_ploidy_corrected"]
            == copy_number_ploidy_corrected
        )

        response, code = operations.get_segments(
            patient_id,
            sample_id,
            chromosome_number,
            start_position=12522,
            end_position=34326,
        )
        
        assert code == 200
        assert len(response) == 2