Beispiel #1
0
    def test_login(self):
        # Create the user
        email = test_data["TEST_USER_EMAIL"]
        password = test_data.get("TEST_USER_PASSWORD")
        userOriginal = User(email=email, accountId=test_data["DEMO"], password=password)
        userOriginal.save()
        try:
            credentials = dict(email = test_data["TEST_USER_EMAIL"], password = test_data["TEST_USER_PASSWORD"])
            login_payload = dumps(credentials)
            response = requests.post(url=test_server + "/login", data=login_payload, headers={'content-type' : 'application/json'})
            assert(response.status_code == 200)
            response_object = response.json()

            user = response_object["response"]["user"]
            assert(user["id"] is not None)
            assert(user["authentication_token"] is not None)
        finally:
            #Cleanup
            userOriginal.delete()
Beispiel #2
0
    def test_login_and_use_resource(self):
        # Create User
        email = test_data["TEST_USER_EMAIL"]
        password = test_data.get("TEST_USER_PASSWORD")
        userOriginal = User(email=email, accountId=test_data["DEMO"], password=password)
        userOriginal.save()
        try:
            credentials = dict(email = test_data["TEST_USER_EMAIL"], password = password)
            login_payload = dumps(credentials)
            response = requests.post(url=test_server + "/login", data=login_payload, headers={'content-type' : 'application/json'})
            assert(response.status_code == 200)
            response_object = response.json()

            user = response_object["response"]["user"]

            basic_auth_credentials = HTTPBasicAuth(email, user["authentication_token"])
            response = requests.get(url=test_server + "/auth/api/resource", headers={'content-type' : 'application/json'}, auth=basic_auth_credentials)
            assert(response.status_code == 200)
            assert(email in str(response.json()["data"]))
        finally:
            #Cleanup
            userOriginal.delete()