def test_venue_with_draft_bank_information(self):
        offerer = offerers_factories.OffererFactory()
        offers_factories.VirtualVenueFactory(managingOfferer=offerer)
        venue = offers_factories.VenueFactory(managingOfferer=offerer)
        offers_factories.BankInformationFactory(venue=venue, status=BankInformationStatus.DRAFT)

        assert not has_physical_venue_without_draft_or_accepted_bank_information(offerer_id=offerer.id)
Beispiel #2
0
    def test_keep_offerer_validation_token_if_siren_is_already_registered_but_not_validated(
            self, mock_maybe_send_offerer_validation_email):
        # Given
        offerers_factories.VirtualVenueTypeFactory()
        user = users_factories.UserFactory()
        offerer_informations = CreateOffererQueryModel(
            name="Test Offerer",
            siren="418166096",
            address="123 rue de Paris",
            postalCode="93100",
            city="Montreuil")
        offerer = offerers_factories.OffererFactory(
            siren=offerer_informations.siren, validationToken="TOKEN")

        # When
        created_user_offerer = offerers_api.create_offerer(
            user, offerer_informations)

        # Then
        created_offerer = created_user_offerer.offerer
        assert created_offerer.name == offerer.name
        assert created_offerer.validationToken == "TOKEN"

        assert created_user_offerer.userId == user.id
        assert created_user_offerer.validationToken is not None
Beispiel #3
0
    def test_create_new_offerer_attachment_with_validation_token_if_siren_is_already_registered(
            self, mock_maybe_send_offerer_validation_email):
        # Given
        offerers_factories.VirtualVenueTypeFactory()
        user = users_factories.UserFactory()
        offerer_informations = CreateOffererQueryModel(
            name="Test Offerer",
            siren="418166096",
            address="123 rue de Paris",
            postalCode="93100",
            city="Montreuil")
        offerer = offerers_factories.OffererFactory(
            siren=offerer_informations.siren)

        # When
        created_user_offerer = offerers_api.create_offerer(
            user, offerer_informations)

        # Then
        created_offerer = created_user_offerer.offerer
        assert created_offerer.name == offerer.name
        assert created_offerer.validationToken is None

        assert created_user_offerer.userId == user.id
        assert created_user_offerer.validationToken is not None

        assert not created_user_offerer.user.has_pro_role

        mock_maybe_send_offerer_validation_email.assert_called_once_with(
            created_user_offerer.offerer, created_user_offerer)
    def test_get_offerers_by_date_validated(self):
        offerer1 = offerers_factories.OffererFactory(
            siren="123456789", validationToken=None, dateValidated=datetime(2021, 6, 7, 15, 49)
        )
        offerer2 = offerers_factories.OffererFactory(
            siren="123456788", validationToken=None, dateValidated=datetime(2021, 6, 7, 23, 59, 59)
        )
        offerer3 = offerers_factories.OffererFactory(
            siren="123456787", validationToken=None, dateValidated=datetime(2021, 6, 8, 00, 00, 00)
        )
        offerer4 = offerers_factories.OffererFactory(
            siren="123456786", validationToken=None, dateValidated=datetime(2021, 6, 6, 11, 49)
        )

        assert set(get_offerers_by_date_validated(date(2021, 6, 7))) == {offerer1, offerer2}
        assert get_offerers_by_date_validated(date(2021, 6, 8)) == [offerer3]
        assert get_offerers_by_date_validated(date(2021, 6, 6)) == [offerer4]
    def test_find_existing_email(self):
        offerer = offerers_factories.OffererFactory()
        pro_user = users_factories.ProFactory()
        offers_factories.UserOffererFactory(offerer=offerer, user=pro_user)

        result = find_new_offerer_user_email(offerer.id)

        assert result == pro_user.email
    def test_venues_with_missing_and_accepted_bank_information(self):
        offerer = offerers_factories.OffererFactory()
        offers_factories.VirtualVenueFactory(managingOfferer=offerer)
        offers_factories.VenueFactory(managingOfferer=offerer)
        venue_with_rejected_bank_information = offers_factories.VenueFactory(managingOfferer=offerer)
        offers_factories.BankInformationFactory(
            venue=venue_with_rejected_bank_information, status=BankInformationStatus.ACCEPTED
        )

        assert has_physical_venue_without_draft_or_accepted_bank_information(offerer_id=offerer.id)
Beispiel #7
0
 def test_validation(self):
     # Validation is thoroughly verified in `test_validation.py`.
     # This is just an integration test.
     offerer = offerers_factories.OffererFactory()
     start = (datetime.today() + timedelta(days=1)).astimezone(pytz.utc)
     with pytest.raises(exceptions.UnknownSubcategoryForReimbursementRule):
         api.create_reimbursement_rule(offerer.id,
                                       subcategories=["UNKNOWN"],
                                       rate=0.8,
                                       start_date=start)
Beispiel #8
0
    def test_create_rule(self):
        offerer = offerers_factories.OffererFactory()
        start = pytz.utc.localize(datetime.today() + timedelta(days=1))
        end = pytz.utc.localize(datetime.today() + timedelta(days=2))
        rule = api.create_reimbursement_rule(offerer.id,
                                             subcategories=["VOD"],
                                             rate=0.8,
                                             start_date=start,
                                             end_date=end)

        db.session.refresh(rule)
        assert rule.offerer == offerer
        assert rule.subcategories == ["VOD"]
        assert rule.rate == Decimal("0.8")
        assert rule.timespan.lower == datetime(2021, 10, 2, 0, 0)
        assert rule.timespan.upper == datetime(2021, 10, 3, 0, 0)
    def test_return_user_with_validated_attachment(self):
        # Given
        applicant = users_factories.UserFactory()
        user_who_asked_for_attachment = users_factories.UserFactory()
        applied_offerer = offerers_factories.OffererFactory(
            validationToken="TOKEN")
        offers_factories.UserOffererFactory(offerer=applied_offerer,
                                            user=applicant)
        offers_factories.UserOffererFactory(offerer=applied_offerer,
                                            user=user_who_asked_for_attachment,
                                            validationToken="OTHER_TOKEN")

        # When
        applicants_found = get_users_with_validated_attachment_by_offerer(
            applied_offerer)

        # Then
        assert len(applicants_found) == 1
        assert applicants_found[0].id == applicant.id
Beispiel #10
0
def test_create_rule(mocked_validate_csrf_token, client, app):
    admin = users_factories.AdminFactory()
    offerer = offerers_factories.OffererFactory()

    data = dict(
        offerer=offerer.id,
        subcategories=[],
        rate=80,
        start_date="2030-10-01",
        end_date="",
    )
    client = client.with_session_auth(admin.email)
    response = client.post("/pc/back-office/customreimbursementrule/new/",
                           form=data)

    assert response.status_code == 302
    rule = payments_models.CustomReimbursementRule.query.one()
    assert rule.offerer == offerer
    assert rule.rate == decimal.Decimal("0.8")
    assert rule.subcategories == []
    assert rule.timespan.lower == datetime.datetime(2030, 9, 30, 22, 0)  # UTC
    assert rule.timespan.upper is None
    def test_digital_venue_without_offer(self):
        offerer = offerers_factories.OffererFactory()
        offers_factories.VirtualVenueFactory(managingOfferer=offerer)

        assert not has_digital_venue_with_at_least_one_offer(offerer.id)
    def test_find_filtered_offerers_with_keywords(self):
        offerer_with_only_virtual_venue_with_offer = offerers_factories.OffererFactory(siren="123456785")
        offerer_with_both_venues_offer_on_both = offerers_factories.OffererFactory(siren="123456782")
        offerer_with_both_venues_offer_on_virtual = offerers_factories.OffererFactory(siren="123456783")
        offerer_with_both_venues_offer_on_not_virtual = offerers_factories.OffererFactory(siren="123456784")

        virtual_venue_with_offer_1 = offers_factories.VenueFactory(
            managingOfferer=offerer_with_only_virtual_venue_with_offer, isVirtual=True, siret=None
        )
        virtual_venue_with_offer_3 = offers_factories.VenueFactory(
            managingOfferer=offerer_with_both_venues_offer_on_both,
            isVirtual=True,
            siret=None,
            publicName="Librairie des mots perdus",
        )
        venue_with_offer_3 = offers_factories.VenueFactory(
            managingOfferer=offerer_with_both_venues_offer_on_both,
            siret="12345678212345",
            publicName="Librairie des mots perdus",
        )
        virtual_venue_with_offer_4 = offers_factories.VenueFactory(
            managingOfferer=offerer_with_both_venues_offer_on_virtual,
            isVirtual=True,
            siret=None,
            publicName="Librairie des mots perdus",
        )
        venue_with_offer_5 = offers_factories.VenueFactory(
            managingOfferer=offerer_with_both_venues_offer_on_not_virtual,
            siret="12345678412345",
            publicName="Librairie des mots perdus",
        )
        offers_factories.VenueFactory(publicName="something else")

        offers_factories.ThingOfferFactory(venue=virtual_venue_with_offer_1, url="http://url.com")
        offers_factories.ThingOfferFactory(venue=virtual_venue_with_offer_3, url="http://url.com")
        offers_factories.ThingOfferFactory(venue=virtual_venue_with_offer_4, url="http://url.com")
        offers_factories.EventOfferFactory(venue=venue_with_offer_3)
        offers_factories.EventOfferFactory(venue=venue_with_offer_5)

        one_keyword_search = filter_offerers_with_keywords_string(Offerer.query.join(Venue), "perdus")
        partial_keyword_search = filter_offerers_with_keywords_string(Offerer.query.join(Venue), "Libr")
        two_keywords_search = filter_offerers_with_keywords_string(Offerer.query.join(Venue), "Librairie perd")
        two_partial_keywords_search = filter_offerers_with_keywords_string(Offerer.query.join(Venue), "Lib perd")

        assert {
            offerer_with_both_venues_offer_on_both,
            offerer_with_both_venues_offer_on_virtual,
            offerer_with_both_venues_offer_on_not_virtual,
        } == set(one_keyword_search)
        assert {
            offerer_with_both_venues_offer_on_both,
            offerer_with_both_venues_offer_on_virtual,
            offerer_with_both_venues_offer_on_not_virtual,
        } == set(partial_keyword_search)
        assert {
            offerer_with_both_venues_offer_on_both,
            offerer_with_both_venues_offer_on_virtual,
            offerer_with_both_venues_offer_on_not_virtual,
        } == set(two_keywords_search)
        assert {
            offerer_with_both_venues_offer_on_both,
            offerer_with_both_venues_offer_on_virtual,
            offerer_with_both_venues_offer_on_not_virtual,
        } == set(two_partial_keywords_search)