mirror of
https://github.com/YunoHost-Apps/ihatemoney_ynh.git
synced 2024-09-03 19:26:15 +02:00
Fix a weird behavior with tests and databases.
Now all the database during the tests is in memory, created for each test and cleared at the end of the test.
This commit is contained in:
parent
63a6491001
commit
35ea308a26
5 changed files with 71 additions and 30 deletions
|
@ -54,6 +54,25 @@ div.topbar ul.secondary-nav { padding-right: 75px; }
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#header .additional-content{
|
||||||
|
font-family: 'Comfortaa', arial, serif;
|
||||||
|
float: right;
|
||||||
|
position: relative;
|
||||||
|
top: -150px;
|
||||||
|
margin-right: 200px;
|
||||||
|
margin-bottom: -100px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.home form button{
|
||||||
|
float: right;
|
||||||
|
margin-right: 100px;
|
||||||
|
}
|
||||||
|
.home .create h3{
|
||||||
|
text-align: right;
|
||||||
|
margin-right: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
.footer{
|
.footer{
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 0px;
|
bottom: 0px;
|
||||||
|
|
|
@ -26,17 +26,19 @@
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro authenticate(form) %}
|
{% macro authenticate(form, home=False) %}
|
||||||
|
|
||||||
{% include "display_errors.html" %}
|
{% include "display_errors.html" %}
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
{{ input(form.id) }}
|
{{ input(form.id) }}
|
||||||
{{ input(form.password) }}
|
{{ input(form.password) }}
|
||||||
|
{% if not home %}
|
||||||
{{ submit(form.submit) }}
|
{{ submit(form.submit) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro create_project(form) %}
|
{% macro create_project(form, home=False) %}
|
||||||
|
|
||||||
{% include "display_errors.html" %}
|
{% include "display_errors.html" %}
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
|
@ -44,7 +46,9 @@
|
||||||
{{ input(form.id) }}
|
{{ input(form.id) }}
|
||||||
{{ input(form.password) }}
|
{{ input(form.password) }}
|
||||||
{{ input(form.contact_email) }}
|
{{ input(form.contact_email) }}
|
||||||
|
{% if not home %}
|
||||||
{{ submit(form.submit) }}
|
{{ submit(form.submit) }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
@ -70,10 +74,3 @@
|
||||||
<button class="btn">Add a new user</button>
|
<button class="btn">Add a new user</button>
|
||||||
|
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro authenticate(form) %}
|
|
||||||
{{ form.hidden_tag() }}
|
|
||||||
{{ input(form.id) }}
|
|
||||||
{{ input(form.password) }}
|
|
||||||
{{ submit(form.submit) }}
|
|
||||||
{% endmacro %}
|
|
||||||
|
|
|
@ -6,29 +6,33 @@
|
||||||
{% block header %}
|
{% block header %}
|
||||||
<div id="header">
|
<div id="header">
|
||||||
<div class="slide">
|
<div class="slide">
|
||||||
<h1><span>Manage your shared <br>expenses easily</span></h1>
|
<h1><span>Manage your shared <br>expenses, easily</span></h1>
|
||||||
<a href="{{ url_for("demo") }}" class="about_link">Try out the demo</a>
|
<a href="{{ url_for("demo") }}" class="about_link">Try out the demo</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="additional-content">
|
||||||
|
<p>You're sharing a house?<br /> Going on holidays with friends?<br /> Simply sharing money with others? <br /><strong>We can help!</strong></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block container %}
|
{% block container %}
|
||||||
<div class="container-fluid" style="margin-top: 20px">
|
<div class="container-fluid" style="margin-top: 20px">
|
||||||
<div class="content">
|
<div class="content home">
|
||||||
|
|
||||||
<h2>Welcome on your budget manager</h2>
|
<div class="row">
|
||||||
<p>You're sharing a house? Going on holidays with friends? Simply sharing money with others? We can help!</p>
|
|
||||||
<div class="row">
|
|
||||||
<div class="span8 columns">
|
<div class="span8 columns">
|
||||||
<form action="{{ url_for('authenticate') }}" method="post">
|
<form action="{{ url_for('authenticate') }}" method="post">
|
||||||
<h3>Log to an existing project...</h3>
|
<h3>Log to an existing project...</h3>
|
||||||
{{ forms.authenticate(auth_form) }}
|
{{ forms.authenticate(auth_form, home=True) }}
|
||||||
|
<button class="btn">log in</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="span8 columns">
|
<div class="span8 columns">
|
||||||
<form action="{{ url_for('create_project') }}" method="post">
|
<form class="create" action="{{ url_for('create_project') }}" method="post">
|
||||||
<h3>...or create a new one</h3>
|
<h3>...or create a new one</h3>
|
||||||
{{ forms.create_project(project_form) }}</div>
|
{{ forms.create_project(project_form, home=True) }}
|
||||||
|
<button class="btn">let's get started</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -13,8 +13,7 @@ class TestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
web.app.config['TESTING'] = True
|
web.app.config['TESTING'] = True
|
||||||
|
|
||||||
self.fd, self.fp = tempfile.mkstemp()
|
web.app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///memory"
|
||||||
web.app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///%s" % self.fp
|
|
||||||
web.app.config['CSRF_ENABLED'] = False # simplify the tests
|
web.app.config['CSRF_ENABLED'] = False # simplify the tests
|
||||||
self.app = web.app.test_client()
|
self.app = web.app.test_client()
|
||||||
|
|
||||||
|
@ -26,8 +25,8 @@ class TestCase(unittest.TestCase):
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
# clean after testing
|
# clean after testing
|
||||||
os.close(self.fd)
|
models.db.session.remove()
|
||||||
os.unlink(self.fp)
|
models.db.drop_all()
|
||||||
|
|
||||||
def login(self, project, password=None, test_client=None):
|
def login(self, project, password=None, test_client=None):
|
||||||
password = password or project
|
password = password or project
|
||||||
|
@ -177,6 +176,24 @@ class BudgetTestCase(TestCase):
|
||||||
result = self.app.get("/raclette/add")
|
result = self.app.get("/raclette/add")
|
||||||
self.assertNotIn("fred", result.data)
|
self.assertNotIn("fred", result.data)
|
||||||
|
|
||||||
|
def test_demo(self):
|
||||||
|
# Test that it is possible to connect automatically by going onto /demo
|
||||||
|
with web.app.test_client() as c:
|
||||||
|
models.db.session.add(models.Project(id="demo", name=u"demonstration",
|
||||||
|
password="demo", contact_email="demo@notmyidea.org"))
|
||||||
|
models.db.session.commit()
|
||||||
|
c.get("/demo")
|
||||||
|
|
||||||
|
# session is updated
|
||||||
|
self.assertEqual(session['demo'], 'demo')
|
||||||
|
|
||||||
|
def test_demo(self):
|
||||||
|
# test that a demo project is created if none is defined
|
||||||
|
with web.app.test_client() as c:
|
||||||
|
self.assertEqual([], models.Project.query.all())
|
||||||
|
c.get("/demo")
|
||||||
|
self.assertTrue(models.Project.query.get("demo") is not None)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -14,15 +14,6 @@ app = Flask(__name__)
|
||||||
app.config.from_object("default_settings")
|
app.config.from_object("default_settings")
|
||||||
mail = Mail()
|
mail = Mail()
|
||||||
|
|
||||||
# db
|
|
||||||
db.init_app(app)
|
|
||||||
db.app = app
|
|
||||||
db.create_all()
|
|
||||||
|
|
||||||
# mail
|
|
||||||
mail.init_app(app)
|
|
||||||
|
|
||||||
|
|
||||||
@app.url_defaults
|
@app.url_defaults
|
||||||
def add_project_id(endpoint, values):
|
def add_project_id(endpoint, values):
|
||||||
if 'project_id' in values or not hasattr(g, 'project'):
|
if 'project_id' in values or not hasattr(g, 'project'):
|
||||||
|
@ -126,6 +117,11 @@ def exit():
|
||||||
@app.route("/demo")
|
@app.route("/demo")
|
||||||
def demo():
|
def demo():
|
||||||
project = Project.query.get("demo")
|
project = Project.query.get("demo")
|
||||||
|
if not project:
|
||||||
|
project = Project(id="demo", name=u"demonstration", password="demo",
|
||||||
|
contact_email="demo@notmyidea.org")
|
||||||
|
db.session.add(project)
|
||||||
|
db.session.commit()
|
||||||
session[project.id] = project.password
|
session[project.id] = project.password
|
||||||
return redirect(url_for("list_bills", project_id=project.id))
|
return redirect(url_for("list_bills", project_id=project.id))
|
||||||
|
|
||||||
|
@ -247,6 +243,14 @@ def reset_bills():
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
# db
|
||||||
|
db.init_app(app)
|
||||||
|
db.app = app
|
||||||
|
db.create_all()
|
||||||
|
|
||||||
|
# mail
|
||||||
|
mail.init_app(app)
|
||||||
|
|
||||||
app.run(host="0.0.0.0", debug=True)
|
app.run(host="0.0.0.0", debug=True)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue