update FN import test to work w/ names
This commit is contained in:
parent
a3bf766642
commit
9d2bf76d3d
@ -8,7 +8,10 @@ def _clean_name(name):
|
||||
|
||||
def import_fitnotes_db(filename):
|
||||
# exercise names to db ids
|
||||
exercises = {_clean_name(e.name): e.id for e in Exercise.objects.all()}
|
||||
exercises = {}
|
||||
for e in Exercise.objects.all():
|
||||
for n in e.names:
|
||||
exercises[_clean_name(n)] = e.id
|
||||
|
||||
# build mapping FitNotes exercise id => our exercise id
|
||||
exercise_id_mapping = {}
|
||||
@ -25,7 +28,8 @@ def import_fitnotes_db(filename):
|
||||
|
||||
# create Exercise if it wasn't found and there's a workout using it
|
||||
if isinstance(exercise_id_mapping[fnid], str):
|
||||
exercise_id_mapping[fnid] = Exercise.objects.create(name=exercise_id_mapping[fnid]).id
|
||||
exercise_id_mapping[fnid] = Exercise.objects.create(
|
||||
names=[exercise_id_mapping[fnid]]).id
|
||||
|
||||
exercise_id = exercise_id_mapping[fnid]
|
||||
|
||||
|
@ -11,7 +11,7 @@ class Exercise(models.Model):
|
||||
names = ArrayField(models.CharField(max_length=200))
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
return self.names
|
||||
|
||||
|
||||
class Set(models.Model):
|
||||
|
@ -18,11 +18,17 @@ class TestFitnotesImport(TestCase):
|
||||
# squat 5 @ 225
|
||||
|
||||
def test_basic_import(self):
|
||||
# ensure that the data comes in
|
||||
import_fitnotes_db('lifting/testdata/example.fitnotes')
|
||||
|
||||
assert Exercise.objects.count() == 2
|
||||
|
||||
bp = Exercise.objects.get(name="flat barbell bench press")
|
||||
squat = Exercise.objects.get(name="barbell squat")
|
||||
|
||||
bp = Exercise.objects.get(names__contains=["flat barbell bench press"])
|
||||
squat = Exercise.objects.get(names__contains=["barbell squat"])
|
||||
assert Set.objects.count() == 9
|
||||
|
||||
def test_double_import(self):
|
||||
# two identical dbs, should be idempotent
|
||||
import_fitnotes_db('lifting/testdata/example.fitnotes')
|
||||
import_fitnotes_db('lifting/testdata/example.fitnotes')
|
||||
assert Exercise.objects.count() == 2
|
||||
assert Set.objects.count() == 9
|
||||
|
Loading…
Reference in New Issue
Block a user