-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_storage.py
50 lines (38 loc) · 1.29 KB
/
test_storage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from models.engine.db_storage import DbStorage
from models.author import Author
from models import app, db
from flask import Flask
def create_app():
app = Flask(__name__)
# You may need to configure your app here (e.g., database URI)
return app
def test_all():
app = create_app()
app.app_context().push() # Push an application context
storage = DbStorage()
# Assuming you have some test data in your database
authors = storage.all(Author)
assert len(authors) > 0
app.app_context().pop() # Pop the application context after the test
def test_new_and_get():
app = create_app()
app.app_context().push()
storage = DbStorage()
author = Author(name="Test Author")
storage.new(author)
storage.save()
retrieved_author = storage.get(Author, author.id)
assert retrieved_author is not None
assert retrieved_author.name == "Test Author"
app.app_context().pop()
def test_delete():
app = create_app()
app.app_context().push()
storage = DbStorage()
author = Author(name="Author to delete")
storage.new(author)
storage.save()
storage.delete(author)
deleted_author = storage.get(Author, author.id)
assert deleted_author is None
app.app_context().pop()