"""Push config API tests.""" def _create_profile(auth_client) -> str: response = auth_client.post( "/api/profiles", json={"name": "小明", "gender": "male"}, ) assert response.status_code == 201 return response.json()["id"] def test_create_list_update_push_config(auth_client): profile_id = _create_profile(auth_client) response = auth_client.put( "/api/push-configs", json={ "child_profile_id": profile_id, "push_time": "20:30", "push_days": [1, 3, 5], "enabled": True, }, ) assert response.status_code == 201 data = response.json() assert data["child_profile_id"] == profile_id assert data["push_time"].startswith("20:30") assert data["push_days"] == [1, 3, 5] assert data["enabled"] is True response = auth_client.get("/api/push-configs") assert response.status_code == 200 payload = response.json() assert payload["total"] == 1 response = auth_client.put( "/api/push-configs", json={ "child_profile_id": profile_id, "enabled": False, }, ) assert response.status_code == 200 data = response.json() assert data["enabled"] is False assert data["push_time"].startswith("20:30") assert data["push_days"] == [1, 3, 5] def test_push_config_validation(auth_client): profile_id = _create_profile(auth_client) response = auth_client.put( "/api/push-configs", json={"child_profile_id": profile_id}, ) assert response.status_code == 400 response = auth_client.put( "/api/push-configs", json={ "child_profile_id": profile_id, "push_time": "19:00", "push_days": [7], }, ) assert response.status_code == 400 response = auth_client.put( "/api/push-configs", json={ "child_profile_id": profile_id, "push_time": None, }, ) assert response.status_code == 400