get fitnotes test kind of working

This commit is contained in:
James Turk 2015-04-01 14:43:47 -04:00
parent 062fa049c4
commit 94ff669419
4 changed files with 14 additions and 9 deletions

View File

@ -17,15 +17,15 @@ def import_fitnotes_db(filename):
cur = conn.cursor()
for fnid, ename in cur.execute('SELECT _id, name FROM exercise WHERE exercise_type_id=0'):
cleaned = _clean_name(ename)
if cleaned in exercises:
exercise_id_mapping[fnid] = exercises[cleaned]
# map to an Exercise id or str
exercise_id_mapping[fnid] = exercises[cleaned] if cleaned in exercises else cleaned
for fnid, date, weight_kg, reps in cur.execute(
'SELECT exercise_id, date, metric_weight, reps FROM training_log'):
# create Exercise if it wasn't found and there's a workout using it
if fnid not in exercise_id_mapping:
exercise_id_mapping[fnid] = Exercise.objects.create(name=cleaned).id
if isinstance(exercise_id_mapping[fnid], str):
exercise_id_mapping[fnid] = Exercise.objects.create(name=exercise_id_mapping[fnid]).id
exercise_id = exercise_id_mapping[fnid]

View File

@ -9,6 +9,9 @@ SET_TYPES = (
class Exercise(models.Model):
name = models.CharField(max_length=200)
def __str__(self):
return self.name
class Set(models.Model):
date = models.DateField()

BIN
lifting/testdata/example.fitnotes vendored Normal file

Binary file not shown.

View File

@ -16,11 +16,13 @@ class TestFitnotesImport(TestCase):
# squat 3 @ 135
# squat 2 @ 185
# squat 5 @ 225
import_fitnotes_db('example.fitnotes')
#assert Exercise.objects.count() == 2
def test_basic_import(self):
import_fitnotes_db('lifting/testdata/example.fitnotes')
bp = Exercise.objects.get(name="bench press")
squat = Exercise.objects.get(name="barbell squat")
assert Exercise.objects.count() == 2
assert Set.objects.count() == 9
bp = Exercise.objects.get(name="flat barbell bench press")
squat = Exercise.objects.get(name="barbell squat")
assert Set.objects.count() == 9