Skip to content

Commit

Permalink
Adding response in Allure report
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksey committed Mar 10, 2024
1 parent ce0e0d3 commit 580e0a5
Show file tree
Hide file tree
Showing 25 changed files with 205 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: dummyapi
on: workflow_dispatch

jobs:
api_tests:
api_tests_dummyapi:
runs-on: ubuntu-latest

steps:
Expand Down
6 changes: 6 additions & 0 deletions base/base_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import allure
import json
from allure_commons.types import AttachmentType


class BaseAPI:
Expand Down Expand Up @@ -27,3 +29,7 @@ def check_total_object(self, objectCount, total_object=1):
@allure.step('Check response is 404')
def check_response_is_403(self):
assert self.response.status_code == 403, f'Error status code {self.response.status_code}'

def attach_response(self):
response = json.dumps(self.response_json, indent=4)
allure.attach(body=response, name="API Response", attachment_type=AttachmentType.JSON)
22 changes: 11 additions & 11 deletions config/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@

class UserDataLink:
GET_LIST = f'{BASE_URL}/user'
GET_USER_BY_ID = f'{BASE_URL}/user/'
GET_USER_BY_ID = lambda self, user_id: f'{BASE_URL}/user/{user_id}'
CREATE_USER = f'{BASE_URL}/user/create'
UPDATE_USER = f'{BASE_URL}/user'
DELETE_USER = f'{BASE_URL}/user'
UPDATE_USER = lambda self, user_id: f'{BASE_URL}/user/{user_id}'
DELETE_USER = lambda self, user_id: f'{BASE_URL}/user/{user_id}'


class PostDataLink:
GET_LIST_POST = f'{BASE_URL}/post'
GET_LIST_BY_USER = f'{BASE_URL}/user'
GET_POST_BY_ID = f'{BASE_URL}/post'
GET_LIST_BY_TAG = f'{BASE_URL}/tag'
GET_LIST_BY_USER = lambda self, user_id: f'{BASE_URL}/user/{user_id}/post'
GET_POST_BY_ID = lambda self, post_id: f'{BASE_URL}/post/{post_id}'
GET_LIST_BY_TAG = lambda self, user_id: f'{BASE_URL}/tag/{user_id}/post'
CREATE_POST = f'{BASE_URL}/post/create'
UPDATE_POST = f'{BASE_URL}/post'
DELETE_POST = f'{BASE_URL}/post'
UPDATE_POST = lambda self, post_id: f'{BASE_URL}/post/{post_id}'
DELETE_POST = lambda self, post_id: f'{BASE_URL}/post/{post_id}'


class CommentDataLink:
GET_LIST_COMMENT = f'{BASE_URL}/comment'
GET_LIST_COMMENT_BY_POST = f'{BASE_URL}/post'
GET_LIST_COMMENT_BY_USER = f'{BASE_URL}/user'
GET_LIST_COMMENT_BY_POST = lambda self, post_id: f'{BASE_URL}/post/{post_id}/comment'
GET_LIST_COMMENT_BY_USER = lambda self, user_id: f'{BASE_URL}/user/{user_id}/comment'
CREATE_COMMENT = f'{BASE_URL}/comment/create'
DELETE_COMMENT = f'{BASE_URL}/comment'
DELETE_COMMENT = lambda self, comment_id: f'{BASE_URL}/comment/{comment_id}'


class TagsDataLink:
Expand Down
13 changes: 11 additions & 2 deletions endpoints/comment_controller/comment_get_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
class CommentList(BaseAPI):
SCHEMA = DataListComment

def __init__(self):
super().__init__()
self.url = CommentDataLink()

@allure.step('Request comment list')
def request_comment_list(self, headers):
self.response = requests.get(url=CommentDataLink.GET_LIST_COMMENT, headers=headers)
self.response_json = self.response.json()
self.response = requests.get(
url=self.url.GET_LIST_COMMENT,
headers=headers
)
self.response_json = self.response.json()
self.attach_response()

16 changes: 10 additions & 6 deletions endpoints/comment_controller/create_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@
from base.base_api import BaseAPI
from config.links import CommentDataLink
from schema.comment import Comment
from model.data_generator import CreateCommentDate
from model.payload import CreateCommentDate


class CreateComment(BaseAPI):
SCHEMA = Comment

def __init__(self):
self.payload_comment = CreateCommentDate.data_comment()
super().__init__()
self.payload = CreateCommentDate()
self.url = CommentDataLink()

def request_create_comment(self, headers, post, commentCount=1):
with allure.step(f'Create {commentCount} comment(s)'):
for i in range(commentCount):
body = self.payload_comment
body['owner'] = post.owner.id
body['post'] = post.id
self.response = requests.post(url=CommentDataLink.CREATE_COMMENT, headers=headers, data=body)
self.response = requests.post(
url=self.url.CREATE_COMMENT,
headers=headers,
json=self.payload.data_comment(post.owner.id, post.id)
)
self.response_json = self.response.json()
self.check_response_is_200()
self.check_validate()
self.attach_response()

@allure.step('Check user id in comment')
def check_id_user_in_comment(post, response):
Expand Down
11 changes: 9 additions & 2 deletions endpoints/comment_controller/delete_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@


class DeleteComment(BaseAPI):
def __init__(self):
super().__init__()
self.url = CommentDataLink()

@allure.step('Delete comment')
def request_delete_comment(self, headers, comment):
self.response = requests.delete(url=f'{CommentDataLink.DELETE_COMMENT}/{comment.id}', headers=headers)
self.response_json = self.response.json()
self.response = requests.delete(
url=self.url.DELETE_COMMENT(comment.id),
headers=headers
)
self.response_json = self.response.json()
self.attach_response()
11 changes: 9 additions & 2 deletions endpoints/comment_controller/list_comment_by_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@
class ListCommentByPost(BaseAPI):
SCHEMA = DataListComment

def __init__(self):
super().__init__()
self.url = CommentDataLink()

@allure.step('Request comment list by post')
def request_list_comment_by_post(self, headers, post_id):
self.response = requests.get(url=f'{CommentDataLink.GET_LIST_COMMENT_BY_POST}/{post_id}/comment',
headers=headers)
self.response = requests.get(
url=self.url.GET_LIST_COMMENT_BY_POST(post_id),
headers=headers
)
self.response_json = self.response.json()
self.attach_response()

@allure.step('Check post id in comment list')
def check_id_post_in_comment_list(self, response, comment):
Expand Down
10 changes: 9 additions & 1 deletion endpoints/comment_controller/list_comment_by_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@
class ListCommentByUser(BaseAPI):
SCHEMA = DataListComment

def __init__(self):
super().__init__()
self.url = CommentDataLink()

@allure.step('Request comment list by user')
def request_list_comment_by_user(self, headers, user_id):
self.response = requests.get(url=f'{CommentDataLink.GET_LIST_COMMENT_BY_USER}/{user_id}/comment', headers=headers)
self.response = requests.get(
url=self.url.GET_LIST_COMMENT_BY_USER(user_id),
headers=headers
)
self.response_json = self.response.json()
self.attach_response()

@allure.step('Check user id in comment list')
def check_id_user_in_comment_list(self, response, comment):
Expand Down
15 changes: 10 additions & 5 deletions endpoints/post_controller/create_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@
from base.base_api import BaseAPI
from config.links import PostDataLink
from schema.post import Post
from model.data_generator import RegisterPost
from model.payload import RegisterPost


class CreatePost(BaseAPI):
SCHEMA = Post

def __init__(self):
self.payload_post = RegisterPost.post_data()
super().__init__()
self.url = PostDataLink()
self.payload = RegisterPost()

def request_create_post(self, headers, owner, postCount=1):
with allure.step(f'Create {postCount} post(s)'):
for i in range(postCount):
body = self.payload_post
body['owner'] = owner.id
self.response = requests.post(url=PostDataLink.CREATE_POST, headers=headers, data=body)
self.response = requests.post(
url=self.url.CREATE_POST,
headers=headers,
json=self.payload.post_data(owner.id)
)
self.response_json = self.response.json()
self.check_response_is_200()
self.check_validate()
self.attach_response()



12 changes: 10 additions & 2 deletions endpoints/post_controller/delete_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@


class DeletePost(BaseAPI):
def __init__(self):
super().__init__()
self.url = PostDataLink()

@allure.step('Delete post')
def request_delete_post(self, headers, post):
self.response = requests.delete(url=f'{PostDataLink.DELETE_POST}/{post.id}', headers=headers)
self.response_json = self.response.json()
self.response = requests.delete(
url=self.url.DELETE_POST(post.id),
headers=headers
)
self.response_json = self.response.json()
self.attach_response()
11 changes: 10 additions & 1 deletion endpoints/post_controller/post_by_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@
from config.links import PostDataLink
from schema.post import Post


class PostByID(BaseAPI):
SCHEMA = Post

def __init__(self):
super().__init__()
self.url = PostDataLink()

@allure.step('Get post by id user')
def request_post_by_id(self, headers, post):
self.response = requests.get(url=f'{PostDataLink.GET_POST_BY_ID}/{post.id}', headers=headers)
self.response = requests.get(
url=self.url.GET_POST_BY_ID(post.id),
headers=headers
)
self.response_json = self.response.json()
self.attach_response()

@allure.step('Checking the requested post by id')
def check_post_by_id(self, post, response):
Expand Down
12 changes: 10 additions & 2 deletions endpoints/post_controller/post_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
class PostList(BaseAPI):
SCHEMA = DataListPost

def __init__(self):
super().__init__()
self.url = PostDataLink()

@allure.step('Request post list')
def request_post_list(self, headers):
self.response = requests.get(url=PostDataLink.GET_LIST_POST, headers=headers)
self.response_json = self.response.json()
self.response = requests.get(
url=self.url.GET_LIST_POST,
headers=headers
)
self.response_json = self.response.json()
self.attach_response()
12 changes: 10 additions & 2 deletions endpoints/post_controller/post_list_by_id_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
class PostListByIDUser(BaseAPI):
SCHEMA = DataListPost

def __init__(self):
super().__init__()
self.url = PostDataLink()

@allure.step('User post list by id')
def request_post_list_by_id(self, headers, user_id):
self.response = requests.get(url=f'{PostDataLink.GET_LIST_BY_USER}/{user_id}/post', headers=headers)
self.response_json = self.response.json()
self.response = requests.get(
url=self.url.GET_LIST_BY_USER(user_id),
headers=headers
)
self.response_json = self.response.json()
self.attach_response()
12 changes: 10 additions & 2 deletions endpoints/post_controller/post_list_by_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
class PostListByTag(BaseAPI):
SCHEMA = DataListPost

def __init__(self):
super().__init__()
self.url = PostDataLink()

@allure.step('User tag list request')
def request_post_list_by_tag(self, headers, user):
self.response = requests.get(url=f'{PostDataLink.GET_LIST_BY_TAG}/{user.owner.id}/post', headers=headers)
self.response_json = self.response.json()
self.response = requests.get(
url=self.url.GET_LIST_BY_TAG(user.owner.id),
headers=headers
)
self.response_json = self.response.json()
self.attach_response()
12 changes: 9 additions & 3 deletions endpoints/post_controller/update_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@
from base.base_api import BaseAPI
from config.links import PostDataLink
from schema.post import Post
from model.data_generator import UpdatePostDate
from model.payload import UpdatePostDate


class UpdatePost(BaseAPI):
SCHEMA = Post

def __init__(self):
self.payload_post = UpdatePostDate.update_post()
super().__init__()
self.url = PostDataLink()
self.payload = UpdatePostDate()

@allure.step('Update post')
def request_update_post(self, headers, post):
self.response = requests.put(url=f'{PostDataLink.UPDATE_POST}/{post.id}', headers=headers, data=self.payload_post)
self.response = requests.put(url=self.url.UPDATE_POST(post.id),
headers=headers,
data=self.payload.update_post()
)
self.response_json = self.response.json()
self.attach_response()

@allure.step('Checking for changes to the post data')
def check_update_post(self, payload, response):
Expand Down
12 changes: 9 additions & 3 deletions endpoints/tag_controller/list_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
from schema.tags import DataListTags



class TagsList(BaseAPI):
SCHEMA = DataListTags

def __init__(self):
super().__init__()
self.url = TagsDataLink()

@allure.step('Get tag list')
def request_tags_list(self, headers):
self.response = requests.get(url=TagsDataLink.GET_LIST_TAGS, headers=headers)
self.response_json = self.response.json()
self.response = requests.get(url=self.url.GET_LIST_TAGS,
headers=headers
)
self.response_json = self.response.json()
self.attach_response()
12 changes: 9 additions & 3 deletions endpoints/user_controller/create_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
from base.base_api import BaseAPI
from config.links import UserDataLink
from schema.user_full import User
from model.data_generator import RegisterUser
from model.payload import RegisterUser


class CreateUser(BaseAPI):
SCHEMA = User

def __init__(self):
self.payload_reg = RegisterUser.user_data()
super().__init__()
self.url = UserDataLink()
self.payload = RegisterUser()

@allure.step('Create user')
def request_create_user(self, headers):
self.response = requests.post(url=UserDataLink.CREATE_USER, headers=headers, data=self.payload_reg)
self.response = requests.post(url=self.url.CREATE_USER,
headers=headers,
json=self.payload.user_data()
)
self.response_json = self.response.json()
self.attach_response()
Loading

0 comments on commit 580e0a5

Please sign in to comment.