from datetime import datetime, timedelta import pytest from atheneum.model import UserToken, User from atheneum.service import patch_service def test_patch_models(): user = User() user.name = 'TestUser' user.version = 1 user.last_login_time = datetime.now() - timedelta(days=1) user_patch = User() user_patch.name = 'TestUser' user_patch.version = 1 user_patch.last_login_time = datetime.now() patched_user = patch_service.patch(user, user_patch) assert patched_user.version > 1 assert patched_user.last_login_time == user_patch.last_login_time def test_patch_of_different_types(): user = User() user_token = UserToken() with pytest.raises(ValueError) as error_info: patch_service.patch(user, user_token) def test_patch_different_ids(): user1 = User() user1.id = 1 user2 = User() user2.id = 2 with pytest.raises(ValueError) as error_info: patch_service.patch(user1, user2) def test_patch_different_versions(): user1 = User() user1.version = 1 user2 = User() user2.version = 2 with pytest.raises(ValueError) as error_info: patch_service.patch(user1, user2) def test_patch_restricted_attributes(): user1 = User() user1.version = 1 user1.name = 'Bob' user2 = User() user2.version = 1 user2.name = 'Chris' with pytest.raises(ValueError) as error_info: patch_service.patch(user1, user2)