Exemple #1
0
def test_change_data_wrong(import_id, correct_citizen_data):
    assert not Citizen.change_data(5, 7, {'apartment': 9})
    Citizen.create_citizen(import_id, correct_citizen_data)
    citizen_id = correct_citizen_data['citizen_id']
    assert not Citizen.change_data(import_id, citizen_id, {})
    assert not Citizen.change_data(import_id, citizen_id, {'town': None})
    assert not Citizen.change_data(import_id, citizen_id, {'citizen_id': 10})
    assert not Citizen.change_data(import_id, citizen_id, {'relatives': [15]})
Exemple #2
0
def test_change_relatives(mocker, correct_import_data):
    mocker.patch('api.database_worker.DataBaseWorker.commit')
    import_id = Import.create_import(correct_import_data)

    citizen_id = correct_import_data[0]['citizen_id']
    old_relatives = Relations.get_all_relatives_id(import_id, citizen_id)
    assert Citizen.change_data(import_id, citizen_id, {'relatives': []})
    for relative_id in old_relatives:
        assert citizen_id not in Relations.get_all_relatives_id(import_id, relative_id)

    another_citizen_id = correct_import_data[1]['citizen_id']
    assert citizen_id not in Relations.get_all_relatives_id(import_id, another_citizen_id)
    assert Citizen.change_data(import_id, citizen_id, {'relatives': [another_citizen_id]})
    assert citizen_id in Relations.get_all_relatives_id(import_id, another_citizen_id)
    assert another_citizen_id in Relations.get_all_relatives_id(import_id, citizen_id)
Exemple #3
0
def handle_change_citizen_request(import_id, citizen_id):
    if request.method == 'PATCH':
        data = request.json
        if not data:
            return json.dumps({}), 400
        citizen = Citizen.change_data(int(import_id), int(citizen_id), data)
        if not citizen:
            return json.dumps({}), 400
        return json.dumps(citizen.as_dict(), ensure_ascii=False), 200
    return json.dumps({}), 405  # pragma:no cover
Exemple #4
0
def test_change_data_ok(mocker, import_id, correct_citizen_data):
    mocker.patch('api.database_worker.DataBaseWorker.commit')
    Citizen.create_citizen(import_id, correct_citizen_data)
    citizen = Citizen.change_data(import_id, correct_citizen_data['citizen_id'], {
        "name": "Иванова Мария Леонидовна",
        "town": "Новосибирск",
        "apartment": 9,
        "birth_date": '23.12.1999'})
    assert citizen
    assert citizen.name == "Иванова Мария Леонидовна"
    assert citizen.town == "Новосибирск"
    assert citizen.apartment == 9