identity icon indicating copy to clipboard operation
identity copied to clipboard

Testing Auth with PyTest

Open 1jamesthompson1 opened this issue 7 months ago • 3 comments

Firstly thanks for your project, it is making it much easier to setup a login then doing it through MSAL.

I am new to working with AZURE and trying to do basic login etc. I am trying to update my tests. How can I simulate a login to then allow the testing of protected api?

Curerntly they looks like:

def test_form_submit_filtered():
    with app.app.test_client() as c:
        rv = c.post(
            "/search",
            data={
                "searchQuery": "",
                "includeModeRail": "on",
                "includeModeMarine": "on",
                "yearSlider-min": "2010",
                "yearSlider-max": "2024",
                "relevanceCutoff": "0.7",
                "includeSafetyIssues": "on",
                "includeRecommendations": "on",
                "includeReportSection": "on",
            },
            follow_redirects=True,
        )

        assert rv.status == "200 OK"

        df = pd.read_html(StringIO(json.loads(rv.data)["html_table"]))[0]

        assert df["year"].isin(range(2010, 2025)).all()
        assert df["mode"].isin(["Rail", "Marine"]).all()

1jamesthompson1 avatar Jul 03 '24 22:07 1jamesthompson1