Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_no_app(self):
with self.assertRaises(check50.Failure):
check50.flask.app("doesnt_exist.py")
def test_app(self):
src = \
"""from flask import Flask
app = Flask(__name__)
@app.route('/')
def root():
return ''"""
with open("hello.py", "w") as f:
f.write(src)
app = check50.flask.app("hello.py")
self.assertIsInstance(app, check50.flask.app)
def test_content(self):
src = \
"""from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'foobar'"""
with open("hello.py", "w") as f:
f.write(src)
app = check50.flask.app("hello.py")
app.get("/").content("foo")
with self.assertRaises(check50.Failure):
app.get("/").content("foo", name="body")
app.get("/").content("bar")
def test_status(self):
src = \
"""from flask import Flask
app = Flask(__name__)
@app.route('/')
def root():
return ''"""
with open("hello.py", "w") as f:
f.write(src)
app = check50.flask.app("hello.py")
app.get("/").status(200)
app.get("/foo").status(404)
app.post("/").status(405)
def test_raw_content(self):
src = \
"""from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'hello world'"""
with open("hello.py", "w") as f:
f.write(src)
app = check50.flask.app("hello.py")
app.get("/").raw_content("hello world")
with self.assertRaises(check50.Failure):
app.get("/").raw_content("foo")