Skip to content

Commit

Permalink
chore(posts_controller.py): remove unused methods and add new method …
Browse files Browse the repository at this point in the history
…to improve code organization and readability

chore(user_controller.py): remove unused file to improve code organization and maintainability
chore(routes.py): comment out unused routes to improve code organization and maintainability
test(messages_endpoint_test copy.py): add tests to ensure proper registration of messages endpoints
test(routes_test.py): add tests to ensure proper registration of routes and methods count
  • Loading branch information
marcuxyz committed Nov 12, 2023
1 parent 1cfd3bc commit d337561
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 41 deletions.
8 changes: 7 additions & 1 deletion tests/app/controllers/posts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ class PostsController:
def index(self):
return {}, 200

def show(self, id):
return {}, 200

def new(self):
return {}, 200

def create(self):
return {}, 201

def show(self, id):
def edit(self, id):
return {}, 200

def update(self, id):
Expand Down
21 changes: 0 additions & 21 deletions tests/app/controllers/user_controller.py

This file was deleted.

11 changes: 6 additions & 5 deletions tests/app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
api.get("/health", "health#index")

posts = api.namespace("/posts")
posts.get("", "posts#index")
posts.post("", "posts#create")
posts.get("/<id>", "posts#show")
posts.put("/<id>", "posts#update")
posts.get("/<id>", "posts#delete")
posts.all("posts", only="index")
# posts.get("", "posts#index")
# posts.post("", "posts#create")
# posts.get("/<id>", "posts#show")
# posts.put("/<id>", "posts#update")
# posts.get("/<id>", "posts#delete")
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,3 @@ def test_when_messages_endpoint_have_been_registered(client):
assert f"messages.edit" in endpoints
assert f"messages.update" in endpoints
assert f"messages.delete" in endpoints


def test_when_there_are_many_registered_routes(client):
methods = [
route
for routes in client.application.url_map.iter_rules()
for route in routes.methods
]

assert methods.count("GET") == 9
assert methods.count("POST") == 2
assert methods.count("PUT") == 2
assert methods.count("PATCH") == 2
assert methods.count("DELETE") == 1
14 changes: 14 additions & 0 deletions tests/routes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,17 @@ def test_when_messages_endpoint_have_been_registered(client):
assert f"messages.edit" in endpoints
assert f"messages.update" in endpoints
assert f"messages.delete" in endpoints


def test_when_there_are_many_registered_routes(client):
methods = [
route
for routes in client.application.url_map.iter_rules()
for route in routes.methods
]

assert methods.count("GET") == 7
assert methods.count("POST") == 1
assert methods.count("PUT") == 1
assert methods.count("PATCH") == 1
assert methods.count("DELETE") == 1

0 comments on commit d337561

Please sign in to comment.