def test_donorHospitalRequestPage_submit_failed(mock_ord, mock_donor,
                                                mock_recipient, mock_flash,
                                                mock_g, mock_ren, mock_request,
                                                mock_urs):
    mock_ord.return_value = fakeOpenRequestDetails(
        "requestid",
        [("*****@*****.**", "*****@*****.**", "organ", "pending")])
    mock_donor.return_value = fakeDonor(
        "*****@*****.**", {"donor", "*****@*****.**", "liver", "hosptal1"})
    mock_recipient.return_value = fakeRecipient(
        "*****@*****.**",
        {"recipient", "*****@*****.**", "liver", "hosptal2"})
    drview.request.method = 'POST'
    drview.request.form = mock_request_form({
        "username": "******",
        "type": "donor",
        "submit": "submit",
        "organ": ["liver", "heart"]
    })
    mock_urs.return_value = fakeUpdateRequestStatus("request", "requestid",
                                                    "*****@*****.**", "body",
                                                    False, False)
    mock_flash.return_value = "Error updating request status. Please try again later!"
    mock_ren.return_value = "<h2>donor receiver request</h2>"
    assert drview.donorHospitalRequestPage(
        "requestid") == "<h2>donor receiver request</h2>"
def test_donorHospitalRequestPage_submit(mock_ord, mock_donor, mock_recipient,
                                         mock_flash, mock_g, mock_ren,
                                         mock_request, mock_urs, mock_url_for,
                                         mock_redirect):
    mock_ord.return_value = fakeOpenRequestDetails(
        "requestid",
        [("*****@*****.**", "*****@*****.**", "organ", "pending")])
    mock_donor.return_value = fakeDonor(
        "*****@*****.**", {"donor", "*****@*****.**", "liver", "hosptal1"})
    mock_recipient.return_value = fakeRecipient(
        "*****@*****.**",
        {"recipient", "*****@*****.**", "liver", "hosptal2"})
    drview.request.method = 'POST'
    drview.request.form = mock_request_form({
        "username": "******",
        "type": "donor",
        "submit": "submit",
        "organ": ["liver", "heart"]
    })
    mock_urs.return_value = fakeUpdateRequestStatus("request", "requestid",
                                                    "*****@*****.**", "body",
                                                    True, True)
    mock_flash.return_value = "Request Status updated successfully"
    mock_url_for.return_value = "http://url"
    mock_redirect.return_value = "<h2>hospital home</h2"
    assert drview.donorHospitalRequestPage(
        "requestid") == "<h2>hospital home</h2"
def test_donorHospitalRequestPage_upload_not_updated(mock_ord, mock_donor,
                                                     mock_recipient,
                                                     mock_flash, mock_binr,
                                                     mock_g, mock_ren,
                                                     mock_request, mock_umr):
    mock_ord.return_value = fakeOpenRequestDetails(
        "requestid",
        [("*****@*****.**", "*****@*****.**", "organ", "pending")])
    mock_donor.return_value = fakeDonor(
        "*****@*****.**", {"donor", "*****@*****.**", "liver", "hosptal1"})
    mock_recipient.return_value = fakeRecipient(
        "*****@*****.**",
        {"recipient", "*****@*****.**", "liver", "hosptal2"})
    drview.request.method = 'POST'
    drview.request.files = {"reports": open("test.txt", "w+")}
    drview.request.form = mock_request_form({
        "username": "******",
        "type": "donor",
        "upload": "upload",
        "organ": ["liver", "heart"]
    })
    mock_umr.return_value = fakeUpdateMedicalReports("*****@*****.**",
                                                     "reports", "donor", False)
    mock_flash.return_value = "Insertion Error!"
    mock_binr.return_value = "reports"
    mock_ren.return_value = "<h2>donor receiver request"
    assert drview.donorHospitalRequestPage(
        "requestid") == "<h2>donor receiver request"
def test_donorHospitalRequestPage_nodata(mock_ord, mock_donor, mock_recipient,
                                         mock_flash, mock_g, mock_ren,
                                         mock_request):
    mock_ord.return_value = fakeOpenRequestDetails(
        "requestid",
        [("*****@*****.**", "*****@*****.**", "organ", "pending")])
    mock_donor.return_value = fakeDonor("*****@*****.**", None)
    mock_recipient.return_value = fakeRecipient("*****@*****.**", None)
    drview.request.method = 'POST'
    mock_flash.return_value = "No donor/reciever available for this Request!"
    mock_ren.return_value = "<h2>donor receiver request</h2>"
    assert drview.donorHospitalRequestPage(
        "requestid") == "<h2>donor receiver request</h2>"
def test_donorHospitalRequestPage_email(mock_ord, mock_donor, mock_recipient,
                                        mock_flash, mock_g, mock_ren,
                                        mock_request, mock_mailsend):
    mock_ord.return_value = fakeOpenRequestDetails(
        "requestid",
        [("*****@*****.**", "*****@*****.**", "organ", "pending")])
    mock_donor.return_value = fakeDonor(
        "*****@*****.**", {"donor", "*****@*****.**", "liver", "hosptal1"})
    mock_recipient.return_value = fakeRecipient(
        "*****@*****.**",
        {"recipient", "*****@*****.**", "liver", "hosptal2"})
    drview.request.method = 'POST'
    drview.request.form = mock_request_form({
        "username": "******",
        "type": "donor",
        "email": "email",
        "organ": ["liver", "heart"]
    })
    mock_flash.return_value = "Email Sent Successfully"
    mock_mailsend.return_value = "sent"
    mock_ren.return_value = "<h2>donor receiver request</h2>"
    assert drview.donorHospitalRequestPage(
        "requestid") == "<h2>donor receiver request</h2>"
def test_donorHospitalRequestPage_report(mock_ord, mock_donor, mock_recipient,
                                         mock_g, mock_request, mock_vur,
                                         mock_bytesio, mock_send_file):
    mock_ord.return_value = fakeOpenRequestDetails(
        "requestid",
        [("*****@*****.**", "*****@*****.**", "organ", "pending")])
    mock_donor.return_value = fakeDonor(
        "*****@*****.**", {"donor", "*****@*****.**", "liver", "hosptal1"})
    mock_recipient.return_value = fakeRecipient(
        "*****@*****.**",
        {"recipient", "*****@*****.**", "liver", "hosptal2"})
    drview.request.method = 'POST'
    drview.request.form = mock_request_form({
        "username": "******",
        "type": "donor",
        "report": "report",
        "organ": ["liver", "heart"]
    })
    mock_vur.return_value = fakeViewUserReports("*****@*****.**", "donor",
                                                "report")
    mock_send_file.return_value = "sent successfully"
    mock_bytesio.return_value = str.encode("sent successfully")
    assert drview.donorHospitalRequestPage("requestid") == "sent successfully"
def test_donorHospitalRequestPage_upload_invalidcerti(mock_ord, mock_donor,
                                                      mock_recipient,
                                                      mock_flash, mock_g,
                                                      mock_ren, mock_request):
    mock_ord.return_value = fakeOpenRequestDetails(
        "requestid",
        [("*****@*****.**", "*****@*****.**", "organ", "pending")])
    mock_donor.return_value = fakeDonor(
        "*****@*****.**", {"donor", "*****@*****.**", "liver", "hosptal1"})
    mock_recipient.return_value = fakeRecipient(
        "*****@*****.**",
        {"recipient", "*****@*****.**", "liver", "hosptal2"})
    drview.request.method = 'POST'
    drview.request.form = mock_request_form({
        "username": "******",
        "type": "donor",
        "upload": "upload",
        "reports": "reports",
        "organ": ["liver", "heart"]
    })
    mock_flash.return_value = "please insert a valid certificates"
    mock_ren.return_value = "<h2>donor receiver request</h2>"
    assert drview.donorHospitalRequestPage(
        "requestid") == "<h2>donor receiver request</h2>"