Exemplo n.º 1
0
def test_required_values(attr):
    disease = factories.Disease()

    for arg in REQUIRED_ARGS:
        assert getattr(disease, arg, None) is not None

    setattr(disease, attr, None)
    db_session.add(disease)
    with pytest.raises(IntegrityError):
        db_session.commit()
    db_session.rollback()
Exemplo n.º 2
0
def test_required_values(attr):
    patient = factories.Patient()

    for arg in REQUIRED_ARGS:
        assert getattr(patient, arg, None) is not None

    setattr(patient, attr, None)
    db_session.add(patient)
    with pytest.raises(IntegrityError):
        db_session.commit()
    db_session.rollback()
Exemplo n.º 3
0
def handle_request(**kwargs):
    g.logger.info('patients.create', payload=str(kwargs))
    try:
        patient_args = validate_kwargs(**kwargs)
        patient = Patient(**patient_args)
        db_session.add(patient)
        db_session.commit()
        return patient_schema.dump(patient).data
    except ValidationError as e:
        db_session.rollback()
        description = {'description': f'{e.__class__.__name__}: {str(e)}'}
        handle_exception(e, 'create_patient', 400, description)
Exemplo n.º 4
0
def handle_request(**kwargs):
    g.logger.info('diseases.create', payload=str(kwargs))
    try:
        disease_args = validate_kwargs(**kwargs)
        disease = Disease(**disease_args)
        db_session.add(disease)
        db_session.commit()
        return disease_schema.dump(disease).data
    except ValidationError as e:
        db_session.rollback()
        description = {'description': f'{e.__class__.__name__}: {str(e)}'}
        handle_exception(e, 'create_disease', 400, description)
Exemplo n.º 5
0
def test_patients_diseases_n_to_1():
    patient1 = factories.Patient()
    patient2 = factories.Patient()

    disease = factories.Disease(patients=[patient1, patient2])

    db_session.add(disease)
    db_session.commit()

    assert patient1.diseases == [disease]
    assert patient2.diseases == [disease]

    db_session.rollback()
Exemplo n.º 6
0
def test_patients_diseases_1_to_n():
    disease1 = factories.Disease()
    disease2 = factories.Disease()
    disease3 = factories.Disease()

    patient = factories.Patient(diseases=[disease1, disease2, disease3])

    db_session.add(patient)
    db_session.commit()

    assert disease1.patients == [patient]
    assert disease2.patients == [patient]
    assert disease3.patients == [patient]

    db_session.rollback()
Exemplo n.º 7
0
def test_default_values():
    disease = factories.Disease()

    assert disease.id is None
    assert disease.created is None
    assert disease.updated is None

    db_session.add(disease)
    db_session.commit()

    assert disease.id is not None
    assert disease.created is not None
    assert disease.updated is None

    disease.name = 'Cancer'
    db_session.commit()

    assert disease.updated is not None
Exemplo n.º 8
0
def test_default_values():
    patient = factories.Patient()

    assert patient.id is None
    assert patient.created is None
    assert patient.updated is None

    db_session.add(patient)
    db_session.commit()

    assert patient.id is not None
    assert patient.created is not None
    assert patient.updated is None

    patient.name = 'Jon'
    patient.surname = 'Snow'
    db_session.commit()

    assert patient.updated is not None