def test_should_call_sync_venue_provider_until_reaching_max_pool_size( self, mock_get_nb_containers_at_work, mock_do_sync_venue_provider, mock_sleep, app): # Given mock_get_nb_containers_at_work.side_effect = [0, 1, 0] titelive_provider = activate_provider("TiteLiveStocks") offerer = create_offerer() venue1 = create_venue(offerer) venue2 = create_venue(offerer, siret="12345678912356") venue_provider_titelive1 = create_venue_provider( venue1, titelive_provider) venue_provider_titelive2 = create_venue_provider( venue2, titelive_provider) repository.save(venue_provider_titelive1, venue_provider_titelive2) expected_wait_time = 60 # When update_venues_for_specific_provider(titelive_provider.id) # Then mock_sleep.assert_called_once_with(expected_wait_time) assert mock_get_nb_containers_at_work.call_count == 3 assert mock_do_sync_venue_provider.call_count == 2 assert call(venue_provider_titelive1 ) in mock_do_sync_venue_provider.call_args_list assert call(venue_provider_titelive2 ) in mock_do_sync_venue_provider.call_args_list
def test_nOffers_with_two_venue_providers_from_different_providers(app): # given provider1 = create_provider(local_class="OpenAgenda") provider2 = create_provider(local_class="TiteLive") repository.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", last_provider=provider1 ) offer_2 = create_offer_with_event_product( venue, last_provider_id=provider2.id, id_at_providers="offer2", last_provider=provider2 ) offer_3 = create_offer_with_event_product( venue, last_provider_id=provider1.id, id_at_providers="offer3", last_provider=provider1 ) offer_4 = create_offer_with_thing_product( venue, last_provider_id=provider1.id, id_at_providers="offer4", last_provider=provider1 ) repository.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_should_return_number_of_venue_provider_with_worker_id(self, app): # Given offerer = create_offerer() venue_1 = create_venue(offerer, siret="12345678901234") venue_2 = create_venue(offerer) titelive_provider = activate_provider("TiteLiveStocks") venue_provider_1 = create_venue_provider(venue_1, titelive_provider) venue_provider_2 = create_venue_provider(venue_2, titelive_provider, sync_worker_id="1234567") repository.save(venue_provider_1, venue_provider_2) # When nb_containers_at_work = get_nb_containers_at_work() # Then assert nb_containers_at_work == 1
def test_should_return_only_venue_provider_for_specified_provider(self, app): # Given offerer = create_offerer() venue = create_venue(offerer) titelive_provider = activate_provider("TiteLiveStocks") allocine_provider = activate_provider("AllocineStocks") venue_provider_titelive = create_venue_provider(venue, titelive_provider) venue_provider_allocine = create_venue_provider(venue, allocine_provider) repository.save(venue_provider_titelive, venue_provider_allocine) # When venue_providers = get_venue_providers_to_sync(titelive_provider.id) # Then assert venue_providers == [venue_provider_titelive]
def test_should_return_all_active_venue_providers_matching_provider_id(self, app): # Given offerer = create_offerer() venue1 = create_venue(offerer, siret="12345678901234") venue2 = create_venue(offerer) titelive_provider = activate_provider("TiteLiveStocks") venue_provider1 = create_venue_provider(venue1, titelive_provider) venue_provider2 = create_venue_provider(venue2, titelive_provider, is_active=False) repository.save(venue_provider1, venue_provider2) # When venue_providers = get_active_venue_providers_for_specific_provider(titelive_provider.id) # Then assert venue_providers == [venue_provider1]
def test_raise_errors_if_venue_provider_already_exists_with_same_information(app): # given provider = APIProviderFactory() offerer = create_offerer() venue = create_venue(offerer, name="Librairie Titelive", siret="77567146400110") venue_provider = create_venue_provider(venue, provider, venue_id_at_offer_provider="775671464") repository.save(venue_provider) venue_provider2 = create_venue_provider(venue, provider, venue_id_at_offer_provider="775671464") # when with pytest.raises(ApiErrors) as errors: repository.save(venue_provider2) # then assert errors.value.errors["global"] == ["Votre lieu est déjà lié à cette source"]
def test_titelive_stock_provider_skips_stock_update_when_price_is_null(self, stub_get_stocks_information, app): # Given stub_get_stocks_information.return_value = iter( [{"ref": "0002730757438", "available": 10, "price": None, "validUntil": "2019-10-31T15:10:27Z"}] ) offerer = create_offerer() venue = create_venue(offerer, siret="77567146400110") titelive_stocks_provider = activate_provider("TiteLiveStocks") venue_provider = create_venue_provider( venue, titelive_stocks_provider, is_active=True, venue_id_at_offer_provider="77567146400110" ) product = create_product_with_thing_type(id_at_providers="0002730757438") offer = create_offer_with_thing_product( venue, product=product, id_at_providers="0002730757438@77567146400110" ) stock = create_stock(id_at_providers="0002730757438@77567146400110", offer=offer, quantity=10, price=12.34) repository.save(product, venue_provider, stock) titelive_stocks = TiteLiveStocks(venue_provider) # When titelive_stocks.updateObjects() # Then stock = Stock.query.one() assert stock.quantity == 10 assert stock.price == Decimal("12.34") assert Offer.query.count() == 1
def test_fnac_stock_provider_update_one_stock_and_update_matching_offer(self, mock_fnac_api_response, app): # Given mock_fnac_api_response.return_value = iter([{"ref": "9780199536986", "available": 10, "price": 16}]) offerer = create_offerer() venue = create_venue(offerer) fnac_stocks_provider = activate_provider("FnacStocks") venue_provider = create_venue_provider( venue, fnac_stocks_provider, is_active=True, venue_id_at_offer_provider="12345678912345" ) product = create_product_with_thing_type(id_at_providers="9780199536986") offer = create_offer_with_thing_product( venue, product=product, id_at_providers="9780199536986@12345678912345" ) stock = create_stock(id_at_providers="9780199536986@12345678912345", offer=offer, quantity=20) repository.save(product, offer, stock) fnac_stocks = FnacStocks(venue_provider) # When fnac_stocks.updateObjects() # Then stock = Stock.query.one() assert stock.quantity == 10 assert Offer.query.count() == 1
def test_query_venue_provider_load_allocine_venue_provider_attributes_when_connected_to_allocine( self, app): offerer = create_offerer() venue = create_venue(offerer) provider_allocine = activate_provider("AllocineStocks") provider = create_provider(local_class="TestLocalProvider") venue_provider = create_venue_provider(venue, provider) allocine_venue_provider = create_allocine_venue_provider( venue, provider_allocine, is_duo=True) repository.save(venue_provider, allocine_venue_provider) assert VenueProvider.query.count() == 2 assert AllocineVenueProvider.query.count() == 1 created_venue_provider = VenueProvider.query.filter( VenueProvider.providerId == provider.id).first() assert isinstance(created_venue_provider, VenueProvider) created_allocine_venue_provider = VenueProvider.query.filter( VenueProvider.providerId == provider_allocine.id).first() assert isinstance(created_allocine_venue_provider, AllocineVenueProvider)
def test_should_return_providable_infos_with_correct_data(self, mock_titelive_api_response, app): # Given mock_titelive_api_response.return_value = iter( [{"ref": "0002730757438", "available": 10, "price": 4500, "validUntil": "2019-10-31T15:10:27Z"}] ) offerer = create_offerer() venue = create_venue(offerer, siret="12345678912345") titelive_provider = activate_provider("TiteLiveStocks") venue_provider = create_venue_provider( venue, titelive_provider, venue_id_at_offer_provider=venue.siret, last_sync_date=datetime(2020, 2, 4) ) product = create_product_with_thing_type(id_at_providers="0002730757438") repository.save(product, venue_provider) titelive_stocks = TiteLiveStocks(venue_provider) # When titelive_providable_infos = next(titelive_stocks) # Then assert mock_titelive_api_response.call_args_list == [call("12345678912345", "", datetime(2020, 2, 4))] assert len(titelive_providable_infos) == 2 offer_providable_info = titelive_providable_infos[0] stock_providable_info = titelive_providable_infos[1] assert offer_providable_info.type == Offer assert offer_providable_info.id_at_providers == "0002730757438@12345678912345" assert stock_providable_info.type == Stock assert stock_providable_info.id_at_providers == "0002730757438@12345678912345"
def test_fnac_stocks_create_2_stocks_and_2_offers_even_if_existing_offer_on_same_product( self, mock_fnac_api_response, app ): # Given mock_fnac_api_response.return_value = iter( [ {"ref": "9780199536986", "available": 5, "price": 16}, {"ref": "1550199555555", "available": 4, "price": 18}, ] ) offerer = create_offerer() venue = create_venue(offerer, siret="12345678912345") fnac_stocks_provider = activate_provider("FnacStocks") venue_provider = create_venue_provider( venue, fnac_stocks_provider, is_active=True, venue_id_at_offer_provider="12345678912345" ) product_1 = create_product_with_thing_type(id_at_providers="9780199536986") product_2 = create_product_with_thing_type(id_at_providers="1550199555555") offer = create_offer_with_thing_product(venue, product=product_2, id_at_providers="everything_but_fnac_id") repository.save(offer, product_1, product_2, venue_provider) fnac_stocks = FnacStocks(venue_provider) # When fnac_stocks.updateObjects() # Then assert Stock.query.count() == 2 assert Offer.query.filter_by(lastProviderId=fnac_stocks_provider.id).count() == 2 assert fnac_stocks.last_processed_isbn == "1550199555555"
def when_listing_all_venues_with_a_valid_venue_id(self, app): # given offerer = create_offerer(siren="775671464") venue = create_venue(offerer, name="Librairie Titelive", siret="77567146400110") titelive_things_provider = get_provider_by_local_class( "TiteLiveThings") venue_provider = create_venue_provider( venue=venue, provider=titelive_things_provider) repository.save(venue_provider) user = create_user() repository.save(user) auth_request = TestClient( app.test_client()).with_auth(email=user.email) # when response = auth_request.get("/venueProviders?venueId=" + humanize(venue.id)) # then assert response.status_code == 200 assert response.json[0].get("id") == humanize(venue_provider.id) assert response.json[0].get("venueId") == humanize(venue.id)
def test_fnac_stock_provider_available_stock_is_sum_of_updated_available_and_bookings( self, mock_fnac_api_response, app ): # Given mock_fnac_api_response.return_value = iter([{"ref": "9780199536986", "available": 5, "price": 0}]) offerer = create_offerer() venue = create_venue(offerer, siret="12345678912345") fnac_stocks_provider = activate_provider("FnacStocks") venue_provider = create_venue_provider( venue, fnac_stocks_provider, is_active=True, venue_id_at_offer_provider="12345678912345" ) product = create_product_with_thing_type(id_at_providers="9780199536986") offer = create_offer_with_thing_product( venue, product=product, id_at_providers="9780199536986@12345678912345" ) stock = create_stock(id_at_providers="9780199536986@12345678912345", offer=offer, price=0, quantity=20) booking = create_booking(user=create_user(), quantity=1, stock=stock) repository.save(venue_provider, booking) mock_fnac_api_response.return_value = iter([{"ref": "9780199536986", "available": 66, "price": 0}]) fnac_stocks = FnacStocks(venue_provider) # When fnac_stocks.updateObjects() # Then stock = Stock.query.one() assert stock.quantity == 67
def test_titelive_stock_provider_create_1_stock_and_update_1_existing_offer( self, stub_get_stocks_information, app ): # Given stub_get_stocks_information.return_value = iter( [{"ref": "0002730757438", "available": 10, "price": 4500, "validUntil": "2019-10-31T15:10:27Z"}] ) offerer = create_offerer() venue = create_venue(offerer, siret="77567146400110") titelive_stocks_provider = activate_provider("TiteLiveStocks") venue_provider = create_venue_provider( venue, titelive_stocks_provider, is_active=True, venue_id_at_offer_provider="77567146400110" ) product = create_product_with_thing_type(id_at_providers="0002730757438") offer = create_offer_with_thing_product( venue, product=product, id_at_providers="0002730757438@77567146400110" ) repository.save(product, venue_provider, offer) titelive_stocks = TiteLiveStocks(venue_provider) # When titelive_stocks.updateObjects() # Then assert Stock.query.count() == 1 assert Offer.query.count() == 1
def test_should_return_providable_infos_with_correct_data(self, mock_fnac_api_response, app): # Given mock_fnac_api_response.return_value = iter([{"ref": "9780199536986", "available": 1, "price": 6.36}]) offerer = create_offerer() venue = create_venue(offerer, siret="12345678912345") fnac_provider = activate_provider("FnacStocks") venue_provider = create_venue_provider( venue, fnac_provider, venue_id_at_offer_provider=venue.siret, last_sync_date=datetime(2020, 2, 4) ) product = create_product_with_thing_type(id_at_providers="9780199536986") repository.save(venue_provider, product) fnac_stocks_provider = FnacStocks(venue_provider) # When fnac_providable_infos = next(fnac_stocks_provider) # Then assert mock_fnac_api_response.call_args_list == [call("12345678912345", "", datetime(2020, 2, 4))] assert len(fnac_providable_infos) == 2 offer_providable_info = fnac_providable_infos[0] stock_providable_info = fnac_providable_infos[1] assert offer_providable_info.type == Offer assert offer_providable_info.id_at_providers == "9780199536986@12345678912345" assert stock_providable_info.type == Stock assert stock_providable_info.id_at_providers == "9780199536986@12345678912345"
def test_titelive_stock_provider_create_1_stock_and_1_offer_with_wanted_attributes( self, stub_get_stocks_information, app ): # Given stub_get_stocks_information.return_value = iter( [{"ref": "0002730757438", "available": 10, "price": 4500, "validUntil": "2019-10-31T15:10:27Z"}] ) offerer = create_offerer() venue = create_venue(offerer, siret="12345678912345") titelive_provider = activate_provider("TiteLiveStocks") venue_provider = create_venue_provider( venue, titelive_provider, venue_id_at_offer_provider=venue.siret, last_sync_date=datetime(2020, 2, 4) ) product = create_product_with_thing_type(id_at_providers="0002730757438") repository.save(product, venue_provider) titelive_stocks = TiteLiveStocks(venue_provider) # When titelive_stocks.updateObjects() # Then offer = Offer.query.first() stock = Stock.query.first() assert offer.type == product.type assert offer.description == product.description assert offer.venue is not None assert offer.bookingEmail == venue.bookingEmail assert offer.extraData == product.extraData assert stock.price == 45.00 assert stock.quantity == 10 assert stock.bookingLimitDatetime is None
def test_fnac_stock_provider_create_one_stock_and_one_offer_with_wanted_attributes( self, mock_fnac_api_response, app ): # Given mock_fnac_api_response.return_value = iter([{"ref": "9780199536986", "available": 10, "price": 16.5}]) offerer = create_offerer() venue = create_venue(offerer, siret="77567146400110") fnac_stocks_provider = activate_provider("FnacStocks") venue_provider = create_venue_provider( venue, fnac_stocks_provider, is_active=True, venue_id_at_offer_provider="77567146400110" ) product = create_product_with_thing_type(id_at_providers="9780199536986") repository.save(product, venue_provider) fnac_stocks = FnacStocks(venue_provider) # When fnac_stocks.updateObjects() # Then offer = Offer.query.first() stock = Stock.query.first() assert offer.type == product.type assert offer.description == product.description assert offer.venue is not None assert offer.bookingEmail == venue.bookingEmail assert offer.extraData == product.extraData assert stock.price == 16.5 assert stock.quantity == 10 assert stock.bookingLimitDatetime is None
def should_call_api_with_venue_siret_and_last_sync_date(self, stub_get_stocks_information, app): # Given stub_get_stocks_information.side_effect = [ iter([{"ref": "0002730757438", "available": 0, "price": 4500, "validUntil": "2019-10-31T15:10:27Z"}]) ] offerer = create_offerer() venue = create_venue(offerer, siret="77567146400110") titelive_stocks_provider = activate_provider("TiteLiveStocks") last_sync_date = datetime.strptime("27/08/2020 09:15:32", "%d/%m/%Y %H:%M:%S") venue_provider = create_venue_provider( venue, titelive_stocks_provider, is_active=True, venue_id_at_offer_provider="77567146400110", last_sync_date=last_sync_date, ) product = create_product_with_thing_type(id_at_providers="0002730757438") repository.save(product, venue_provider) titelive_stocks = TiteLiveStocks(venue_provider) # When titelive_stocks.updateObjects() # Then assert stub_get_stocks_information.call_args_list == [ call("77567146400110", "", last_sync_date), call("77567146400110", "0002730757438", last_sync_date), ]
def test_titelive_stock_provider_iterates_over_pagination(self, stub_get_stocks_information, app): # Given stub_get_stocks_information.side_effect = [ iter([{"ref": "0002730757438", "available": 0, "price": 4500, "validUntil": "2019-10-31T15:10:27Z"}]), iter([{"ref": "0002736409898", "available": 2, "price": 100, "validUntil": "2019-10-31T15:10:27Z"}]), ] offerer = create_offerer() venue = create_venue(offerer, siret="77567146400110") titelive_stocks_provider = activate_provider("TiteLiveStocks") venue_provider = create_venue_provider( venue, titelive_stocks_provider, is_active=True, venue_id_at_offer_provider="77567146400110" ) product1 = create_product_with_thing_type(id_at_providers="0002730757438") product2 = create_product_with_thing_type(id_at_providers="0002736409898") repository.save(product1, product2, venue_provider) titelive_stocks = TiteLiveStocks(venue_provider) # When titelive_stocks.updateObjects() # Then assert Offer.query.count() == 2 assert Stock.query.count() == 2 assert stub_get_stocks_information.call_args_list == [ call("77567146400110", "", None), call("77567146400110", "0002730757438", None), call("77567146400110", "0002736409898", None), ]
def test_titelive_stock_provider_create_nothing_if_titelive_api_returns_no_results( self, stub_get_stocks_information, app ): # Given stub_get_stocks_information.return_value = iter([]) offerer = create_offerer() venue = create_venue(offerer, siret="77567146400110") titelive_stocks_provider = activate_provider("TiteLiveStocks") venue_provider = create_venue_provider( venue, titelive_stocks_provider, is_active=True, venue_id_at_offer_provider="77567146400110" ) product = create_product_with_thing_type(id_at_providers="0002730757438") offer = create_offer_with_thing_product(venue, product=product) repository.save(product, venue_provider, offer) titelive_stocks = TiteLiveStocks(venue_provider) # When titelive_stocks.updateObjects() # Then assert Offer.query.filter_by(lastProviderId=titelive_stocks_provider.id).count() == 0 assert Stock.query.count() == 0
def test_titelive_stock_provider_create_2_stocks_and_2_offers_even_if_existing_offer_on_same_product( self, mock_stocks_information, app ): # Given mock_stocks_information.return_value = iter( [ {"ref": "0002730757438", "available": 10, "price": 4500, "validUntil": "2019-10-31T15:10:27Z"}, {"ref": "0002736409898", "available": 2, "price": 100, "validUntil": "2019-10-31T15:10:27Z"}, ] ) offerer = create_offerer() venue = create_venue(offerer, siret="77567146400110") titelive_stocks_provider = activate_provider("TiteLiveStocks") venue_provider = create_venue_provider( venue, titelive_stocks_provider, is_active=True, venue_id_at_offer_provider="77567146400110" ) product1 = create_product_with_thing_type(id_at_providers="0002730757438") product2 = create_product_with_thing_type(id_at_providers="0002736409898") offer = create_offer_with_thing_product(venue, product=product1, id_at_providers="not_titelive") repository.save(product1, product2, venue_provider, offer) titelive_stocks = TiteLiveStocks(venue_provider) # When titelive_stocks.updateObjects() # Then assert Offer.query.filter_by(lastProviderId=titelive_stocks_provider.id).count() == 2 assert Stock.query.count() == 2
def test_nOffers_with_one_venue_provider(app): # given provider = create_provider() repository.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", last_provider=provider) offer_2 = create_offer_with_event_product(venue, last_provider_id=provider.id, id_at_providers="offer2", last_provider=provider) offer_3 = create_offer_with_event_product(venue, last_provider_id=provider.id, id_at_providers="offer3", last_provider=provider) offer_4 = create_offer_with_thing_product(venue, last_provider_id=provider.id, id_at_providers="offer4", last_provider=provider) repository.save(offer_1, offer_2, offer_3, offer_4, venue_provider) # when n_offers = venue_provider.nOffers # then assert n_offers == 4
def test_when_add_same_provider(self, mock_siret_can_be_synchronized, mock_synchronize_venue_provider, app): # Given user = user_factories.AdminFactory() venue = offer_factories.VenueFactory(siret="12345678912345") provider = offerers_factories.APIProviderFactory() venue_provider = create_venue_provider( venue, provider, venue_id_at_offer_provider="12345678912345") repository.save(venue_provider) auth_request = TestClient( app.test_client()).with_session_auth(email=user.email) venue_provider_data = { "providerId": humanize(provider.id), "venueId": humanize(venue.id), } mock_siret_can_be_synchronized.return_value = True # When response = auth_request.post("/venueProviders", json=venue_provider_data) # Then assert response.status_code == 400 assert response.json == { "global": ["Votre lieu est déjà lié à cette source"] } assert venue.venueProviders[0].provider.id == provider.id
def test_should_return_venue_provider_with_no_worker_id(self, app): # Given offerer = create_offerer() venue_1 = create_venue(offerer, siret="12345678901234") venue_2 = create_venue(offerer) titelive_provider = activate_provider("TiteLiveStocks") venue_provider_1 = create_venue_provider(venue_1, titelive_provider, last_sync_date=None, sync_worker_id=None) venue_provider_2 = create_venue_provider( venue_2, titelive_provider, last_sync_date=None, sync_worker_id="123456789098765432345634" ) repository.save(venue_provider_1, venue_provider_2) # When venue_providers = get_venue_providers_to_sync(titelive_provider.id) # Then assert venue_providers == [venue_provider_1]
def save_allocine_sandbox() -> None: sirene = Sirene() create_industrial_admin_users() user = create_user( first_name="Didier", last_name="Champion", public_name="Didier Champion", email="*****@*****.**", is_beneficiary=False, ) offerer = create_offerer( address="145, rue Chaplin", city="Paris 17", name="Le Royal - Cinéma d'essai", postal_code="75017", siren=sirene.siren, ) user_offerer = create_user_offerer( offerer=offerer, user=user, ) venue = create_venue( offerer, address=offerer.address, booking_email="*****@*****.**", city=offerer.city, comment="Salle de cinéma", name=offerer.name + " - Salle 1", postal_code=offerer.postalCode, siret=sirene.siret, ) activate_provider("AllocineStocks") provider = get_provider_by_local_class("AllocineStocks") venue_provider = create_venue_provider(venue, provider=provider, is_active=True) repository.save(user, offerer, user_offerer, venue, provider, venue_provider) offer = create_offer_with_event_product( venue, event_type=EventType.CINEMA, last_provider_id=provider.id, id_at_providers="TW92aWU6MjQ4MTAy%34007977100028-VF", last_provider=provider, ) repository.save(offer)
def test_titelive_stock_provider_available_stock_is_sum_of_updated_available_and_bookings( self, stub_get_stocks_information, app ): # Given stub_get_stocks_information.side_effect = [ iter( [ { "ref": "9780199536986", "available": 5, "price": 0, } ] ) ] offerer = create_offerer() venue = create_venue(offerer, siret="12345678912345") titelive_stocks_provider = activate_provider("TiteLiveStocks") venue_provider = create_venue_provider( venue, titelive_stocks_provider, is_active=True, venue_id_at_offer_provider="12345678912345" ) product = create_product_with_thing_type(id_at_providers="9780199536986") offer = create_offer_with_thing_product( venue, product=product, id_at_providers="9780199536986@12345678912345" ) stock = create_stock(id_at_providers="9780199536986@12345678912345", offer=offer, price=0, quantity=20) booking = create_booking(user=create_user(), quantity=1, stock=stock) repository.save(venue_provider, booking) stub_get_stocks_information.side_effect = [ iter( [ { "ref": "9780199536986", "available": 66, "price": 0, } ] ) ] titelive_stocks = TiteLiveStocks(venue_provider) # When titelive_stocks.updateObjects() # Then stock = Stock.query.one() assert stock.quantity == 67
def test_should_have_attribute_matching_allocine_when_having_allocine_provider(app): # given provider = activate_provider("AllocineStocks") offerer = create_offerer() venue = create_venue(offerer) venue_provider = create_venue_provider(venue, provider) repository.save(venue_provider) # when allocine_venue_provider = VenueProvider.query.first() # then assert allocine_venue_provider.isFromAllocineProvider
def test_should_call_sync_venue_provider_for_expected_venue_provider( self, mock_do_sync_venue_provider, app): # Given titelive_provider = activate_provider("TiteLiveStocks") offerer = create_offerer() venue1 = create_venue(offerer) venue2 = create_venue(offerer, siret="12345678912356") venue_provider_titelive1 = create_venue_provider( venue1, titelive_provider) venue_provider_titelive2 = create_venue_provider( venue2, titelive_provider) repository.save(venue_provider_titelive1, venue_provider_titelive2) # When update_venues_for_specific_provider(titelive_provider.id) # Then assert mock_do_sync_venue_provider.call_count == 2 assert call(venue_provider_titelive1 ) in mock_do_sync_venue_provider.call_args_list assert call(venue_provider_titelive2 ) in mock_do_sync_venue_provider.call_args_list
def test_should_not_be_matched_has_allocine_provider_with_other_provider(app): # given provider = activate_provider("TiteLiveStocks") offerer = create_offerer() venue = create_venue(offerer) venue_provider = create_venue_provider(venue, provider) repository.save(venue_provider) # when allocine_venue_provider = VenueProvider.query.first() # then assert not allocine_venue_provider.isFromAllocineProvider
def test_should_call_synchronize_venue_provider( self, mock_synchronize_venue_provider, app): # Given provider_test = create_provider(local_class="TestLocalProvider") offerer = create_offerer() venue = create_venue(offerer) venue_provider = create_venue_provider(venue, provider_test) repository.save(venue_provider) # When synchronize_venue_providers_for_provider(provider_test.id, 10) # Then mock_synchronize_venue_provider.assert_called_once()