Esempio n. 1
0
def test_update_location(user: User):
    parent_location = locations.create_location("Parent Location",
                                                "This is an example location",
                                                None, user.id)
    location = locations.create_location("Location",
                                         "This is an example location", None,
                                         user.id)
    assert len(locations.get_locations()) == 2
    locations.update_location(location.id, "Updated Location",
                              "This is a location description", None, user.id)
    assert len(locations.get_locations()) == 2
    location = locations.get_location(location.id)
    assert location.name == "Updated Location"
    assert location.description == "This is a location description"
    assert location.parent_location_id is None
    locations.update_location(location.id, "Updated Location",
                              "This is a location description",
                              parent_location.id, user.id)
    location = locations.get_location(location.id)
    assert location.parent_location_id == parent_location.id
    user_log_entries = user_log.get_user_log_entries(user.id)
    assert [
        e for e in user_log_entries
        if e.data.get('location_id', -1) == location.id
        and e.type == UserLogEntryType.UPDATE_LOCATION
    ]
Esempio n. 2
0
def test_create_location_with_invalid_parent_location(user: User):
    parent_location = locations.create_location("Parent Location",
                                                "This is an example location",
                                                None, user.id)
    assert len(locations.get_locations()) == 1
    with pytest.raises(errors.LocationDoesNotExistError):
        locations.create_location("Example Location",
                                  "This is an example location",
                                  parent_location.id + 1, user.id)
    assert len(locations.get_locations()) == 1
Esempio n. 3
0
def test_create_location(user: User):
    assert len(locations.get_locations()) == 0
    locations.create_location("Example Location",
                              "This is an example location", None, user.id)
    assert len(locations.get_locations()) == 1
    location = locations.get_locations()[0]
    assert location.name == "Example Location"
    assert location.description == "This is an example location"
    assert location.parent_location_id is None
    user_log_entries = user_log.get_user_log_entries(user.id)
    assert user_log_entries[-1].type == UserLogEntryType.CREATE_LOCATION
    assert user_log_entries[-1].data['location_id'] == location.id
Esempio n. 4
0
def test_create_location_with_parent_location(user: User):
    parent_location = locations.create_location("Parent Location",
                                                "This is an example location",
                                                None, user.id)
    assert len(locations.get_locations()) == 1
    user_log_entries = user_log.get_user_log_entries(user.id)
    assert len(user_log_entries) == 1
    location = locations.create_location("Example Location",
                                         "This is an example location",
                                         parent_location.id, user.id)
    assert len(locations.get_locations()) == 2
    location = locations.get_location(location.id)
    assert location.name == "Example Location"
    assert location.description == "This is an example location"
    assert location.parent_location_id == parent_location.id
    user_log_entries = user_log.get_user_log_entries(user.id)
    assert len(user_log_entries) == 2
    user_log_entry = [
        e for e in user_log_entries
        if e.data.get('location_id', -1) == location.id
    ][0]
    assert user_log_entry.type == UserLogEntryType.CREATE_LOCATION
    assert user_log_entry.data['location_id'] == location.id