def test_registerUser_noguser(mock_request, mock_g, mock_url_for,
                              mock_redirect, mock_flash, mock_reg,
                              mock_hlo_li):
    mock_hlo_li.return_value = fakeHospitalList(
        "{\"hospitals\": \"[('hospital1', '*****@*****.**', 'address hospital1'), ('hospital2', '*****@*****.**', 'address hospital2')]"
    )
    drview.request.method = 'POST'
    mock_g.user = None
    drview.request.form = mock_request_form({
        "username": "******",
        "address": "halifax",
        "type": "donor",
        "organ": ["liver", "heart"]
    })
    mock_reg.return_value = fakeRegister(
        {
            "username": "******",
            "address": "halifax",
            "type": "donor",
            "organ": ["liver", "heart"]
        }, "donor", True)
    mock_flash.return_value = "Registered Successfully"
    mock_url_for.return_value = "http://url"
    mock_redirect.return_value = "<h2>login</h2"
    assert drview.registerUser("donor") == "<h2>login</h2"
def test_registerUser_get(mock_request, mock_g, mock_ren, mock_hlo_li):
    mock_hlo_li.return_value = fakeHospitalList(
        "{\"hospitals\": \"[('hospital1', '*****@*****.**', 'address hospital1'), ('hospital2', '*****@*****.**', 'address hospital2')]"
    )
    drview.request.method = 'GET'
    mock_ren.return_value = "<h2>sign up</h2"
    assert drview.registerUser("donor") == "<h2>sign up</h2"
def test_adminHomePage_certificate_failed(mock_fl_re, mock_g, mock_vc_certi,
                                          mock_fl_ren, mock_hlo_li):
    mock_hlo_li.return_value = fakeHospitalList(
        "{\"hospitals\": \"[('hospital1', '*****@*****.**', 'address hospital1'), ('hospital2', '*****@*****.**', 'address hospital2')]"
    )
    adminviews.request.method = 'POST'
    adminviews.request.form = mock_request_form({
        "hospital": "hospital1",
        "certificate": None
    })
    mock_vc_certi.return_value = fakeViewCertificate("*****@*****.**",
                                                     None)
    mock_fl_ren.return_value = "<h2>admin page</h2>"
    assert adminviews.adminHomepage() == "<h2>admin page</h2>"
def test_adminHomePage_validate_failed(mock_fl_re, mock_vho_validate, mock_g,
                                       mock_fl_ren, mock_hlo_li):
    mock_hlo_li.return_value = fakeHospitalList(
        "{\"hospitals\": \"[('hospital1', '*****@*****.**', 'address hospital1'), ('hospital2', '*****@*****.**', 'address hospital2')]"
    )
    adminviews.request.method = 'POST'
    adminviews.request.form = mock_request_form({
        "hospital": "hospital1",
        "validate": "false"
    })
    mock_vho_validate.return_value = fakeValidateHospital(
        {
            "hospital": "hospital1",
            "validate": "true"
        }, "g", "False")
    mock_fl_ren.return_value = "<h2>admin page</h2>"
    assert adminviews.adminHomepage() == "<h2>admin page</h2>"
def test_adminHomePage_delete_failed(mock_fl_re, mock_dho_delete, mock_g,
                                     mock_flash, mock_fl_ren, mock_hlo_li):
    mock_hlo_li.return_value = fakeHospitalList(
        "{\"hospitals\": \"[('hospital1', '*****@*****.**', 'address hospital1'), ('hospital2', '*****@*****.**', 'address hospital2')]"
    )
    adminviews.request.method = 'POST'
    adminviews.request.form = mock_request_form({
        "hospital": "hospital1",
        "delete": None
    })
    mock_flash.return_value = "deleted successfully"
    mock_dho_delete.return_value = fakeDeleteHospital(
        {
            "hospital": "hospital1",
            "delete": "hospital1"
        }, "False")
    mock_fl_ren.return_value = "<h2>admin page</h2>"
    assert adminviews.adminHomepage() == "<h2>admin page</h2>"
def test_adminHomePage_certificate(mock_fl_re, mock_vc_certi, mock_g,
                                   mock_bytesio, mock_send_file, mock_fl_ren,
                                   mock_hlo_li):
    mock_hlo_li.return_value = fakeHospitalList(
        "{\"hospitals\": \"[('hospital1', '*****@*****.**', 'address hospital1'), ('hospital2', '*****@*****.**', 'address hospital2')]"
    )
    adminviews.request.method = 'POST'
    adminviews.request.form = mock_request_form({
        "hospital":
        "hospital1",
        "certificate":
        "*****@*****.**"
    })
    mock_send_file.return_value = "sent successfully"
    mock_bytesio.return_value = str.encode("sent successfully")
    mock_vc_certi.return_value = fakeViewCertificate("*****@*****.**",
                                                     [["certificate"]])
    assert adminviews.adminHomepage() == "sent successfully"
def test_registerUser_invalid(mock_g, mock_request, mock_flash, mock_reg,
                              mock_hlo_li):
    mock_hlo_li.return_value = fakeHospitalList(
        "{\"hospitals\": \"[('hospital1', '*****@*****.**', 'address hospital1'), ('hospital2', '*****@*****.**', 'address hospital2')]"
    )
    drview.request.method = 'POST'
    drview.request.form = mock_request_form({
        "username": "******",
        "address": "halifax",
        "type": "donor",
        "organ": ["liver", "heart"]
    })
    mock_reg.return_value = fakeRegister(
        {
            "username": "******",
            "address": "halifax",
            "type": "donor",
            "organ": ["liver", "heart"]
        }, "donor", False)
    mock_flash.return_value = "Registration error"
    assert drview.registerUser("donor") == "<h2> Registration failed </h2>"