The Vedro framework categorizes steps into three types:
- “given” - arrange steps, preparing data,
- “when” - the main act,
- “then”, “and” and “but” - asserts
In order to ease scenario reading all names of steps should start with their type.
class Scenario(vedro.Scenario):
subject = "login as registered user"
def registered_user(self):
self.user = registered_user()
def logs_in(self):
self.response = httpx.post(f"{API_URL}/auth/login", json=self.user)
def success_status_code(self):
assert self.response.status_code == 200
def created_token_in_response(self):
assert self.response.json() == AuthTokenSchema % {
"username": self.user["username"]
}
class Scenario(vedro.Scenario):
subject = "login as registered user"
def given_registered_user(self):
self.user = registered_user()
def when_user_logs_in(self):
self.response = httpx.post(f"{API_URL}/auth/login", json=self.user)
def then_it_should_return_success_response(self):
assert self.response.status_code == 200
def and_it_should_return_created_token(self):
assert self.response.json() == AuthTokenSchema % {
"username": self.user["username"]
}