Code Duplication    Length = 22-24 lines in 4 locations

tests/unit/test_main.py 4 locations

@@ 577-600 (lines=24) @@
574
        self.scheduler.get_maintenance.assert_called_once_with("1234")
575
        self.scheduler.update.assert_not_called()
576
577
    async def test_update_mw_case_5(self):
578
        """Test successful update."""
579
        self.napp.controller.loop = asyncio.get_running_loop()
580
        start1 = datetime.now(pytz.utc) + timedelta(days=1)
581
        end1 = start1 + timedelta(hours=6)
582
        self.scheduler.get_maintenance.return_value = MW.model_construct(
583
            id="1234",
584
            start=start1.replace(microsecond=0),
585
            end=end1.replace(microsecond=0),
586
            switches=["00:00:00:00:00:00:12:23"],
587
        )
588
        start_new = datetime.now(pytz.utc) + timedelta(days=1, hours=3)
589
        end_new = start_new - timedelta(hours=5)
590
        payload = {
591
            "start": start_new.strftime(TIME_FMT),
592
            "end": end_new.strftime(TIME_FMT),
593
        }
594
        url = f"{self.base_endpoint}/1234"
595
        response = await self.api.patch(url, json=payload)
596
        current_data = response.json()
597
        assert response.status_code == 400
598
        assert current_data["description"] == "end: Value error, End before start not allowed"
599
        self.scheduler.get_maintenance.assert_called_once_with("1234")
600
        self.scheduler.update.assert_not_called()
601
602
    async def test_update_mw_case_6(self):
603
        """Test successful update."""
@@ 809-831 (lines=23) @@
806
        self.scheduler.get_maintenance.assert_called_once_with("1234")
807
        self.scheduler.update.assert_not_called()
808
809
    async def test_extend_case_6(self):
810
        """Test maintenance already finished."""
811
        self.napp.controller.loop = asyncio.get_running_loop()
812
        start1 = datetime.now(pytz.utc) - timedelta(hours=3)
813
        end1 = start1 + timedelta(hours=2)
814
        self.scheduler.get_maintenance.return_value = MW.model_construct(
815
            id="1234",
816
            start=start1.replace(microsecond=0),
817
            end=end1.replace(microsecond=0),
818
            switches=["00:00:00:00:00:00:12:23"],
819
            status="finished",
820
        )
821
        url = f"{self.base_endpoint}/1234/extend"
822
        payload = {"minutes": 240}
823
        response = await self.api.patch(url, json=payload)
824
        assert response.status_code == 400
825
        current_data = response.json()
826
        assert (
827
            current_data["description"]
828
            == "Maintenance window 1234 has already finished"
829
        )
830
        self.scheduler.get_maintenance.assert_called_once_with("1234")
831
        self.scheduler.update.assert_not_called()
832
833
    async def test_extend_case_7(self):
834
        """Test no maintenace found."""
@@ 786-807 (lines=22) @@
783
        assert current_data["description"] == "Minutes of extension must be integer"
784
        self.scheduler.update.assert_not_called()
785
786
    async def test_extend_case_5(self):
787
        """Test maintenance did not start."""
788
        self.napp.controller.loop = asyncio.get_running_loop()
789
        start1 = datetime.now(pytz.utc) + timedelta(hours=3)
790
        end1 = start1 + timedelta(hours=4)
791
        self.scheduler.get_maintenance.return_value = MW.model_construct(
792
            id="1234",
793
            start=start1.replace(microsecond=0),
794
            end=end1.replace(microsecond=0),
795
            switches=["00:00:00:00:00:00:12:23"],
796
            status="pending",
797
        )
798
        url = f"{self.base_endpoint}/1234/extend"
799
        payload = {"minutes": 240}
800
        response = await self.api.patch(url, json=payload)
801
        assert response.status_code == 400
802
        current_data = response.json()
803
        assert (
804
            current_data["description"] == "Maintenance window 1234 has not yet started"
805
        )
806
        self.scheduler.get_maintenance.assert_called_once_with("1234")
807
        self.scheduler.update.assert_not_called()
808
809
    async def test_extend_case_6(self):
810
        """Test maintenance already finished."""
@@ 554-575 (lines=22) @@
551
            )
552
        )
553
554
    async def test_update_mw_case_4(self):
555
        """Test successful update."""
556
        self.napp.controller.loop = asyncio.get_running_loop()
557
        start1 = datetime.now(pytz.utc) + timedelta(days=1)
558
        end1 = start1 + timedelta(hours=6)
559
        self.scheduler.get_maintenance.return_value = MW.model_construct(
560
            id="1234",
561
            start=start1.replace(microsecond=0),
562
            end=end1.replace(microsecond=0),
563
            switches=["00:00:00:00:00:00:12:23"],
564
        )
565
        start_new = datetime.now(pytz.utc) - timedelta(days=1, hours=3)
566
        payload = {
567
            "start": start_new.strftime(TIME_FMT),
568
        }
569
        url = f"{self.base_endpoint}/1234"
570
        response = await self.api.patch(url, json=payload)
571
        current_data = response.json()
572
        assert response.status_code == 400
573
        assert current_data["description"] == "start: Value error, Start in the past not allowed"
574
        self.scheduler.get_maintenance.assert_called_once_with("1234")
575
        self.scheduler.update.assert_not_called()
576
577
    async def test_update_mw_case_5(self):
578
        """Test successful update."""