Skip to content

Commit

Permalink
Refactor notebook creation API endpoint and model in test_notebook_se…
Browse files Browse the repository at this point in the history
…rvice.py, fix test_create_and_get_notebook test case, and handle non-existent notebook in Notebook class
  • Loading branch information
xuwenyihust committed Jul 4, 2024
1 parent 22b140d commit a516ed6
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions server/tests/services/test_notebook_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def test_get_all_notebooks(self):

def test_create_and_get_notebook(self):
with self.app.app_context():
create_response = Notebook.create_notebook_with_init_cells(notebook_name='Notebook.ipynb', notebook_path='')
self.assertEqual(create_response[1], 200)
# Create with name but without path & get by path
create_response_0 = Notebook.create_notebook_with_init_cells(notebook_name='Notebook.ipynb', notebook_path='')
self.assertEqual(create_response_0[1], 200)

get_response_0 = Notebook.get_notebook_by_path(notebook_path='work/Notebook.ipynb')
notebook_0 = get_response_0[0]
Expand All @@ -50,11 +51,28 @@ def test_create_and_get_notebook(self):
self.assertEqual(notebook_0['path'], 'work/Notebook.ipynb')
self.assertEqual(len(notebook_0['content']['cells']), 2)

get_response_1 = Notebook.get_notebook_by_path(notebook_path='work/Notebook666.ipynb')
notebook_1 = get_response_1[0]
status_code_1 = get_response_1[1]
# Create without name / path & get by path
create_response_1 = Notebook.create_notebook_with_init_cells(notebook_name='', notebook_path='')
self.assertEqual(create_response_1[1], 200)
print(create_response_1)

self.assertEqual(status_code_1, 404)
# get_response_1 = Notebook.get_notebook_by_path(notebook_path='work/Notebook.ipynb')
# notebook_0 = get_response_0[0]
# status_code_0 = get_response_0[1]

print(notebook_1.json())
# self.assertEqual(status_code_0, 200)
# self.assertEqual(notebook_0['name'], 'Notebook.ipynb')
# self.assertEqual(notebook_0['path'], 'work/Notebook.ipynb')
# self.assertEqual(len(notebook_0['content']['cells']), 2)

# Create with name / path & get by path

# Get non-exist path
get_response_3 = Notebook.get_notebook_by_path(notebook_path='work/Notebook666.ipynb')
status_code_3 = get_response_3[1]

self.assertEqual(status_code_3, 404)

def test_delete_notebook(self):
pass

0 comments on commit a516ed6

Please sign in to comment.