mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-06 05:01:48 +02:00
Compare commits
2 commits
2d2a773f71
...
40fd353f95
Author | SHA1 | Date | |
---|---|---|---|
![]() |
40fd353f95 | ||
![]() |
a90999b4bb |
2 changed files with 85 additions and 1 deletions
|
@ -4,6 +4,7 @@ import getpass
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
|
import datetime
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from flask.cli import FlaskGroup
|
from flask.cli import FlaskGroup
|
||||||
|
@ -93,5 +94,31 @@ def delete_project(project_name):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
@click.argument("print_emails", default=False)
|
||||||
|
@click.argument("bills", default=0) # default values will get total projects
|
||||||
|
@click.argument("days", default=73000) # approximately 200 years
|
||||||
|
def get_project_count(print_emails, bills, days):
|
||||||
|
"""Count projets with at least x bills and at less than x days old"""
|
||||||
|
projects = [
|
||||||
|
pr
|
||||||
|
for pr in Project.query.all()
|
||||||
|
if pr.get_bills().count() > bills
|
||||||
|
and pr.get_bills()[0].date
|
||||||
|
> datetime.date.today() - datetime.timedelta(days=days)
|
||||||
|
]
|
||||||
|
click.secho("Number of projects: " + str(len(projects)))
|
||||||
|
|
||||||
|
if print_emails:
|
||||||
|
emails = set([pr.contact_email for pr in projects])
|
||||||
|
emails_str = ", ".join(emails)
|
||||||
|
if len(emails) > 1:
|
||||||
|
click.secho("Contact emails: " + emails_str)
|
||||||
|
elif len(emails) == 1:
|
||||||
|
click.secho("Contact email: " + emails_str)
|
||||||
|
else:
|
||||||
|
click.secho("No contact emails found")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cli()
|
cli()
|
||||||
|
|
|
@ -9,7 +9,12 @@ from werkzeug.security import check_password_hash
|
||||||
|
|
||||||
from ihatemoney import models
|
from ihatemoney import models
|
||||||
from ihatemoney.currency_convertor import CurrencyConverter
|
from ihatemoney.currency_convertor import CurrencyConverter
|
||||||
from ihatemoney.manage import delete_project, generate_config, password_hash
|
from ihatemoney.manage import (
|
||||||
|
delete_project,
|
||||||
|
generate_config,
|
||||||
|
get_project_count,
|
||||||
|
password_hash,
|
||||||
|
)
|
||||||
from ihatemoney.run import load_configuration
|
from ihatemoney.run import load_configuration
|
||||||
from ihatemoney.tests.common.ihatemoney_testcase import BaseTestCase, IhatemoneyTestCase
|
from ihatemoney.tests.common.ihatemoney_testcase import BaseTestCase, IhatemoneyTestCase
|
||||||
|
|
||||||
|
@ -229,6 +234,58 @@ class TestModels(IhatemoneyTestCase):
|
||||||
pay_each_expected = 10 / 3
|
pay_each_expected = 10 / 3
|
||||||
assert bill.pay_each() == pay_each_expected
|
assert bill.pay_each() == pay_each_expected
|
||||||
|
|
||||||
|
def test_demo_project_count(self):
|
||||||
|
"""Test command the get-project-count"""
|
||||||
|
self.post_project("raclette")
|
||||||
|
|
||||||
|
# add members
|
||||||
|
self.client.post("/raclette/members/add", data={"name": "zorglub", "weight": 2})
|
||||||
|
self.client.post("/raclette/members/add", data={"name": "fred"})
|
||||||
|
self.client.post("/raclette/members/add", data={"name": "tata"})
|
||||||
|
self.client.post("/raclette/members/add", data={"name": "pépé"})
|
||||||
|
|
||||||
|
# create bills
|
||||||
|
self.client.post(
|
||||||
|
"/raclette/add",
|
||||||
|
data={
|
||||||
|
"date": "2011-08-10",
|
||||||
|
"what": "fromage à raclette",
|
||||||
|
"payer": 1,
|
||||||
|
"payed_for": [1, 2, 3],
|
||||||
|
"amount": "10.0",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
self.client.post(
|
||||||
|
"/raclette/add",
|
||||||
|
data={
|
||||||
|
"date": "2011-08-10",
|
||||||
|
"what": "red wine",
|
||||||
|
"payer": 2,
|
||||||
|
"payed_for": [1],
|
||||||
|
"amount": "20",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(self.get_project("raclette").has_bills(), True)
|
||||||
|
|
||||||
|
runner = self.app.test_cli_runner()
|
||||||
|
result0 = runner.invoke(get_project_count)
|
||||||
|
self.assertEqual(result0.output.strip(), "Number of projects: 1")
|
||||||
|
result1 = runner.invoke(get_project_count, "False 1")
|
||||||
|
self.assertEqual(result1.output.strip(), "Number of projects: 1")
|
||||||
|
result2 = runner.invoke(get_project_count, "False 2")
|
||||||
|
self.assertEqual(result2.output.strip(), "Number of projects: 0")
|
||||||
|
result3 = runner.invoke(get_project_count, "False 0 0")
|
||||||
|
self.assertEqual(result3.output.strip(), "Number of projects: 0")
|
||||||
|
result4 = runner.invoke(get_project_count, "False 0 20000")
|
||||||
|
self.assertEqual(result4.output.strip(), "Number of projects: 1")
|
||||||
|
result4 = runner.invoke(get_project_count, "True")
|
||||||
|
self.assertEqual(
|
||||||
|
result4.output.strip(),
|
||||||
|
"Number of projects: 1\nContact email: raclette@notmyidea.org",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestEmailFailure(IhatemoneyTestCase):
|
class TestEmailFailure(IhatemoneyTestCase):
|
||||||
def test_creation_email_failure_smtp(self):
|
def test_creation_email_failure_smtp(self):
|
||||||
|
|
Loading…
Reference in a new issue