From 94ff669419aee503c5d0901b4a676cd38f02fafd Mon Sep 17 00:00:00 2001 From: James Turk Date: Wed, 1 Apr 2015 14:43:47 -0400 Subject: [PATCH] get fitnotes test kind of working --- lifting/importers.py | 8 ++++---- lifting/models.py | 3 +++ lifting/testdata/example.fitnotes | Bin 0 -> 73728 bytes lifting/tests.py | 12 +++++++----- 4 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 lifting/testdata/example.fitnotes diff --git a/lifting/importers.py b/lifting/importers.py index 05a0e9f..3942c1d 100644 --- a/lifting/importers.py +++ b/lifting/importers.py @@ -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] diff --git a/lifting/models.py b/lifting/models.py index 623b16c..734141b 100644 --- a/lifting/models.py +++ b/lifting/models.py @@ -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() diff --git a/lifting/testdata/example.fitnotes b/lifting/testdata/example.fitnotes new file mode 100644 index 0000000000000000000000000000000000000000..14d2c9d21ddc6ae80951a8605488828628b8d8fd GIT binary patch literal 73728 zcmeI5e{38_7035{zMVb$?$%D?TpZiUh9pgn*d%F_w&@QN`+RXtY{$8ClBUpJH|OHZ?BF8e~_eAB}%EF@COy}55I)eO09%M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o)fJjCl&~p| z_?!#w-tC*~kAKpp6V8e>>fTY%o>Kou1hUivUc5Fov1ymc>VhGUx6zBaApuC~6o@L1TD zS)l2Xb0~WlPTT&iOq%4DQ~<8g%+?<9Ix^y!QBP=h7mZtZ1<$HCUZ(C+De-Zo z2|AgUc$||;*nAvaj$-VgdP@LZ`di?7Ckim z(Wpo}g*0uDzoUlbRtK79`_2xc!t2(g)#~1wqdzRFQ+73Y9`vKclkQQNG{&ooNUhfO zwLPu9jQDY_=4|DEpVw^ zD$l&C5nks5L7M(t=$q6i?r#(RHGAN7))Sy;` z#onVLTp$1fAOHd&00JNY0w4eaAOHd&@F69jg(Fg67Yitg5>}KGw;notbm-8Lp+mQx zxNz;I>pw0{hBT$BK}z)+Gk^cwi7(#%kD$g@)0p~3&+lJ2p9pF4Y8t60p8v|ZHy;aW zp{hoc9Y@UEJFh-CO{r?6YT(|}TAOHd&00JNY z0w4eaAOHd&00M#l_WuY45C8!X009sH0T2KI5C8!X009u#_yn;3-}qw;4?zF~KmY_l z00ck)1V8`;KmY_l0Q-N$00@8p2!H?xfB*=900@8p2!H?xYk0w4ea zAOHd&00JNY0w4eaAb|ZpVgLj{00ck)1V8`;KmY_l00ck)1U5ba?Eg3Z7{fyl009sH z0T2KI5C8!X009sH0T96cA29#|AOHd&00JNY0w4eaAOHd&00JAI0QUbIe~jTF2!H?x zfB*=900@8p2!H?xfB*>a{eM9HlSF@TfdB}A00@8p2!H?xfB*=900@8p2;AfZwg#e- Tq6C=2udot2{=={G>zRK8E)XhR literal 0 HcmV?d00001 diff --git a/lifting/tests.py b/lifting/tests.py index d9df877..459bb5f 100644 --- a/lifting/tests.py +++ b/lifting/tests.py @@ -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