more FitNotes tests
This commit is contained in:
parent
397d1223c9
commit
03650d27ef
@ -1,4 +1,5 @@
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
|
from django.db import transaction
|
||||||
from lifting.models import Exercise, Set
|
from lifting.models import Exercise, Set
|
||||||
|
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ def import_fitnotes_db(filename):
|
|||||||
# map to an Exercise id or str
|
# map to an Exercise id or str
|
||||||
exercise_id_mapping[fnid] = exercises[cleaned] if cleaned in exercises else cleaned
|
exercise_id_mapping[fnid] = exercises[cleaned] if cleaned in exercises else cleaned
|
||||||
|
|
||||||
|
with transaction.atomic():
|
||||||
Set.objects.filter(source='fitnotes').delete()
|
Set.objects.filter(source='fitnotes').delete()
|
||||||
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'):
|
||||||
|
BIN
lifting/testdata/baddata.fitnotes
vendored
Normal file
BIN
lifting/testdata/baddata.fitnotes
vendored
Normal file
Binary file not shown.
@ -32,3 +32,14 @@ class TestFitnotesImport(TestCase):
|
|||||||
import_fitnotes_db('lifting/testdata/example.fitnotes')
|
import_fitnotes_db('lifting/testdata/example.fitnotes')
|
||||||
assert Exercise.objects.count() == 2
|
assert Exercise.objects.count() == 2
|
||||||
assert Set.objects.count() == 9
|
assert Set.objects.count() == 9
|
||||||
|
|
||||||
|
def test_bad_import(self):
|
||||||
|
# good db then bad db, should fail without screwing up existing data
|
||||||
|
import_fitnotes_db('lifting/testdata/example.fitnotes')
|
||||||
|
try:
|
||||||
|
# baddata.fitnotes has all exercise ids set to 9999
|
||||||
|
import_fitnotes_db('lifting/testdata/baddata.fitnotes')
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
assert Exercise.objects.count() == 2
|
||||||
|
assert Set.objects.count() == 9
|
||||||
|
Loading…
Reference in New Issue
Block a user