Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove obsolete python code (<3.6). #571

Merged
merged 3 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
sudo: false
language: python
python:
- "3.5"
- "3.6"
- "3.7"
- "3.8"
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ encouraged to do so.
Requirements
============

* **Python**: 3.5, 3.6, 3.7.
* **Python**: 3.6, 3.7, 3.8.
* **Backends**: MySQL, PostgreSQL, SQLite, Memory.

Contributing
Expand Down
4 changes: 0 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# coding: utf8
import os
import sys

templates_path = ["_templates"]
source_suffix = ".rst"
master_doc = "index"
Expand Down
1 change: 0 additions & 1 deletion ihatemoney/api/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf8
from functools import wraps

from flask import current_app, request
Expand Down
1 change: 0 additions & 1 deletion ihatemoney/api/v1/resources.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf8
from flask import Blueprint
from flask_cors import CORS
from flask_restful import Api
Expand Down
2 changes: 1 addition & 1 deletion ihatemoney/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def gen_secret_key():

def run(self, config_file):
env = create_jinja_env("conf-templates", strict_rendering=True)
template = env.get_template("%s.j2" % config_file)
template = env.get_template(f"{config_file}.j2")

bin_path = os.path.dirname(sys.executable)
pkg_path = os.path.abspath(os.path.dirname(__file__))
Expand Down
13 changes: 6 additions & 7 deletions ihatemoney/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def __str__(self):
return self.name

def __repr__(self):
return "<Project %s>" % self.name
return f"<Project {self.name}>"


class Person(db.Model):
Expand Down Expand Up @@ -381,7 +381,7 @@ def __str__(self):
return self.name

def __repr__(self):
return "<Person %s for project %s>" % (self.name, self.project.name)
return f"<Person {self.name} for project {self.project.name}>"


# We need to manually define a join table for m2m relations
Expand Down Expand Up @@ -460,13 +460,12 @@ def pay_each(self):
return 0

def __str__(self):
return "%s for %s" % (self.amount, self.what)
return f"{self.amount} for {self.what}"

def __repr__(self):
return "<Bill of %s from %s for %s>" % (
self.amount,
self.payer,
", ".join([o.name for o in self.owers]),
return (
f"<Bill of {self.amount} from {self.payer} for "
f"{', '.join([o.name for o in self.owers])}>"
)


Expand Down
85 changes: 38 additions & 47 deletions ihatemoney/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf8
import base64
from collections import defaultdict
import datetime
Expand Down Expand Up @@ -59,7 +58,7 @@ def post_project(self, name):
"name": name,
"id": name,
"password": name,
"contact_email": "%s@notmyidea.org" % name,
"contact_email": f"{name}@notmyidea.org",
},
)

Expand All @@ -68,7 +67,7 @@ def create_project(self, name):
id=name,
name=str(name),
password=generate_password_hash(name),
contact_email="%s@notmyidea.org" % name,
contact_email=f"{name}@notmyidea.org",
)
models.db.session.add(project)
models.db.session.commit()
Expand All @@ -83,7 +82,7 @@ def assertStatus(self, expected, resp, url=""):
return self.assertEqual(
expected,
resp.status_code,
"%s expected %s, got %s" % (url, expected, resp.status_code),
f"{url} expected {expected}, got {resp.status_code}",
)


Expand Down Expand Up @@ -410,7 +409,7 @@ def test_membership(self):
)

# remove fred
self.client.post("/raclette/members/%s/delete" % fred_id)
self.client.post(f"/raclette/members/{fred_id}/delete")

# he is still in the database, but is deactivated
self.assertEqual(len(models.Project.query.get("raclette").members), 2)
Expand All @@ -420,7 +419,7 @@ def test_membership(self):
# a bill or displaying the balance
result = self.client.get("/raclette/")
self.assertNotIn(
("/raclette/members/%s/delete" % fred_id), result.data.decode("utf-8")
(f"/raclette/members/{fred_id}/delete"), result.data.decode("utf-8")
)

result = self.client.get("/raclette/add")
Expand Down Expand Up @@ -619,7 +618,7 @@ def test_manage_bills(self):

# edit the bill
self.client.post(
"/raclette/edit/%s" % bill.id,
f"/raclette/edit/{bill.id}",
data={
"date": "2011-08-10",
"what": "fromage à raclette",
Expand All @@ -633,7 +632,7 @@ def test_manage_bills(self):
self.assertEqual(bill.amount, 10, "bill edition")

# delete the bill
self.client.get("/raclette/delete/%s" % bill.id)
self.client.get(f"/raclette/delete/{bill.id}")
self.assertEqual(0, len(models.Bill.query.all()), "bill deletion")

# test balance
Expand Down Expand Up @@ -1079,7 +1078,7 @@ def test_settle_zero(self):
self.assertNotEqual(
0.0,
rounded_amount,
msg="%f is equal to zero after rounding" % t["amount"],
msg=f"{t['amount']} is equal to zero after rounding",
)

def test_export(self):
Expand Down Expand Up @@ -1417,7 +1416,7 @@ class APITestCase(IhatemoneyTestCase):
def api_create(self, name, id=None, password=None, contact=None):
id = id or name
password = password or name
contact = contact or "%s@notmyidea.org" % name
contact = contact or f"{name}@notmyidea.org"

return self.client.post(
"/api/projects",
Expand All @@ -1431,19 +1430,19 @@ def api_create(self, name, id=None, password=None, contact=None):

def api_add_member(self, project, name, weight=1):
self.client.post(
"/api/projects/%s/members" % project,
f"/api/projects/{project}/members",
data={"name": name, "weight": weight},
headers=self.get_auth(project),
)

def get_auth(self, username, password=None):
password = password or username
base64string = (
base64.encodebytes(("%s:%s" % (username, password)).encode("utf-8"))
base64.encodebytes(f"{username}:{password}".encode("utf-8"))
.decode("utf-8")
.replace("\n", "")
)
return {"Authorization": "Basic %s" % base64string}
return {"Authorization": f"Basic {base64string}"}

def test_cors_requests(self):
# Create a project and test that CORS headers are present if requested.
Expand Down Expand Up @@ -1599,7 +1598,7 @@ def test_token_creation(self):
# Access with token
resp = self.client.get(
"/api/projects/raclette/token",
headers={"Authorization": "Basic %s" % decoded_resp["token"]},
headers={"Authorization": f"Basic {decoded_resp['token']}"},
)

self.assertEqual(200, resp.status_code)
Expand Down Expand Up @@ -2124,10 +2123,10 @@ def test_log_created_from_api_call(self):
resp = self.client.get("/raclette/history", follow_redirects=True)
self.assertEqual(resp.status_code, 200)
self.assertIn(
"Person %s added" % em_surround("alexis"), resp.data.decode("utf-8")
f"Person {em_surround('alexis')} added", resp.data.decode("utf-8")
)
self.assertIn(
"Project %s added" % em_surround("raclette"), resp.data.decode("utf-8"),
f"Project {em_surround('raclette')} added", resp.data.decode("utf-8"),
)
self.assertEqual(resp.data.decode("utf-8").count("<td> -- </td>"), 2)
self.assertNotIn("127.0.0.1", resp.data.decode("utf-8"))
Expand Down Expand Up @@ -2263,7 +2262,7 @@ def test_simple_create_logentry_no_ip(self):
resp = self.client.get("/demo/history")
self.assertEqual(resp.status_code, 200)
self.assertIn(
"Project %s added" % em_surround("demo"), resp.data.decode("utf-8"),
f"Project {em_surround('demo')} added", resp.data.decode("utf-8"),
)
self.assertEqual(resp.data.decode("utf-8").count("<td> -- </td>"), 1)
self.assertNotIn("127.0.0.1", resp.data.decode("utf-8"))
Expand Down Expand Up @@ -2319,7 +2318,7 @@ def assert_empty_history_logging_disabled(self):
self.assertNotIn("127.0.0.1", resp.data.decode("utf-8"))
self.assertNotIn("<td> -- </td>", resp.data.decode("utf-8"))
self.assertNotIn(
"Project %s added" % em_surround("demo"), resp.data.decode("utf-8")
f"Project {em_surround('demo')} added", resp.data.decode("utf-8")
)

def test_project_edit(self):
Expand All @@ -2335,18 +2334,16 @@ def test_project_edit(self):

resp = self.client.get("/demo/history")
self.assertEqual(resp.status_code, 200)
self.assertIn(f"Project {em_surround('demo')} added", resp.data.decode("utf-8"))
self.assertIn(
"Project %s added" % em_surround("demo"), resp.data.decode("utf-8")
)
self.assertIn(
"Project contact email changed to %s" % em_surround("demo2@notmyidea.org"),
f"Project contact email changed to {em_surround('demo2@notmyidea.org')}",
resp.data.decode("utf-8"),
)
self.assertIn(
"Project private code changed", resp.data.decode("utf-8"),
)
self.assertIn(
"Project renamed to %s" % em_surround("demo2"), resp.data.decode("utf-8"),
f"Project renamed to {em_surround('demo2')}", resp.data.decode("utf-8"),
)
self.assertLess(
resp.data.decode("utf-8").index("Project renamed "),
Expand Down Expand Up @@ -2462,7 +2459,7 @@ def do_misc_database_operations(self, logging_mode):

# edit the bill
resp = self.client.post(
"/demo/edit/%i" % bill_id,
f"/demo/edit/{bill_id}",
data={
"date": "2011-08-10",
"what": "fromage à raclette",
Expand All @@ -2474,12 +2471,12 @@ def do_misc_database_operations(self, logging_mode):
)
self.assertEqual(resp.status_code, 200)
# delete the bill
resp = self.client.get("/demo/delete/%i" % bill_id, follow_redirects=True)
resp = self.client.get(f"/demo/delete/{bill_id}", follow_redirects=True)
self.assertEqual(resp.status_code, 200)

# delete user using POST method
resp = self.client.post(
"/demo/members/%i/delete" % user_id, follow_redirects=True
f"/demo/members/{user_id}/delete", follow_redirects=True
)
self.assertEqual(resp.status_code, 200)

Expand Down Expand Up @@ -2581,7 +2578,7 @@ def test_logs_for_common_actions(self):
resp = self.client.get("/demo/history")
self.assertEqual(resp.status_code, 200)
self.assertIn(
"Person %s added" % em_surround("alexis"), resp.data.decode("utf-8")
f"Person {em_surround('alexis')} added", resp.data.decode("utf-8")
)

# create a bill
Expand All @@ -2601,7 +2598,7 @@ def test_logs_for_common_actions(self):
resp = self.client.get("/demo/history")
self.assertEqual(resp.status_code, 200)
self.assertIn(
"Bill %s added" % em_surround("25.0 for fromage à raclette"),
f"Bill {em_surround('25.0 for fromage à raclette')} added",
resp.data.decode("utf-8"),
)

Expand All @@ -2622,7 +2619,7 @@ def test_logs_for_common_actions(self):
resp = self.client.get("/demo/history")
self.assertEqual(resp.status_code, 200)
self.assertIn(
"Bill %s added" % em_surround("25.0 for fromage à raclette"),
f"Bill {em_surround('25.0 for fromage à raclette')} added",
resp.data.decode("utf-8"),
)
self.assertRegex(
Expand All @@ -2641,7 +2638,7 @@ def test_logs_for_common_actions(self):
)
self.assertLess(
resp.data.decode("utf-8").index(
"Bill %s renamed to" % em_surround("25.0 for fromage à raclette")
f"Bill {em_surround('25.0 for fromage à raclette')} renamed to"
),
resp.data.decode("utf-8").index("Amount changed"),
)
Expand All @@ -2653,7 +2650,7 @@ def test_logs_for_common_actions(self):
resp = self.client.get("/demo/history")
self.assertEqual(resp.status_code, 200)
self.assertIn(
"Bill %s removed" % em_surround("10.0 for new thing"),
f"Bill {em_surround('10.0 for new thing')} removed",
resp.data.decode("utf-8"),
)

Expand Down Expand Up @@ -2682,9 +2679,7 @@ def test_logs_for_common_actions(self):
resp.data.decode("utf-8"),
)
self.assertLess(
resp.data.decode("utf-8").index(
"Person %s renamed" % em_surround("alexis")
),
resp.data.decode("utf-8").index(f"Person {em_surround('alexis')} renamed"),
resp.data.decode("utf-8").index("Weight changed"),
)

Expand All @@ -2695,7 +2690,7 @@ def test_logs_for_common_actions(self):
resp = self.client.get("/demo/history")
self.assertEqual(resp.status_code, 200)
self.assertIn(
"Person %s removed" % em_surround("new name"), resp.data.decode("utf-8")
f"Person {em_surround('new name')} removed", resp.data.decode("utf-8")
)

def test_double_bill_double_person_edit_second(self):
Expand Down Expand Up @@ -2748,8 +2743,7 @@ def test_double_bill_double_person_edit_second(self):
self.assertEqual(resp.status_code, 200)
self.assertRegex(
resp.data.decode("utf-8"),
r"Bill %s:\s* Amount changed\s* from %s\s* to %s"
% (
r"Bill {}:\s* Amount changed\s* from {}\s* to {}".format(
em_surround("25.0 for Bill 1", regex_escape=True),
em_surround("25.0", regex_escape=True),
em_surround("88.0", regex_escape=True),
Expand All @@ -2758,8 +2752,7 @@ def test_double_bill_double_person_edit_second(self):

self.assertNotRegex(
resp.data.decode("utf-8"),
r"Removed\s* %s\s* and\s* %s\s* from\s* owers list"
% (
r"Removed\s* {}\s* and\s* {}\s* from\s* owers list".format(
em_surround("User 1", regex_escape=True),
em_surround("User 2", regex_escape=True),
),
Expand Down Expand Up @@ -2795,11 +2788,10 @@ def test_bill_add_remove_add(self):
self.assertEqual(resp.data.decode("utf-8").count("<td> -- </td>"), 5)
self.assertNotIn("127.0.0.1", resp.data.decode("utf-8"))
self.assertIn(
"Bill %s added" % em_surround("25.0 for Bill 1"), resp.data.decode("utf-8")
f"Bill {em_surround('25.0 for Bill 1')} added", resp.data.decode("utf-8")
)
self.assertIn(
"Bill %s removed" % em_surround("25.0 for Bill 1"),
resp.data.decode("utf-8"),
f"Bill {em_surround('25.0 for Bill 1')} removed", resp.data.decode("utf-8"),
)

# Add a new bill
Expand All @@ -2819,20 +2811,19 @@ def test_bill_add_remove_add(self):
self.assertEqual(resp.data.decode("utf-8").count("<td> -- </td>"), 6)
self.assertNotIn("127.0.0.1", resp.data.decode("utf-8"))
self.assertIn(
"Bill %s added" % em_surround("25.0 for Bill 1"), resp.data.decode("utf-8")
f"Bill {em_surround('25.0 for Bill 1')} added", resp.data.decode("utf-8")
)
self.assertEqual(
resp.data.decode("utf-8").count(
"Bill %s added" % em_surround("25.0 for Bill 1")
f"Bill {em_surround('25.0 for Bill 1')} added"
),
1,
)
self.assertIn(
"Bill %s added" % em_surround("20.0 for Bill 2"), resp.data.decode("utf-8")
f"Bill {em_surround('20.0 for Bill 2')} added", resp.data.decode("utf-8")
)
self.assertIn(
"Bill %s removed" % em_surround("25.0 for Bill 1"),
resp.data.decode("utf-8"),
f"Bill {em_surround('25.0 for Bill 1')} removed", resp.data.decode("utf-8"),
)

def test_double_bill_double_person_edit_second_no_web(self):
Expand Down
Loading