def test_back_dating_update_with_earlier_days(self, sau_stub):
        """For RT-489, specifically"""
        # Arrange
        StrategicActionUpdateFactory.create(
            user=sau_stub["user"],
            strategic_action=sau_stub["sa"],
            supply_chain=sau_stub["sc"],
            status=Staus.SUBMITTED,
            implementation_rag_rating=RAGRating.GREEN,
            reason_for_delays="some text",
            date_created=date.today().replace(day=10) -
            relativedelta(months=3),
            submission_date=date.today().replace(day=10) -
            relativedelta(months=3),
        )
        # Act
        sau = StrategicActionUpdateFactory.build(
            user=sau_stub["user"],
            strategic_action=sau_stub["sa"],
            supply_chain=sau_stub["sc"],
            status=Staus.SUBMITTED,
            implementation_rag_rating=RAGRating.GREEN,
            reason_for_delays="some text",
            date_created=date.today().replace(day=20) -
            relativedelta(months=3),
            submission_date=date.today().replace(day=20) -
            relativedelta(months=3),
        )

        # Assert
        self.validate(sau, {ObjectLevelError: ""}, objects_saved=1)

        assert (StrategicActionUpdate.objects.given_month(date.today().replace(
            day=20) - relativedelta(months=3)).count() == 1)
    def test_back_dating_fail(self, sau_stub):
        # Arrange
        sau1 = StrategicActionUpdateFactory.create(
            user=sau_stub["user"],
            strategic_action=sau_stub["sa"],
            supply_chain=sau_stub["sc"],
            status=Staus.SUBMITTED,
            implementation_rag_rating=RAGRating.GREEN,
            reason_for_delays="some text",
            date_created=date.today().replace(day=20) -
            relativedelta(months=3),
            submission_date=date.today().replace(day=20) -
            relativedelta(months=3),
        )

        # Act
        new = StrategicActionUpdateFactory.build(
            user=sau_stub["user"],
            strategic_action=sau_stub["sa"],
            supply_chain=sau_stub["sc"],
            status=Staus.IN_PROGRESS,
            date_created=date.today().replace(day=20) -
            relativedelta(months=3),
        )

        # Assert
        self.validate(new, {ObjectLevelError: ""}, objects_saved=1)
        assert (StrategicActionUpdate.objects.given_month(date.today().replace(
            day=20) - relativedelta(months=3)).count() == 1)
    def test_SAU_missing_sub_date(self, sau_stub):
        # Arrange
        # Act
        sau = StrategicActionUpdateFactory.build(
            user=sau_stub["user"],
            strategic_action=sau_stub["sa"],
            supply_chain=sau_stub["sc"],
            status=Staus.SUBMITTED,
            submission_date=None,
        )

        # Assert
        self.validate(sau, {SubDate: ERROR_MSGS[SubDate]})
    def test_SAU_save(self, sau_stub):
        # Arrange
        # Act
        sau = StrategicActionUpdateFactory.build(
            user=sau_stub["user"],
            strategic_action=sau_stub["sa"],
            supply_chain=sau_stub["sc"],
            status=Staus.SUBMITTED,
            implementation_rag_rating=RAGRating.GREEN,
        )

        # Assert
        self.validate(sau, {}, objects_saved=1)
    def test_SAU_missing_RAG(self, sau_stub):
        # Arrange
        # Act
        sau = StrategicActionUpdateFactory.build(
            user=sau_stub["user"],
            strategic_action=sau_stub["sa"],
            supply_chain=sau_stub["sc"],
            status=Staus.SUBMITTED,
            implementation_rag_rating=None,
        )

        # Assert
        self.validate(sau, {RagRating: ERROR_MSGS[RagRating]})
    def test_SAU_missing_content(self, sau_stub):
        # Arrange
        # Act
        sau = StrategicActionUpdateFactory.build(
            user=sau_stub["user"],
            strategic_action=sau_stub["sa"],
            supply_chain=sau_stub["sc"],
            status=Staus.SUBMITTED,
            content=None,
        )

        # Assert
        self.validate(sau, {Content: ERROR_MSGS[Content]})
    def test_back_dating_update_in_gap(self, sau_stub):
        # Arrange
        StrategicActionUpdateFactory.create(
            user=sau_stub["user"],
            strategic_action=sau_stub["sa"],
            supply_chain=sau_stub["sc"],
            status=Staus.SUBMITTED,
            implementation_rag_rating=RAGRating.GREEN,
            reason_for_delays="some text",
            date_created=date.today().replace(day=20) -
            relativedelta(months=4),
            submission_date=date.today().replace(day=20) -
            relativedelta(months=4),
        )

        StrategicActionUpdateFactory.create(
            user=sau_stub["user"],
            strategic_action=sau_stub["sa"],
            supply_chain=sau_stub["sc"],
            status=Staus.SUBMITTED,
            implementation_rag_rating=RAGRating.GREEN,
            reason_for_delays="some text",
            date_created=date.today().replace(day=20) -
            relativedelta(months=2),
            submission_date=date.today().replace(day=20) -
            relativedelta(months=2),
        )

        # Act
        sau = StrategicActionUpdateFactory.build(
            user=sau_stub["user"],
            strategic_action=sau_stub["sa"],
            supply_chain=sau_stub["sc"],
            status=Staus.SUBMITTED,
            implementation_rag_rating=RAGRating.GREEN,
            reason_for_delays="some text",
            date_created=date.today().replace(day=20) -
            relativedelta(months=3),
            submission_date=date.today().replace(day=20) -
            relativedelta(months=3),
        )

        # Assert
        self.validate(sau, {}, objects_saved=3)
        assert (StrategicActionUpdate.objects.given_month(date.today().replace(
            day=20) - relativedelta(months=3)).count() == 1)
    def test_SAU_missing_completion_change_reason(self, sau_stub):
        # Arrange
        # Act
        sau = StrategicActionUpdateFactory.build(
            user=sau_stub["user"],
            strategic_action=sau_stub["sa"],
            supply_chain=sau_stub["sc"],
            status=Staus.SUBMITTED,
            implementation_rag_rating=RAGRating.RED,
            reason_for_delays="some text",
            changed_value_for_target_completion_date=date.today().replace(
                day=20) + relativedelta(years=1, months=1),
            reason_for_completion_date_change=None,
        )

        # Assert
        self.validate(sau, {
            CompletionDateChangeReason:
            ERROR_MSGS[CompletionDateChangeReason]
        })