2323# wger
2424from wger .core .tests .base_testcase import WgerTestCase
2525from wger .manager .models import (
26- Slot ,
27- SlotEntry ,
2826 WorkoutLog ,
2927 WorkoutSession ,
3028)
@@ -152,27 +150,6 @@ def test_create_session(self):
152150
153151 self .assertEqual (WorkoutSession .objects .count (), 1 )
154152
155- def test_create_session_sets_day (self ):
156- """
157- The auto-created session inherits the day of the log's slot entry, so
158- that need_logs_to_advance days can find it
159- """
160-
161- WorkoutLog .objects .all ().delete ()
162- WorkoutSession .objects .all ().delete ()
163-
164- WorkoutLog (
165- user_id = 1 ,
166- exercise_id = 1 ,
167- routine_id = 1 ,
168- slot_entry_id = 1 ,
169- weight = 10 ,
170- repetitions = 10 ,
171- ).save ()
172-
173- session = WorkoutSession .objects .get ()
174- self .assertEqual (session .day_id , 1 )
175-
176153 def test_create_session_without_slot_entry_has_no_day (self ):
177154 """
178155 A free log without a slot entry can't know its day
@@ -191,28 +168,6 @@ def test_create_session_without_slot_entry_has_no_day(self):
191168 session = WorkoutSession .objects .get ()
192169 self .assertIsNone (session .day_id )
193170
194- def test_fills_missing_day_on_a_client_created_session (self ):
195- """
196- A session the client created without a day gets it from the log, so that
197- need_logs_to_advance days can find it
198- """
199-
200- session = WorkoutSession .objects .get (pk = 'bbbbbbbb-bbbb-bbbb-bbbb-000000000001' )
201- self .assertIsNone (session .day_id )
202-
203- WorkoutLog (
204- user_id = 1 ,
205- exercise_id = 1 ,
206- routine_id = 1 ,
207- slot_entry_id = 1 ,
208- session = session ,
209- weight = 10 ,
210- repetitions = 10 ,
211- ).save ()
212-
213- session .refresh_from_db ()
214- self .assertEqual (session .day_id , 1 )
215-
216171 def test_does_not_overwrite_the_day_of_a_session (self ):
217172 """
218173 A session that already has a day keeps it, even when the log points
@@ -236,112 +191,6 @@ def test_does_not_overwrite_the_day_of_a_session(self):
236191 session .refresh_from_db ()
237192 self .assertEqual (session .day_id , 3 )
238193
239- def test_does_not_fill_the_day_when_the_logs_span_several_days (self ):
240- """
241- A session whose logs come from more than one day stays without one, since
242- no single day is the right answer
243- """
244-
245- session = WorkoutSession .objects .get (pk = 'bbbbbbbb-bbbb-bbbb-bbbb-000000000001' )
246- self .assertIsNone (session .day_id )
247-
248- # A second entry, on another day of the same routine
249- other_slot = Slot .objects .create (day_id = 3 , order = 1 )
250- other_entry = SlotEntry .objects .create (slot = other_slot , exercise_id = 1 , order = 1 )
251-
252- WorkoutLog (
253- user_id = 1 ,
254- exercise_id = 1 ,
255- routine_id = 1 ,
256- slot_entry_id = 1 ,
257- session = session ,
258- weight = 10 ,
259- repetitions = 10 ,
260- ).save ()
261-
262- session .refresh_from_db ()
263- self .assertEqual (session .day_id , 1 )
264-
265- # The day of the first log is no longer the whole truth, but an already
266- # set day is never taken away again
267- WorkoutLog (
268- user_id = 1 ,
269- exercise_id = 1 ,
270- routine_id = 1 ,
271- slot_entry = other_entry ,
272- session = session ,
273- weight = 10 ,
274- repetitions = 10 ,
275- ).save ()
276-
277- session .refresh_from_db ()
278- self .assertEqual (session .day_id , 1 )
279-
280- def test_does_not_fill_the_day_when_earlier_logs_disagree (self ):
281- """
282- Logs that were already there decide as well, not just the one being saved
283- """
284-
285- session = WorkoutSession .objects .get (pk = 'bbbbbbbb-bbbb-bbbb-bbbb-000000000001' )
286- other_slot = Slot .objects .create (day_id = 3 , order = 1 )
287- other_entry = SlotEntry .objects .create (slot = other_slot , exercise_id = 1 , order = 1 )
288-
289- # Two logs from different days, written without going through save()
290- for slot_entry_id in (1 , other_entry .pk ):
291- WorkoutLog .objects .bulk_create (
292- [
293- WorkoutLog (
294- user_id = 1 ,
295- exercise_id = 1 ,
296- routine_id = 1 ,
297- slot_entry_id = slot_entry_id ,
298- session = session ,
299- weight = 10 ,
300- repetitions = 10 ,
301- )
302- ]
303- )
304-
305- session .refresh_from_db ()
306- self .assertIsNone (session .day_id )
307-
308- WorkoutLog (
309- user_id = 1 ,
310- exercise_id = 1 ,
311- routine_id = 1 ,
312- slot_entry_id = 1 ,
313- session = session ,
314- weight = 20 ,
315- repetitions = 8 ,
316- ).save ()
317-
318- session .refresh_from_db ()
319- self .assertIsNone (session .day_id )
320-
321- def test_does_not_fill_the_day_from_another_routine (self ):
322- """
323- The day of a slot entry from a different routine must not leak into the
324- session
325- """
326-
327- session = WorkoutSession .objects .get (pk = 'bbbbbbbb-bbbb-bbbb-bbbb-000000000003' )
328- self .assertIsNone (session .day_id )
329- self .assertEqual (session .routine_id , 2 )
330-
331- # slot entry 1 lives in routine 1, the session in routine 2
332- WorkoutLog (
333- user_id = 1 ,
334- exercise_id = 1 ,
335- routine_id = 1 ,
336- slot_entry_id = 1 ,
337- session = session ,
338- weight = 10 ,
339- repetitions = 10 ,
340- ).save ()
341-
342- session .refresh_from_db ()
343- self .assertIsNone (session .day_id )
344-
345194 def test_save_reuses_session_when_duplicates_exist (self ):
346195 """
347196 Duplicate routine-less sessions can exist for one (user, date) because the
0 commit comments