Skip to content

Commit

Permalink
Merge pull request #87 from Yelp/fix-type-error
Browse files Browse the repository at this point in the history
Extract format_loves and fix type error
  • Loading branch information
rockdog authored Aug 6, 2024
2 parents 3d78a72 + a6bc46f commit bdea219
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.6
12 changes: 12 additions & 0 deletions loveapp/util/formatting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def format_loves(loves):
# organise loves into two roughly equal lists for displaying
if len(loves) < 20:
loves_list_one = loves
loves_list_two = []
else:
loves_list_one = loves[:len(loves)//2]
loves_list_two = loves[len(loves)//2:]

if len(loves_list_one) < len(loves_list_two):
loves_list_one.append(loves_list_two.pop())
return loves_list_one, loves_list_two
15 changes: 1 addition & 14 deletions loveapp/views/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from loveapp.util.decorators import admin_required
from loveapp.util.decorators import csrf_protect
from loveapp.util.decorators import user_required
from loveapp.util.formatting import format_loves
from loveapp.util.recipient import sanitize_recipients
from loveapp.util.render import make_json_response
from loveapp.util.render import render_template
Expand Down Expand Up @@ -95,20 +96,6 @@ def me_or_explore(user):
return redirect(url_for('web_app.explore', user=username))


def format_loves(loves):
# organise loves into two roughly equal lists for displaying
if len(loves) < 20:
loves_list_one = loves
loves_list_two = []
else:
loves_list_one = loves[:len(loves)/2]
loves_list_two = loves[len(loves)/2:]

if len(loves_list_one) < len(loves_list_two):
loves_list_one.append(loves_list_two.pop())
return loves_list_one, loves_list_two


@web_app.route('/value/<string:company_value_id>', methods=['GET'])
@user_required
def single_company_value(company_value_id):
Expand Down
13 changes: 13 additions & 0 deletions tests/util/formatting_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
import pytest

from loveapp.util.formatting import format_loves


@pytest.mark.parametrize('loves, expected', [
([], ([], [])),
(list(range(5)), (list(range(5)), [])),
(list(range(31)), (list(range(15)) + [30], list(range(15, 30)))),
])
def test_format_loves(loves, expected):
assert format_loves(loves) == expected

0 comments on commit bdea219

Please sign in to comment.