def test_get_enabled_providers_for_pro(self, app): # given provider1 = Provider() provider1.name = 'Open Agenda' provider1.localClass = 'OpenAgenda' provider1.isActive = False provider1.enabledForPro = False provider2 = Provider() provider2.name = 'Tite Live' provider2.localClass = 'TiteLive' provider2.isActive = True provider2.enabledForPro = True PcObject.save(provider1, provider2) # when enabled_providers = get_enabled_providers_for_pro() # then assert enabled_providers == [provider2] # clean db.session.delete(provider1) db.session.delete(provider2) db.session.commit()
def test_nOffers_with_one_venue_provider(app): # given provider = Provider() provider.name = 'Open Agenda' provider.localClass = 'OpenAgenda' provider.isActive = True provider.enabledForPro = True PcObject.save(provider) offerer = create_offerer() venue = create_venue(offerer) venue_provider = create_venue_provider(venue, provider) offer_1 = create_offer_with_thing_product(venue, last_provider_id=provider.id, id_at_providers='offer1') offer_2 = create_offer_with_event_product(venue, last_provider_id=provider.id, id_at_providers='offer2') offer_3 = create_offer_with_event_product(venue, last_provider_id=provider.id, id_at_providers='offer3') offer_4 = create_offer_with_thing_product(venue, last_provider_id=provider.id, id_at_providers='offer4') PcObject.save(offer_1, offer_2, offer_3, offer_4, venue_provider) # when n_offers = venue_provider.nOffers # then assert n_offers == 4
def test_raise_errors_if_venue_provider_already_exists(self, app): # given provider = Provider() provider.name = 'Open Agenda' provider.localClass = 'OpenAgenda' provider.isActive = True provider.enabledForPro = True offerer = create_offerer() user = create_user() user_offerer = create_user_offerer(user, offerer, is_admin=True) venue = create_venue(offerer, name='Librairie Titelive', siret='77567146400110') venue_provider = create_venue_provider(venue, provider, venue_id_at_offer_provider="775671464") PcObject.save(provider, user_offerer, venue, venue_provider) payload = { 'providerId': humanize(provider.id), 'venueId': humanize(venue.id), 'venueIdAtOfferProvider': '775671464' } # when with pytest.raises(ApiErrors) as errors: validate_new_venue_provider_information(payload) # then assert errors.value.status_code == 400 assert errors.value.errors['venueProvider'] == ["Votre lieu est déjà lié à cette source"]
def test_returns_true_when_all_information_are_present_and_well_formed(self, app): # given provider = Provider() provider.name = 'Open Agenda' provider.localClass = 'OpenAgenda' provider.isActive = True provider.enabledForPro = True offerer = create_offerer() user = create_user() user_offerer = create_user_offerer(user, offerer, is_admin=True) venue = create_venue(offerer, name='Librairie Titelive', siret='77567146400110') PcObject.save(provider, user_offerer, venue) payload = { 'providerId': humanize(provider.id), 'venueId': humanize(venue.id), 'venueIdAtOfferProvider': '567890' } # when try: validate_new_venue_provider_information(payload) except ApiErrors: # then assert False
def test_nOffers_with_two_venue_providers_from_different_providers(app): # given provider1 = Provider() provider1.name = 'Open Agenda' provider1.localClass = 'OpenAgenda' provider1.isActive = True provider1.enabledForPro = True provider2 = Provider() provider2.name = 'TiteLive' provider2.localClass = 'TiteLive' provider2.isActive = True provider2.enabledForPro = True PcObject.save(provider1, provider2) offerer = create_offerer() venue = create_venue(offerer) venue_provider1 = create_venue_provider(venue, provider1) venue_provider2 = create_venue_provider(venue, provider2) offer_1 = create_offer_with_thing_product(venue, last_provider_id=provider1.id, id_at_providers='offer1') offer_2 = create_offer_with_event_product(venue, last_provider_id=provider2.id, id_at_providers='offer2') offer_3 = create_offer_with_event_product(venue, last_provider_id=provider1.id, id_at_providers='offer3') offer_4 = create_offer_with_thing_product(venue, last_provider_id=provider1.id, id_at_providers='offer4') PcObject.save(offer_1, offer_2, offer_3, offer_4, venue_provider1, venue_provider2) # when n_offers_for_venue_provider1 = venue_provider1.nOffers n_offers_for_venue_provider2 = venue_provider2.nOffers # then assert n_offers_for_venue_provider1 == 3 assert n_offers_for_venue_provider2 == 1
def test_raise_errors_if_provider_is_not_enable_for_pro(self, app): # given provider = Provider() provider.name = 'Open Agenda' provider.localClass = 'OpenAgenda' provider.isActive = True provider.enabledForPro = False PcObject.save(provider) payload = { 'providerId': humanize(provider.id), 'venueId': 'B9', 'venueIdAtOfferProvider': '567890' } # when with pytest.raises(ApiErrors) as errors: validate_new_venue_provider_information(payload) # then assert errors.value.status_code == 400 assert errors.value.errors['provider'] == ["Cette source n'est pas disponible"]
def test_return_venue_provider_when_exists(self, app): # given provider = Provider() provider.name = 'Open Agenda' provider.localClass = 'OpenAgenda' provider.isActive = True provider.enabledForPro = True offerer = create_offerer() user = create_user() user_offerer = create_user_offerer(user, offerer, is_admin=True) venue = create_venue(offerer, name='Librairie Titelive', siret='77567146400110') venue_provider = create_venue_provider( venue, provider, venue_id_at_offer_provider="775671464") PcObject.save(provider, user_offerer, venue, venue_provider) # when existing_venue_provider = find_venue_provider(provider.id, venue.id, "775671464") # then assert existing_venue_provider == venue_provider