def test_update_data(self) -> None: """Update custom data of user profile.""" old_data = {'user_type': 'amateur'} new_data = {'user_type': 'amateur', 'special_field': 42} user_id = User.from_alias('tomb_raider').id assert User.from_id(user_id).data == old_data User.update(user_id, special_field=42) assert User.from_id(user_id).data == new_data User.update(user_id, data=old_data) assert User.from_id(user_id).data == old_data
def test_embedded(self) -> None: """Test embedded method to check JSON-serialization and full join.""" assert Recommendation.from_id(1).to_json(join=True) == { 'id': 1, 'group_id': 1, 'tag_id': 1, 'time': '2020-10-24 20:02:00' + ('' if config.backend == 'sqlite' else '-04:00'), 'priority': 1, 'object_id': 1, 'facility_id': 1, 'user_id': 2, 'forecast_id': 1, 'predicted_observation_id': 11, 'observation_id': 19, 'accepted': True, 'rejected': False, 'data': {}, 'group': RecommendationGroup.from_id(1).to_json(join=True), 'tag': RecommendationTag.from_id(1).to_json(join=True), 'user': User.from_id(2).to_json(join=True), 'facility': Facility.from_id(1).to_json(join=True), 'object': Object.from_id(1).to_json(join=True), 'forecast': Forecast.from_id(1).to_json(join=True), 'predicted': Observation.from_id(11).to_json(join=True), 'observed': Observation.from_id(19).to_json(join=True), }
def test_from_id_missing(self) -> None: """Test exception on missing user `id`.""" with pytest.raises(NotFound): User.from_id(-1)
def test_from_id(self, testdata: TestData) -> None: """Test loading user profile from `id`.""" # NOTE: `id` not set until after insert for i, user in enumerate(testdata['user']): assert User.from_id(i + 1).alias == user['alias']
def test_from_user(self) -> None: """Test loading client from `user`.""" for id in range(1, 4): assert id == Client.from_user(id).user_id == User.from_id(id).id
def test_relationship_user(self) -> None: """Test user foreign key relationship.""" for id in range(1, 4): assert id == Client.from_user(id).user.id == User.from_id(id).id