def test_raises_an_error_if_no_offerer_found(self):
        # given
        offerer = None

        # when
        with pytest.raises(CannotRegisterBankInformation) as error:
            check_offerer_presence(offerer)

        # then
        assert error.value.args == ("Offerer not found",)
Exemple #2
0
    def execute(self, application_id: str):
        application_details = get_venue_bank_information_application_details_by_application_id(
            application_id)

        try:
            siren = application_details.siren
            offerer = self.offerer_repository.find_by_siren(siren)
            check_offerer_presence(offerer)
            venue = self.get_referent_venue(application_details, offerer)
        except CannotRegisterBankInformation as error:
            if application_details.status == BankInformationStatus.ACCEPTED:
                raise error
            return None

        bank_information_by_application_id = self.bank_informations_repository.get_by_application(
            application_details.application_id)

        if bank_information_by_application_id:
            check_new_bank_information_older_than_saved_one(
                bank_information_by_application_id, application_details)
            new_bank_informations = self.create_new_bank_informations(
                application_details, venue.identifier)
            return self.bank_informations_repository.update_by_application_id(
                new_bank_informations)

        bank_information_by_venue_id = self.bank_informations_repository.find_by_venue(
            venue.identifier)

        if bank_information_by_venue_id:
            check_new_bank_information_older_than_saved_one(
                bank_information_by_venue_id, application_details)
            check_new_bank_information_has_a_more_advanced_status(
                bank_information_by_venue_id, application_details)

            new_bank_informations = self.create_new_bank_informations(
                application_details, venue.identifier)
            return self.bank_informations_repository.update_by_venue_id(
                new_bank_informations)

        new_bank_informations = self.create_new_bank_informations(
            application_details, venue.identifier)
        return self.bank_informations_repository.save(new_bank_informations)