bia-fitness/lifting/tests.py

56 lines
2.1 KiB
Python
Raw Normal View History

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-03-31 21:26:03 +00:00
from lifting.models import Exercise, Set
from lifting.importers import import_fitnotes_db
class TestFitnotesImport(TestCase):
# fitnotes.db has:
# April 1
# bench press 10 @ 45
# bench press 5 @ 95
# bench press 3 @ 135
# bench press 5 @ 155
# April 3
# squat 10 @ 45
# squat 5 @ 95
# squat 3 @ 135
# squat 2 @ 185
# squat 5 @ 225
2015-04-01 21:57:30 +00:00
def setUp(self):
self.user = User.objects.create_user('default', 'default@example.com', 'default')
2015-04-01 18:43:47 +00:00
def test_basic_import(self):
2015-04-01 21:19:28 +00:00
# ensure that the data comes in
2015-04-01 21:57:30 +00:00
import_fitnotes_db('lifting/testdata/example.fitnotes', self.user)
2015-03-31 21:26:03 +00:00
2015-04-01 18:43:47 +00:00
assert Exercise.objects.count() == 2
2015-04-01 21:19:28 +00:00
bp = Exercise.objects.get(names__contains=["flat barbell bench press"])
squat = Exercise.objects.get(names__contains=["barbell squat"])
assert Set.objects.count() == 9
2015-03-31 21:26:03 +00:00
2015-04-01 21:19:28 +00:00
def test_double_import(self):
# two identical dbs, should be idempotent
2015-04-01 21:57:30 +00:00
import_fitnotes_db('lifting/testdata/example.fitnotes', self.user)
import_fitnotes_db('lifting/testdata/example.fitnotes', self.user)
2015-04-01 21:19:28 +00:00
assert Exercise.objects.count() == 2
2015-04-01 18:43:47 +00:00
assert Set.objects.count() == 9
2015-04-01 21:31:25 +00:00
2015-04-01 21:47:41 +00:00
def test_import_with_other_data(self):
Exercise.objects.create(names=['incline bench press'])
e = Exercise.objects.create(names=['flat barbell bench press'])
2015-04-01 21:57:30 +00:00
Set.objects.create(exercise=e, weight_kg=100, reps=10, date='2014-01-01', user=self.user)
import_fitnotes_db('lifting/testdata/example.fitnotes', self.user)
2015-04-01 21:47:41 +00:00
assert Exercise.objects.count() == 3
assert Set.objects.count() == 10
2015-04-01 21:31:25 +00:00
def test_bad_import(self):
# good db then bad db, should fail without screwing up existing data
2015-04-01 21:57:30 +00:00
import_fitnotes_db('lifting/testdata/example.fitnotes', self.user)
2015-04-01 21:43:10 +00:00
with self.assertRaises(Exception):
2015-04-01 21:31:25 +00:00
# baddata.fitnotes has all exercise ids set to 9999
2015-04-01 21:57:30 +00:00
import_fitnotes_db('lifting/testdata/baddata.fitnotes', self.user)
2015-04-01 21:31:25 +00:00
assert Exercise.objects.count() == 2
assert Set.objects.count() == 9