def test_partial_update(self, api_client, user): api_client.force_authenticate(user) new_profile_data = ProfileFactory.build() new_user_data = UserFactory.build() data = { "description": new_profile_data.description, "last_name": new_user_data.last_name, } response = api_client.patch(self.profile_detail_url, data) assert response.status_code == status.HTTP_200_OK user.refresh_from_db() assert user.last_name == data["last_name"] assert user.profile.description == data["description"]
def test_partial_update(self): user = UserFactory() profile = ProfileFactory(user=user) new_profile_data = ProfileFactory.build() new_user_data = UserFactory.build() data = { "description": new_profile_data.description, "last_name": new_user_data.last_name, } serializer = ProfileSerializer(instance=profile, data=data, partial=True) assert serializer.is_valid(), serializer.errors serializer.save() user.refresh_from_db() assert user.last_name == data["last_name"] profile.refresh_from_db() assert profile.description == data["description"]
def test_update(self): user = UserFactory() profile = ProfileFactory(user=user) new_profile_data = ProfileFactory.build() new_user_data = UserFactory.build() data = { "birth_date": new_profile_data.birth_date, "description": new_profile_data.description, "first_name": new_user_data.first_name, "last_name": new_user_data.last_name, "username": new_user_data.username, } serializer = ProfileSerializer(instance=profile, data=data) assert serializer.is_valid(), serializer.errors profile = serializer.save() assert profile.description == data["description"] assert profile.birth_date == data["birth_date"] assert profile.user.last_name == data["last_name"] assert profile.user.first_name == data["first_name"] assert profile.user.username == data["username"]