from unittest.mock import MagicMock, patch


def test_post_media_record_json_and_auth():
    # Arrange
    import main

    mock_resp = MagicMock()
    mock_resp.status_code = 201
    payload = {
        "id": "h1",
        "name": "a.jpg",
        "path": "/x/a.jpg",
        "mediaType": "Image",
        "mediaStatus": 1,
        "userId": "u1",
    }
    with patch.object(main.http_requests, "post", return_value=mock_resp) as post:
        # Act
        ok = main._post_media_record(payload, "tok")
    # Assert
    assert ok is True
    post.assert_called_once()
    args, kwargs = post.call_args
    assert kwargs["json"] == payload
    assert kwargs["headers"]["Authorization"] == "Bearer tok"


def test_put_media_status_json():
    # Arrange
    import main

    mock_resp = MagicMock()
    mock_resp.status_code = 204
    with patch.object(main.http_requests, "put", return_value=mock_resp) as put:
        # Act
        ok = main._put_media_status("mid", 2, "t")
    # Assert
    assert ok is True
    put.assert_called_once()
    _args, kwargs = put.call_args
    assert kwargs["json"] == {"mediaStatus": 2}
    assert "/api/media/mid/status" in put.call_args[0][0]
