def should_connect_venue_to_allocine_provider(self, app): # Given offerer = create_offerer() venue = create_venue(offerer) provider = activate_provider("AllocineStocks") allocine_pivot = create_allocine_pivot(siret=venue.siret) repository.save(venue, allocine_pivot) self.find_by_id.return_value = venue self.get_theaterid_for_venue.return_value = allocine_pivot.theaterId venue_provider_payload = { "providerId": humanize(provider.id), "venueId": humanize(venue.id), "price": "9.99", "isDuo": True, "quantity": 50, } # When connect_venue_to_allocine(venue_provider_payload, self.find_by_id, self.get_theaterid_for_venue) # Then allocine_venue_provider = AllocineVenueProvider.query.one() venue_provider_price_rule = AllocineVenueProviderPriceRule.query.one() assert allocine_venue_provider.venue == venue assert allocine_venue_provider.isDuo assert allocine_venue_provider.quantity == 50 assert venue_provider_price_rule.price == Decimal("9.99")
def when_add_allocine_stocks_provider_with_price_but_no_isDuo_config( self, stubbed_get_theaterid_for_venue, stubbed_find_by_id, app ): # Given offerer = create_offerer(siren="775671464") venue = create_venue(offerer) user = create_user(is_admin=True, is_beneficiary=False) allocine_pivot = create_allocine_pivot(siret=venue.siret) repository.save(venue, user, allocine_pivot) stubbed_find_by_id.return_value = venue stubbed_get_theaterid_for_venue.return_value = allocine_pivot.theaterId provider = activate_provider("AllocineStocks") venue_provider_data = {"providerId": humanize(provider.id), "venueId": humanize(venue.id), "price": "9.99"} auth_request = TestClient(app.test_client()).with_auth(email=user.email) # When response = auth_request.post("/venueProviders", json=venue_provider_data) # Then assert response.status_code == 201 json = response.json assert "_sa_polymorphic_on" not in json venue_provider = VenueProvider.query.one() assert json["venueId"] == humanize(venue_provider.venueId)
def test_should_return_theaterId_when_siret_is_present_in_allocine_pivot(self, app): # Given offerer = create_offerer() venue = create_venue(offerer, siret="12345678912345", comment="En attente de siret") allocine_pivot = create_allocine_pivot(siret="12345678912345", theater_id="XXXXXXXXXXXXXXXXXX==") repository.save(venue, allocine_pivot) # When allocine_theater_id = get_allocine_theaterId_for_venue(venue) # Then assert allocine_theater_id == "XXXXXXXXXXXXXXXXXX=="
def test_should_not_return_value_when_not_matching_in_allocine_pivot(self, app): # Given offerer = create_offerer() venue = create_venue(offerer, siret=None, comment="En attente de siret") allocine_pivot = create_allocine_pivot(siret="12345678912345") repository.save(venue, allocine_pivot) # When allocine_theater_id = get_allocine_theaterId_for_venue(venue) # Then assert allocine_theater_id is None
def test_should_return_false_when_venue_has_no_siret(self, app): # Given offerer = create_offerer() venue = create_venue(offerer, siret=None, comment="En attente de siret") allocine_pivot = create_allocine_pivot(siret="12345678912345") repository.save(venue, allocine_pivot) # When has_allocine_pivot = has_allocine_pivot_for_venue(venue) # Then assert not has_allocine_pivot
def when_venue_does_not_exists(self, app): # Given user = create_user(email="*****@*****.**") offerer = create_offerer() venue = create_venue(offerer) allocine_pivot = create_allocine_pivot() repository.save(user, venue, allocine_pivot) activate_provider("TiteLiveStocks") activate_provider("AllocineStocks") # When response = TestClient(app.test_client()).with_auth( email="*****@*****.**").get("/providers/AZER") # Then assert response.status_code == 404
def when_venue_has_known_allocine_id(self, app): # Given user = create_user(email="*****@*****.**") offerer = create_offerer() venue = create_venue(offerer, siret="12345678912345") allocine_pivot = create_allocine_pivot( siret="12345678912345", theater_id="XXXXXXXXXXXXXXXXXX==") repository.save(user, venue, allocine_pivot) titelive_stocks = activate_provider("TiteLiveStocks") allocine_stocks = activate_provider("AllocineStocks") # When response = (TestClient(app.test_client()).with_auth( email="*****@*****.**").get(f"/providers/{humanize(venue.id)}")) # Then assert response.status_code == 200 response_json = response.json assert response_json == [ { "enabledForPro": True, "id": humanize(allocine_stocks.id), "isActive": True, "localClass": "AllocineStocks", "name": "Allociné", "requireProviderIdentifier": True, }, { "enabledForPro": True, "id": humanize(titelive_stocks.id), "isActive": True, "localClass": "TiteLiveStocks", "name": "TiteLive Stocks (Epagine / Place des libraires.com)", "requireProviderIdentifier": True, }, ]
def should_inject_no_repository_to_the_usecase_when_provider_is_not_concerned( self, mocked_connect_venue_to_allocine, stubbed_find_by_id, stubbed_get_theaterId_for_venue, stubbed_check, app, ): # Given user = create_user(is_admin=True, is_beneficiary=False) offerer = create_offerer() venue = create_venue(offerer, siret="12345678912345") allocine_pivot = create_allocine_pivot(siret=venue.siret) repository.save(venue, user) stubbed_find_by_id.return_value = venue stubbed_get_theaterId_for_venue.return_value = allocine_pivot.theaterId provider = activate_provider("AllocineStocks") venue_provider_data = { "providerId": humanize(provider.id), "venueId": humanize(venue.id), } auth_request = TestClient(app.test_client()).with_auth(email=user.email) stubbed_check.return_value = True # When auth_request.post("/venueProviders", json=venue_provider_data) # Then mocked_connect_venue_to_allocine.assert_called_once_with( {"providerId": humanize(provider.id), "venueId": humanize(venue.id)}, stubbed_find_by_id, stubbed_get_theaterId_for_venue, )