Skip to content

Commit

Permalink
(fix): fix route names for the notes to be standard with other endpoi…
Browse files Browse the repository at this point in the history
…nts.
  • Loading branch information
ecourtial committed Jun 7, 2024
1 parent fca2686 commit df763f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,27 +344,27 @@ def get_transactions():

# Notes

@app.route('/api/v1/notes/<int:entity_id>', methods=['GET'])
@app.route('/api/v1/note/<int:entity_id>', methods=['GET'])
def get_note_by_id(entity_id):
"""Returns the note according to its id"""
controller = NoteController
return controller.get_by_id(MySQLFactory.get(), entity_id)

@app.route('/api/v1/notes', methods=['POST'])
@app.route('/api/v1/note', methods=['POST'])
@token_required
def create_note():
"""Create a note"""
controller = NoteController
return controller.create(MySQLFactory.get())

@app.route('/api/v1/notes/<int:entity_id>', methods=['PATCH'])
@app.route('/api/v1/note/<int:entity_id>', methods=['PATCH'])
@token_required
def update_note(entity_id):
"""Update the note according to its id"""
controller = NoteController
return controller.update(MySQLFactory.get(), entity_id)

@app.route('/api/v1/notes/<int:entity_id>', methods=['DELETE'])
@app.route('/api/v1/note/<int:entity_id>', methods=['DELETE'])
@token_required
def delete_note(entity_id):
"""Delete the note according to its id"""
Expand All @@ -373,6 +373,6 @@ def delete_note(entity_id):

@app.route('/api/v1/notes', methods=['GET'])
def get_notes():
"""Get the transactions"""
"""Get the notes"""
controller = NoteController
return controller.get_list(MySQLFactory.get())
18 changes: 9 additions & 9 deletions test/functional/test_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,48 @@

class TestNotes(AbstractTests):
def test_commons(self):
super().check_all_routes_error_bad_user_token('notes')
super().check_all_routes_error_missing_user_token('notes')
super().check_all_routes_error_bad_user_token('note')
super().check_all_routes_error_missing_user_token('note')

def test_get_note(self):
# Does not exist
resp = self.api_call('get', 'notes/666', {}, True)
resp = self.api_call('get', 'note/666', {}, True)

self.assertEqual(404, resp.status_code)
self.assertEqual({'message': "The resource of type 'note' with id #666 has not been found.", 'code': 1}, resp.json())

# Exist
resp = self.api_call('get', 'notes/1', {}, True)
resp = self.api_call('get', 'note/1', {}, True)

self.assertEqual(200, resp.status_code)
self.assertEqual({'id': 1, 'title': 'Note 1', 'content': 'Some comment 1.'}, resp.json())

def test_create_incomplete_payload(self):
resp = self.api_call('post', 'notes', {}, True)
resp = self.api_call('post', 'note', {}, True)

self.assertEqual(400, resp.status_code)
self.assertEqual({'message': 'The following field is missing: title.', 'code': 6}, resp.json())

def test_create_update_delete_success(self):
# Create
resp = self.api_call('post', 'notes', {'title': 'Genesis', 'content': 'Pues'}, True)
resp = self.api_call('post', 'note', {'title': 'Genesis', 'content': 'Pues'}, True)

self.assertEqual(200, resp.status_code)
self.assertEqual('Genesis', resp.json()["title"])
self.assertEqual('Pues', resp.json()["content"])
note_id = str(resp.json()["id"])

# Patch
resp = self.api_call('patch', 'notes/' + note_id, {'title': 'Playstation III'}, True)
resp = self.api_call('patch', 'note/' + note_id, {'title': 'Playstation III'}, True)

self.assertEqual(200, resp.status_code)
self.assertEqual('Playstation III', resp.json()["title"])

# Delete
resp = self.api_call('delete', 'notes/' + note_id, {}, True)
resp = self.api_call('delete', 'note/' + note_id, {}, True)
self.assertEqual(200, resp.status_code)

resp = self.api_call('delete', 'notes/' + note_id, {}, True)
resp = self.api_call('delete', 'note/' + note_id, {}, True)
self.assertEqual(404, resp.status_code)
self.assertEqual({'message': "The resource of type 'note' with id #4 has not been found.", 'code': 1}, resp.json())

Expand Down

0 comments on commit df763f0

Please sign in to comment.