def should_not_unscramble_unproperly_formatted_ids(self): # When with pytest.raises(NonProperlyFormattedScrambledId) as exception: Identifier.from_scrambled_id("#4%^&") # Then assert str(exception.value) == 'Scrambled identifier "#4%^&===" is not properly formatted'
def should_be_equals_if_identifier_is_equal(self): # Given identifier_value = 84 # When equality = Identifier(identifier_value) == Identifier(identifier_value) # Then assert equality is True
def should_be_equal_to_original_identifier_when_initialized_from_scrambled_identifier(self): # Given identifier = Identifier(42) # When scrambled_identifier = identifier.scrambled # Then identifier_from_scrambled = Identifier.from_scrambled_id(scrambled_identifier) assert identifier == identifier_from_scrambled
def should_be_a_strictly_positive_number(self): # When with pytest.raises(NonStricltyPositiveIdentifierException) as exception: Identifier(-1) # Then assert str(exception.value) == "Identifier should be a strictly positive number"
def should_return_venues_filtered_by_offerer_id_when_provided( self, app: object): # given pro_user = create_user() wanted_offerer = create_offerer(idx=1) unwanted_offerer = create_offerer(idx=2, siren="5654367") create_user_offerer(user=pro_user, offerer=wanted_offerer) create_user_offerer(user=pro_user, offerer=unwanted_offerer) venue_from_wanted_offerer = create_venue( name="Kléber", offerer=wanted_offerer, siret="12345678912345", public_name="Librairie Kléber") venue_from_unwanted_offerer = create_venue(name="QG FNAC", offerer=unwanted_offerer, siret="98765432198765") repository.save(venue_from_wanted_offerer, venue_from_unwanted_offerer) # when found_venues = self.venue_sql_repository.get_by_pro_identifier( pro_user.id, False, Identifier(1)) # then assert len(found_venues) == 1 assert found_venues[0].name == venue_from_wanted_offerer.name
def should_not_be_equal_with_another_object(self): # When identifier = Identifier(42) # Then assert identifier != 42 assert identifier != "42" assert identifier != {"identifier": 42}
def should_return_pagination_details(): # given offer_id = 1 stock_id = 2 venue_id = 3 offerer_id = 4 stock = { "identifier": Identifier(stock_id), "is_event_expired": False, "remaining_quantity": 10 } offer = OfferRecap( identifier=Identifier(offer_id), has_booking_limit_datetimes_passed=False, is_active=True, is_editable=True, is_event=False, is_thing=True, name="Test Book", thumb_url="/thumb/url", offer_type="ThingType.AUDIOVISUEL", venue_identifier=Identifier(venue_id), venue_is_virtual=False, venue_managing_offerer_id=offerer_id, venue_name="La petite librairie", venue_public_name="Petite librairie", venue_offerer_name="Gérant de petites librairies", venue_departement_code=None, stocks=[stock], ) current_page = 1 total_pages = 2 total_offers = 3 paginated_offers_recap = PaginatedOffersRecap(offers_recap=[offer], current_page=current_page, total_pages=total_pages, total_offers=total_offers) # when result = serialize_offers_recap_paginated(paginated_offers_recap) # then assert result["page"] == current_page assert result["page_count"] == total_pages assert result["total_count"] == total_offers
def should_be_given_identifier(self): # Given expected_identifier = 42 # When persisted_identifier = Identifier(expected_identifier).persisted # Then assert persisted_identifier == expected_identifier
def get_venues(): offerer_identifier = Identifier.from_scrambled_id( request.args.get("offererId")) venues = get_all_venues_by_pro_user.execute( pro_identifier=current_user.id, user_is_admin=current_user.isAdmin, offerer_id=offerer_identifier) return jsonify(serialize_venues_with_offerer_name(venues)), 200
def should_scramble_identifier(self): # Given persisted_identifier = 42 identifier = Identifier(persisted_identifier) # When scrambled_identifier = identifier.scrambled # Then assert scrambled_identifier != persisted_identifier
def _offer_recap_to_domain(offer: Offer) -> OfferRecap: stocks = [_stock_serializer(stock_entity) for stock_entity in offer.activeStocks] return OfferRecap( identifier=Identifier(offer.id), has_booking_limit_datetimes_passed=offer.hasBookingLimitDatetimesPassed, is_active=offer.isActive, is_editable=offer.isEditable, is_event=offer.isEvent, is_thing=offer.isThing, name=offer.name, thumb_url=offer.thumbUrl, offer_type=offer.type, venue_identifier=Identifier(offer.venue.id), venue_is_virtual=offer.venue.isVirtual, venue_managing_offerer_id=offer.venue.managingOffererId, venue_name=offer.venue.name, venue_offerer_name=offer.venue.managingOfferer.name, venue_public_name=offer.venue.publicName, venue_departement_code=offer.venue.departementCode, stocks=stocks, )
def __init__( self, identifier: Identifier, is_virtual: bool, managing_offerer_id: int, name: str, public_name: str, offerer_name: str, venue_departement_code: Optional[str], ): self.identifier = identifier self.is_virtual = is_virtual self.managing_offerer_id = Identifier(managing_offerer_id) self.name = name self.offerer_name = offerer_name self.public_name = public_name self.departement_code = venue_departement_code
def should_not_be_equals_if_identifiers_are_differents(self): # When identifier = Identifier(42) # Then assert identifier != Identifier(84)
def should_return_serialized_offers_with_relevant_informations(): # given offer_id = 1 stock_id = 2 venue_id = 3 offerer_id = 4 stock = { "identifier": Identifier(stock_id), "is_event_expired": False, "remaining_quantity": 10 } departement_code = 12 offer = OfferRecap( identifier=Identifier(offer_id), has_booking_limit_datetimes_passed=False, is_active=True, is_editable=True, is_event=False, is_thing=True, name="Test Book", thumb_url="/thumb/url", offer_type="ThingType.AUDIOVISUEL", venue_identifier=Identifier(venue_id), venue_is_virtual=False, venue_managing_offerer_id=offerer_id, venue_name="La petite librairie", venue_public_name="Petite librairie", venue_offerer_name="Gérant de petites librairies", venue_departement_code=departement_code, stocks=[stock], ) paginated_offers_recap = PaginatedOffersRecap(offers_recap=[offer], current_page=1, total_pages=2, total_offers=3) # when result = serialize_offers_recap_paginated(paginated_offers_recap) # then expected_serialized_offer = [{ "hasBookingLimitDatetimesPassed": False, "id": offer.identifier.scrambled, "isActive": True, "isEditable": True, "isEvent": False, "isThing": True, "name": "Test Book", "stocks": [{ "id": offer.stocks[0].identifier.scrambled, "offerId": offer.identifier.scrambled, "remainingQuantity": 10, }], "thumbUrl": "/thumb/url", "type": "ThingType.AUDIOVISUEL", "venue": { "id": offer.venue.identifier.scrambled, "isVirtual": False, "departementCode": departement_code, "managingOffererId": offer.venue.managing_offerer_id.scrambled, "name": "La petite librairie", "offererName": "Gérant de petites librairies", "publicName": "Petite librairie", }, "venueId": offer.venue.identifier.scrambled, }] assert result["offers"] == expected_serialized_offer
def should_be_unique_for_a_given_persisted_identifier(self): # When scrambled_identifier = Identifier(42).scrambled # Then assert scrambled_identifier != Identifier(43).scrambled
def should_be_a_mix_of_uppercase_letters_and_digits(self): # When scrambled_identifier = Identifier(12452).scrambled # Then assert re.match("[A-Z0-9]*", scrambled_identifier)
def should_not_initialize_id_when_given_scrambled_id_is_none(self): # When identifier = Identifier.from_scrambled_id(None) # Then assert identifier is None
def _stock_serializer(stock: Stock) -> Dict: return {"identifier": Identifier(stock.id), "remaining_quantity": stock.remainingQuantity}