|
1 | 1 | # Tests for validating process_tracking works as expected. |
2 | 2 |
|
3 | | -from datetime import datetime |
| 3 | +from datetime import datetime, timedelta |
4 | 4 | import unittest |
5 | 5 |
|
6 | 6 | from sqlalchemy.orm import Session |
@@ -441,3 +441,101 @@ def test_raise_run_error_with_fail(self): |
441 | 441 | with self.subTest(): |
442 | 442 | self.assertTrue('Process halting. An error triggered the process to fail.' in str(context.exception)) |
443 | 443 |
|
| 444 | + def test_set_run_low_high_dates(self): |
| 445 | + """ |
| 446 | + Testing that if low and high date are not set, the process_tracking_record low/high dates are set. |
| 447 | + :return: |
| 448 | + """ |
| 449 | + low_date = datetime.now() - timedelta(hours=1) |
| 450 | + high_date = datetime.now() |
| 451 | + |
| 452 | + self.process_tracker.set_process_run_low_high_dates(low_date=low_date, high_date=high_date) |
| 453 | + |
| 454 | + given_dates = self.session.query(ProcessTracking.process_run_low_date_time, ProcessTracking.process_run_high_date_time)\ |
| 455 | + .filter(ProcessTracking.process_tracking_id == self.process_tracker.process_tracking_run.process_tracking_id) |
| 456 | + |
| 457 | + expected_result = [low_date, high_date] |
| 458 | + given_result = [given_dates[0].process_run_low_date_time, given_dates[0].process_run_high_date_time] |
| 459 | + |
| 460 | + self.assertEqual(expected_result, given_result) |
| 461 | + |
| 462 | + def test_set_run_low_high_dates_lower_low_date(self): |
| 463 | + """ |
| 464 | + Testing that if a new low date comes in for a given process_run, set the process_run_low_date_time to the new |
| 465 | + low date. |
| 466 | + :return: |
| 467 | + """ |
| 468 | + low_date = datetime.now() - timedelta(hours=1) |
| 469 | + lower_low_date = low_date - timedelta(hours=1) |
| 470 | + |
| 471 | + self.process_tracker.set_process_run_low_high_dates(low_date=low_date) |
| 472 | + |
| 473 | + self.process_tracker.set_process_run_low_high_dates(low_date=lower_low_date) |
| 474 | + |
| 475 | + given_dates = self.session.query(ProcessTracking.process_run_low_date_time) \ |
| 476 | + .filter(ProcessTracking.process_tracking_id == self.process_tracker.process_tracking_run.process_tracking_id) |
| 477 | + |
| 478 | + expected_result = lower_low_date |
| 479 | + given_result = given_dates[0].process_run_low_date_time |
| 480 | + |
| 481 | + self.assertEqual(expected_result, given_result) |
| 482 | + |
| 483 | + def test_set_run_low_high_dates_higher_high_date(self): |
| 484 | + """ |
| 485 | + Testing that if a new low date comes in for a given process_run, set the process_run_low_date_time to the new |
| 486 | + low date. |
| 487 | + :return: |
| 488 | + """ |
| 489 | + high_date = datetime.now() |
| 490 | + higher_high_date = high_date + timedelta(hours=1) |
| 491 | + |
| 492 | + self.process_tracker.set_process_run_low_high_dates(high_date=high_date) |
| 493 | + |
| 494 | + self.process_tracker.set_process_run_low_high_dates(high_date=higher_high_date) |
| 495 | + |
| 496 | + given_dates = self.session.query(ProcessTracking.process_run_high_date_time) \ |
| 497 | + .filter(ProcessTracking.process_tracking_id == self.process_tracker.process_tracking_run.process_tracking_id) |
| 498 | + |
| 499 | + expected_result = higher_high_date |
| 500 | + given_result = given_dates[0].process_run_high_date_time |
| 501 | + |
| 502 | + self.assertEqual(expected_result, given_result) |
| 503 | + |
| 504 | + def test_set_process_run_record_count(self): |
| 505 | + """ |
| 506 | + Testing that if record counts are provided for a given process_run, set the process_run_record_count and process' |
| 507 | + total_record_counts correctly. |
| 508 | + :return: |
| 509 | + """ |
| 510 | + initial_record_count = 1000 |
| 511 | + |
| 512 | + self.process_tracker.set_process_run_record_count(num_records=initial_record_count) |
| 513 | + |
| 514 | + given_counts = self.session.query(ProcessTracking.process_run_record_count, Process.total_record_count) \ |
| 515 | + .join(Process)\ |
| 516 | + .filter(ProcessTracking.process_tracking_id == self.process_tracker.process_tracking_run.process_tracking_id) |
| 517 | + |
| 518 | + expected_result = [initial_record_count, initial_record_count] |
| 519 | + given_result = [given_counts[0].process_run_record_count, given_counts[0].total_record_count] |
| 520 | + |
| 521 | + self.assertEqual(expected_result, given_result) |
| 522 | + |
| 523 | + def test_set_process_run_record_count_twice(self): |
| 524 | + """ |
| 525 | + Testing that if record counts get set multiple times, then the process total record count will be set correctly. |
| 526 | + :return: |
| 527 | + """ |
| 528 | + initial_record_count = 1000 |
| 529 | + modified_record_count = 1500 |
| 530 | + |
| 531 | + self.process_tracker.set_process_run_record_count(num_records=initial_record_count) |
| 532 | + self.process_tracker.set_process_run_record_count(num_records=modified_record_count) |
| 533 | + |
| 534 | + given_counts = self.session.query(ProcessTracking.process_run_record_count, Process.total_record_count) \ |
| 535 | + .join(Process)\ |
| 536 | + .filter(ProcessTracking.process_tracking_id == self.process_tracker.process_tracking_run.process_tracking_id) |
| 537 | + |
| 538 | + expected_result = [modified_record_count, modified_record_count] |
| 539 | + given_result = [given_counts[0].process_run_record_count, given_counts[0].total_record_count] |
| 540 | + |
| 541 | + self.assertEqual(expected_result, given_result) |
0 commit comments