コード例 #1
0
        else:
            resp = self.session.post(url,
                                     json=jsonBody,
                                     headers=authheader,
                                     verify=self.verify_ssl)

        if resp.status_code < 200 or resp.status_code > 201:
            print(f"Failed POST {jsonBody} to {url}.")
            return resp.text, resp.status_code

        created = resp.json()

        print("OK, id:", created['id'])
        return resp.json(), resp.status_code


if __name__ == "__main__":
    demouser = DataGenerator.demo_user()
    # api = EffortlessApi("http://localhost:5000/api")
    api = EffortlessApi("https://staging.effortless.dk/api")

    auth = api.login(demouser["userName"], demouser["password"])
    if (api.is_logged_in()):
        print(
            f"Logged in as {auth['user']['firstName']} {auth['user']['lastName']}."
        )
    else:
        print(
            f"Could not log in. User {demouser['userName']} might not exist, or the API might be down."
        )