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

View File

@ -9,6 +9,9 @@ SET_TYPES = (
class Exercise(models.Model): class Exercise(models.Model):
name = models.CharField(max_length=200) name = models.CharField(max_length=200)
def __str__(self):
return self.name
class Set(models.Model): class Set(models.Model):
date = models.DateField() 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 3 @ 135
# squat 2 @ 185 # squat 2 @ 185
# squat 5 @ 225 # 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") assert Exercise.objects.count() == 2
bp = Exercise.objects.get(name="flat barbell bench press")
squat = Exercise.objects.get(name="barbell squat") squat = Exercise.objects.get(name="barbell squat")
assert Set.objects.count() == 9 assert Set.objects.count() == 9