bia-fitness/lifting/tests.py

61 lines
2.4 KiB
Python
Raw Normal View History

from decimal import Decimal as D
2015-03-31 21:26:03 +00:00
from django.test import TestCase
2015-04-01 21:57:30 +00:00
from django.contrib.auth.models import User
2015-04-10 18:19:12 +00:00
from lifting.models import LiftingOptions
2015-03-31 21:26:03 +00:00
2015-04-10 18:19:12 +00:00
class TestLiftingOptions(TestCase):
2015-03-31 21:26:03 +00:00
def setUp(self):
self.user = User.objects.create_user(username='test', email='test@example.com', password='test')
2015-04-10 18:19:12 +00:00
def test_signal(self):
assert LiftingOptions.objects.filter(user=self.user).count() == 1
def test_plates_for_weight(self):
opts = self.user.lifting_options
opts.plate_pairs = [D(45), D(45), D(25), D(10), D(5), D(5), D('2.5')]
opts.default_bar_id = 1
2015-04-13 03:59:21 +00:00
opts.lifting_units = 'i'
assert opts.plates_for_weight(45) == []
assert opts.plates_for_weight(50) == [D('2.5')]
assert opts.plates_for_weight(90) == [D(10), D(5), D(5), D('2.5')]
assert opts.plates_for_weight(320) == [D(45), D(45), D(25), D(10), D(5), D(5), D('2.5')]
2015-04-13 03:59:21 +00:00
def test_plates_for_weight_womens_bar(self):
opts = self.user.lifting_options
opts.plate_pairs = [D(45), D(45), D(25), D(10), D(5), D(5), D('2.5')]
opts.default_bar_id = 2
opts.lifting_units = 'i'
assert opts.plates_for_weight(35) == []
assert opts.plates_for_weight(40) == [D('2.5')]
assert opts.plates_for_weight(80) == [D(10), D(5), D(5), D('2.5')]
assert opts.plates_for_weight(310) == [D(45), D(45), D(25), D(10), D(5), D(5), D('2.5')]
def test_plates_for_weight_kg(self):
opts = self.user.lifting_options
opts.plate_pairs = [D(20), D(20), D(10), D(5), D('2.5')]
opts.default_bar_id = 1
opts.lifting_units = 'm'
assert opts.plates_for_weight(20) == []
assert opts.plates_for_weight(25) == [D('2.5')]
assert opts.plates_for_weight(55) == [D(10), D(5), D('2.5')]
assert opts.plates_for_weight(135) == [D(20), D(20), D(10), D(5), D('2.5')]
def test_plates_for_weight_error(self):
opts = self.user.lifting_options
opts.plate_pairs = [D(45), D(45), D(25), D(10), D(5), D(5), D('2.5')]
opts.default_bar_id = 1
2015-04-13 03:59:21 +00:00
opts.lifting_units = 'i'
# TODO: check amounts
with self.assertRaises(ValueError):
opts.plates_for_weight('47.5')
with self.assertRaises(ValueError):
opts.plates_for_weight(325)
with self.assertRaises(ValueError):
opts.plates_for_weight(30)