|
3 | 3 | import socket
|
4 | 4 | from unittest.mock import MagicMock, patch
|
5 | 5 |
|
6 |
| -import pytest |
7 | 6 | from sqlalchemy import orm
|
8 | 7 | from werkzeug.security import check_password_hash
|
9 | 8 |
|
10 | 9 | from ihatemoney import models
|
11 | 10 | from ihatemoney.currency_convertor import CurrencyConverter
|
12 |
| -from ihatemoney.manage import delete_project, generate_config, password_hash |
| 11 | +from ihatemoney.manage import ( |
| 12 | + delete_project, |
| 13 | + generate_config, |
| 14 | + get_project_count, |
| 15 | + password_hash, |
| 16 | +) |
13 | 17 | from ihatemoney.run import load_configuration
|
14 | 18 | from ihatemoney.tests.common.ihatemoney_testcase import BaseTestCase, IhatemoneyTestCase
|
15 | 19 |
|
@@ -229,6 +233,65 @@ def test_bill_pay_each(self):
|
229 | 233 | pay_each_expected = 10 / 3
|
230 | 234 | assert bill.pay_each() == pay_each_expected
|
231 | 235 |
|
| 236 | + def test_demo_project_count(self): |
| 237 | + """Test command the get-project-count""" |
| 238 | + self.post_project("raclette") |
| 239 | + |
| 240 | + # add members |
| 241 | + self.client.post("/raclette/members/add", data={"name": "zorglub", "weight": 2}) |
| 242 | + self.client.post("/raclette/members/add", data={"name": "fred"}) |
| 243 | + self.client.post("/raclette/members/add", data={"name": "tata"}) |
| 244 | + self.client.post("/raclette/members/add", data={"name": "pépé"}) |
| 245 | + |
| 246 | + # create bills |
| 247 | + self.client.post( |
| 248 | + "/raclette/add", |
| 249 | + data={ |
| 250 | + "date": "2011-08-10", |
| 251 | + "what": "fromage à raclette", |
| 252 | + "payer": 1, |
| 253 | + "payed_for": [1, 2, 3], |
| 254 | + "amount": "10.0", |
| 255 | + }, |
| 256 | + ) |
| 257 | + |
| 258 | + self.client.post( |
| 259 | + "/raclette/add", |
| 260 | + data={ |
| 261 | + "date": "2011-08-10", |
| 262 | + "what": "red wine", |
| 263 | + "payer": 2, |
| 264 | + "payed_for": [1], |
| 265 | + "amount": "20", |
| 266 | + }, |
| 267 | + ) |
| 268 | + |
| 269 | + assert self.get_project("raclette").has_bills() |
| 270 | + |
| 271 | + # Now check the different parameters |
| 272 | + runner = self.app.test_cli_runner() |
| 273 | + result0 = runner.invoke(get_project_count) |
| 274 | + assert result0.output.strip() == "Number of projects: 1" |
| 275 | + |
| 276 | + # With more than 1 bill, without printing emails |
| 277 | + result1 = runner.invoke(get_project_count, "False 1") |
| 278 | + assert result1.output.strip() == "Number of projects: 1" |
| 279 | + |
| 280 | + # With more than 2 bill, without printing emails |
| 281 | + result2 = runner.invoke(get_project_count, "False 2") |
| 282 | + assert result2.output.strip() == "Number of projects: 0" |
| 283 | + |
| 284 | + # With more than 0 days old |
| 285 | + result3 = runner.invoke(get_project_count, "False 0 0") |
| 286 | + assert result3.output.strip() == "Number of projects: 0" |
| 287 | + |
| 288 | + result4 = runner.invoke(get_project_count, "False 0 20000") |
| 289 | + assert result4.output.strip() == "Number of projects: 1" |
| 290 | + |
| 291 | + # Print emails |
| 292 | + result5 = runner.invoke(get_project_count, "True") |
| 293 | + assert "raclette@notmyidea.org" in result5.output |
| 294 | + |
232 | 295 |
|
233 | 296 | class TestEmailFailure(IhatemoneyTestCase):
|
234 | 297 | def test_creation_email_failure_smtp(self):
|
@@ -401,9 +464,7 @@ def test_exchange_currency(self):
|
401 | 464 |
|
402 | 465 | def test_failing_remote(self):
|
403 | 466 | rates = {}
|
404 |
| - with patch("requests.Response.json", new=lambda _: {}), pytest.warns( |
405 |
| - UserWarning |
406 |
| - ): |
| 467 | + with patch("requests.Response.json", new=lambda _: {}): |
407 | 468 | # we need a non-patched converter, but it seems that MagickMock
|
408 | 469 | # is mocking EVERY instance of the class method. Too bad.
|
409 | 470 | rates = CurrencyConverter.get_rates(self.converter)
|
|
0 commit comments