Changeset 24596da in OpenWorkouts-current for ow/tests/models/test_user.py
- Timestamp:
- Feb 27, 2019, 6:28:07 PM (5 years ago)
- Branches:
- current, feature/docs, master
- Children:
- cef474f
- Parents:
- 68d00f5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/tests/models/test_user.py
r68d00f5 r24596da 348 348 'time': timedelta(0) 349 349 } 350 351 def test_yearly_stats(self, root): 352 expected_no_stats_per_month = { 353 'workouts': 0, 354 'time': timedelta(0), 355 'distance': Decimal(0), 356 'elevation': Decimal(0), 357 'sports': {} 358 } 359 360 yearly_stats = root['john'].yearly_stats 361 for month, stats in yearly_stats.items(): 362 assert stats == expected_no_stats_per_month 363 364 # add a cycling workout 365 start_date = datetime.now(timezone.utc) 366 workout = Workout( 367 start=start_date, 368 duration=timedelta(minutes=(60*4)), 369 uphill=1200, 370 distance=115, 371 sport='cycling') 372 root['john'].add_workout(workout) 373 374 yearly_stats = root['john'].yearly_stats 375 for month, stats in yearly_stats.items(): 376 if month == (start_date.year, start_date.month): 377 assert stats == { 378 'workouts': 1, 379 'time': timedelta(minutes=(60*4)), 380 'distance': Decimal(115), 381 'elevation': Decimal(1200), 382 'sports': { 383 'cycling': {'distance': Decimal(115), 384 'elevation': Decimal(1200), 385 'time': timedelta(minutes=(60*4)), 386 'workouts': 1} 387 } 388 } 389 else: 390 assert stats == expected_no_stats_per_month 391 392 # add a second cycling workout 393 workout = Workout( 394 start=start_date, 395 duration=timedelta(minutes=(30)), 396 uphill=500, 397 distance=20, 398 sport='cycling') 399 root['john'].add_workout(workout) 400 401 yearly_stats = root['john'].yearly_stats 402 for month, stats in yearly_stats.items(): 403 if month == (start_date.year, start_date.month): 404 assert stats == { 405 'workouts': 2, 406 'time': timedelta(minutes=((60*4)+30)), 407 'distance': Decimal(115+20), 408 'elevation': Decimal(1200+500), 409 'sports': { 410 'cycling': {'distance': Decimal(115+20), 411 'elevation': Decimal(1200+500), 412 'time': timedelta(minutes=((60*4)+30)), 413 'workouts': 2} 414 } 415 } 416 else: 417 assert stats == expected_no_stats_per_month 418 419 # add a running workout 420 workout = Workout( 421 start=start_date, 422 duration=timedelta(minutes=(60)), 423 uphill=200, 424 distance=5, 425 sport='running') 426 root['john'].add_workout(workout) 427 428 yearly_stats = root['john'].yearly_stats 429 for month, stats in yearly_stats.items(): 430 if month == (start_date.year, start_date.month): 431 assert stats == { 432 'workouts': 3, 433 'time': timedelta(minutes=((60*4)+30+60)), 434 'distance': Decimal(115+20+5), 435 'elevation': Decimal(1200+500+200), 436 'sports': { 437 'cycling': {'distance': Decimal(115+20), 438 'elevation': Decimal(1200+500), 439 'time': timedelta(minutes=((60*4)+30)), 440 'workouts': 2}, 441 'running': {'distance': Decimal(5), 442 'elevation': Decimal(200), 443 'time': timedelta(minutes=(60)), 444 'workouts': 1} 445 } 446 } 447 else: 448 assert stats == expected_no_stats_per_month 449 450 def test_weekly_year_stats(self, root): 451 expected_no_stats_per_week = { 452 'workouts': 0, 453 'time': timedelta(0), 454 'distance': Decimal(0), 455 'elevation': Decimal(0), 456 'sports': {} 457 } 458 459 weekly_year_stats = root['john'].weekly_year_stats 460 for week, stats in weekly_year_stats.items(): 461 assert stats == expected_no_stats_per_week 462 463 # add a cycling workout 464 start_date = datetime.now(timezone.utc) 465 workout = Workout( 466 start=start_date, 467 duration=timedelta(minutes=(60*4)), 468 uphill=1200, 469 distance=115, 470 sport='cycling') 471 root['john'].add_workout(workout) 472 473 weekly_year_stats = root['john'].weekly_year_stats 474 workout_week = (start_date.year, start_date.month, 475 start_date.isocalendar()[1]) 476 for week, stats in weekly_year_stats.items(): 477 if week[:3] == workout_week: 478 assert stats == { 479 'workouts': 1, 480 'time': timedelta(minutes=(60*4)), 481 'distance': Decimal(115), 482 'elevation': Decimal(1200), 483 'sports': { 484 'cycling': {'distance': Decimal(115), 485 'elevation': Decimal(1200), 486 'time': timedelta(minutes=(60*4)), 487 'workouts': 1} 488 } 489 } 490 else: 491 assert stats == expected_no_stats_per_week 492 493 # add a second cycling workout 494 workout = Workout( 495 start=start_date, 496 duration=timedelta(minutes=(30)), 497 uphill=500, 498 distance=20, 499 sport='cycling') 500 root['john'].add_workout(workout) 501 502 weekly_year_stats = root['john'].weekly_year_stats 503 workout_week = (start_date.year, start_date.month, 504 start_date.isocalendar()[1]) 505 for week, stats in weekly_year_stats.items(): 506 if week[:3] == workout_week: 507 assert stats == { 508 'workouts': 2, 509 'time': timedelta(minutes=((60*4)+30)), 510 'distance': Decimal(115+20), 511 'elevation': Decimal(1200+500), 512 'sports': { 513 'cycling': {'distance': Decimal(115+20), 514 'elevation': Decimal(1200+500), 515 'time': timedelta(minutes=((60*4)+30)), 516 'workouts': 2} 517 } 518 } 519 else: 520 assert stats == expected_no_stats_per_week 521 522 # add a running workout 523 workout = Workout( 524 start=start_date, 525 duration=timedelta(minutes=(60)), 526 uphill=200, 527 distance=5, 528 sport='running') 529 root['john'].add_workout(workout) 530 531 weekly_year_stats = root['john'].weekly_year_stats 532 workout_week = (start_date.year, start_date.month, 533 start_date.isocalendar()[1]) 534 for week, stats in weekly_year_stats.items(): 535 if week[:3] == workout_week: 536 assert stats == { 537 'workouts': 3, 538 'time': timedelta(minutes=((60*4)+30+60)), 539 'distance': Decimal(115+20+5), 540 'elevation': Decimal(1200+500+200), 541 'sports': { 542 'cycling': {'distance': Decimal(115+20), 543 'elevation': Decimal(1200+500), 544 'time': timedelta(minutes=((60*4)+30)), 545 'workouts': 2}, 546 'running': {'distance': Decimal(5), 547 'elevation': Decimal(200), 548 'time': timedelta(minutes=(60)), 549 'workouts': 1} 550 } 551 } 552 else: 553 assert stats == expected_no_stats_per_week
Note: See TracChangeset
for help on using the changeset viewer.