AttributeError:“ dict”对象没有属性“ url”

I'm writing some API tests in pytest which take in a user object which is generated from a utility class. Then it calls the requests library to make the required API calls.

Below is my code that tests the /user operations.

import requests

class users:
    def __init__(self, user):
        self.token = user["Token"]
        self.url = 'http://127.0.0.1:5000/api/Users/'
        self.headers = {'token': self.token}

    def get_all_users(self):
        return requests.get(self.url, headers=self.headers).status_code

    def delete_user(self):
        return requests.delete(self.url, headers=self.headers).text

    def update_user(self):
        return requests.post(self.url, headers=self.headers).text

但是,当我运行它时。我收到一条错误消息:

AttributeError: 'dict' object has no attribute 'url'

Am I unable to use self.url? I wanted to not have to redeclare it in each defination as the endpoint is the same for each test.

评论