Ejemplo n.º 1
0
def test_create_filter_matching_all_keywords_in_any_models_with_several_partial_keywords_at_event_or_thing_or_venue_or_offerer_level(
        app):
    # given
    ok_event1 = create_product_with_event_type(
        event_name='Rencontre avec Jacques Martin')
    event2 = create_product_with_event_type(
        event_name='Concert de contrebasse')
    thing1 = create_product_with_thing_type(thing_name='Jacques la fripouille')
    thing2 = create_product_with_thing_type(thing_name='Belle du Seigneur')
    offerer = create_offerer()
    venue1 = create_venue(offerer,
                          name='Bataclan',
                          city='Paris',
                          siret=offerer.siren + '12345')
    venue2 = create_venue(offerer,
                          name='Librairie la Rencontre',
                          city='Saint Denis',
                          siret=offerer.siren + '54321')
    ok_offer1 = create_offer_with_event_product(venue1, ok_event1)
    ko_offer2 = create_offer_with_event_product(venue1, event2)
    ok_offer3 = create_offer_with_thing_product(venue2, thing1)
    ko_offer4 = create_offer_with_thing_product(venue2, thing2)
    PcObject.save(ok_offer1, ko_offer2, ok_offer3, ko_offer4)

    # when
    query = filter_offers_with_keywords_string(build_offer_search_base_query(),
                                               'Jacq Rencon')

    # then
    found_offers = query.all()
    found_offers_id = [found_offer.id for found_offer in found_offers]
    assert ok_offer1.id in found_offers_id
    assert ko_offer2.id not in found_offers_id
    assert ok_offer3.id in found_offers_id
    assert ko_offer4.id not in found_offers_id
Ejemplo n.º 2
0
def test_create_filter_matching_all_keywords_in_any_models_with_several_keywords_at_just_event_or_just_thing_level(
        app):
    # given
    ok_event1 = create_product_with_event_type(
        event_name='Rencontre avec Jacques Martin')
    event2 = create_product_with_event_type(
        event_name='Concert de contrebasse')
    ok_thing1 = create_product_with_thing_type(
        thing_name='Rencontre avec vous savez qui',
        description='Il s\'agit de Jacques')
    thing2 = create_product_with_thing_type(
        thing_name='Rencontre avec Belle du Seigneur')
    offerer = create_offerer()
    venue = create_venue(offerer)
    ok_offer1 = create_offer_with_event_product(venue, ok_event1)
    ko_offer2 = create_offer_with_event_product(venue, event2)
    ok_offer3 = create_offer_with_thing_product(venue, ok_thing1)
    ko_offer4 = create_offer_with_thing_product(venue, thing2)
    PcObject.save(ok_offer1, ko_offer2, ok_offer3, ko_offer4)

    # when
    query = filter_offers_with_keywords_string(build_offer_search_base_query(),
                                               'Rencontre Jacques')

    # then
    found_offers = query.all()
    found_offers_id = [found_offer.id for found_offer in found_offers]
    assert ok_offer1.id in found_offers_id
    assert ko_offer2.id not in found_offers_id
    assert ok_offer3.id in found_offers_id
    assert ko_offer4.id not in found_offers_id
Ejemplo n.º 3
0
def test_find_offers_with_filter_parameters_with_partial_keywords_and_filter_by_venue(
        app):
    user = create_user(email='*****@*****.**')
    offerer1 = create_offerer(siren='123456789')
    offerer2 = create_offerer(siren='987654321')
    ko_offerer3 = create_offerer(siren='123456780')
    user_offerer1 = create_user_offerer(user, offerer1)
    user_offerer2 = create_user_offerer(user, offerer2)

    ok_product_event = create_product_with_event_type(
        event_name='Rencontre avec Jacques Martin')
    ok_product_thing = create_product_with_thing_type(
        thing_name='Rencontrez Jacques Chirac')
    event_product2 = create_product_with_event_type(
        event_name='Concert de contrebasse')
    thing1_product = create_product_with_thing_type(
        thing_name='Jacques la fripouille')
    thing2_product = create_product_with_thing_type(
        thing_name='Belle du Seigneur')
    offerer = create_offerer()
    venue1 = create_venue(offerer1,
                          name='Bataclan',
                          city='Paris',
                          siret=offerer.siren + '12345')
    venue2 = create_venue(offerer2,
                          name='Librairie la Rencontre',
                          city='Saint Denis',
                          siret=offerer.siren + '54321')
    ko_venue3 = create_venue(
        ko_offerer3,
        name='Une librairie du méchant concurrent gripsou',
        city='Saint Denis',
        siret=ko_offerer3.siren + '54321')
    ok_offer1 = create_offer_with_event_product(venue1, ok_product_event)
    ok_offer2 = create_offer_with_thing_product(venue1, ok_product_thing)
    ko_offer2 = create_offer_with_event_product(venue1, event_product2)
    ko_offer3 = create_offer_with_thing_product(ko_venue3, thing1_product)
    ko_offer4 = create_offer_with_thing_product(venue2, thing2_product)
    PcObject.save(user_offerer1, user_offerer2, ko_offerer3, ok_offer1,
                  ko_offer2, ko_offer3, ko_offer4)

    # when
    offers = find_offers_with_filter_parameters(
        user, venue_id=venue1.id, keywords_string='Jacq Rencon').all()

    # then
    offers_id = [offer.id for offer in offers]
    assert ok_offer1.id in offers_id
    assert ok_offer2.id in offers_id
    assert ko_offer2.id not in offers_id
    assert ko_offer3.id not in offers_id
    assert ko_offer4.id not in offers_id
Ejemplo n.º 4
0
        def when_offer_type_is_unknown(self, app):
            # Given
            user = create_user(email='*****@*****.**')
            offerer = create_offerer()
            user_offerer = create_user_offerer(user, offerer)
            venue = create_venue(offerer, is_virtual=False)
            event_product = create_product_with_event_type()
            PcObject.save(user, venue, event_product, user_offerer)
            json = {
                'type': '',
                'name': 'Les lapins crétins',
                'mediaUrls': ['http://media.url'],
                'durationMinutes': 200,
                'venueId': humanize(venue.id),
                'bookingEmail': '*****@*****.**'
            }

            # When
            response = TestClient(app.test_client()).with_auth(user.email).post(
                f'{API_URL}/offers',
                json=json)

            # Then
            assert response.status_code == 400
            assert response.json['type'] == ['Le type de cette offre est inconnu']
Ejemplo n.º 5
0
def test_event_offerType_returns_dict_matching_EventType_enum():
    # given
    event_product = create_product_with_event_type(
        event_type=EventType.SPECTACLE_VIVANT)
    expected_value = {
        'conditionalFields':
        ["author", "showType", "stageDirector", "performer"],
        'proLabel':
        "Spectacle vivant",
        'appLabel':
        "Spectacle vivant",
        'offlineOnly':
        True,
        'onlineOnly':
        False,
        'sublabel':
        "Applaudir",
        'description':
        "Suivre un géant de 12 mètres dans la ville ? "
        "Rire aux éclats devant un stand up ?"
        " Rêver le temps d’un opéra ou d’un spectacle de danse ? "
        "Assister à une pièce de théâtre, ou se laisser conter une histoire ?",
        'value':
        'EventType.SPECTACLE_VIVANT',
        'type':
        'Event'
    }

    # when
    offer_type = event_product.offerType

    # then
    assert offer_type == expected_value
Ejemplo n.º 6
0
    def test_search_with_several_partial_keywords_returns_things_and_events_with_name_containing_keywords(
            self, app):
        # Given
        thing_ok = create_product_with_thing_type(
            thing_name='Rencontre de michel')
        thing_product = create_product_with_thing_type(
            thing_name='Rencontre avec jean-luc')
        event_product = create_product_with_event_type(
            event_name='Rencontre avec jean-mimi chelou')
        offerer = create_offerer()
        venue = create_venue(offerer)
        thing_ok_offer = create_offer_with_thing_product(venue, thing_ok)
        thing_ko_offer = create_offer_with_thing_product(venue, thing_product)
        event_ko_offer = create_offer_with_event_product(venue, event_product)
        event_ko_occurrence = create_event_occurrence(event_ko_offer)
        event_ko_stock = create_stock_from_event_occurrence(
            event_ko_occurrence)
        thing_ok_stock = create_stock_from_offer(thing_ok_offer)
        thing_ko_stock = create_stock_from_offer(thing_ko_offer)
        PcObject.save(event_ko_stock, thing_ok_stock, thing_ko_stock)

        # When
        offers = get_offers_for_recommendations_search(
            keywords_string='renc michel')

        # Then
        assert thing_ok_offer in offers
        assert thing_ko_offer not in offers
        assert event_ko_offer not in offers
Ejemplo n.º 7
0
def test_date_range_is_empty_if_event_has_no_stocks():
    # given
    offer = Offer()
    offer.product = create_product_with_event_type()
    offer.stocks = []

    # then
    assert offer.dateRange == DateTimes()
def test_filter_query_where_user_is_user_offerer_and_is_validated(app):
    # Given
    user = create_user(email='*****@*****.**')
    offerer1 = create_offerer(siren='123456789')
    offerer2 = create_offerer(siren='987654321')
    offerer3 = create_offerer(siren='123456780')
    user_offerer1 = create_user_offerer(user, offerer1)
    user_offerer2 = create_user_offerer(user, offerer2)

    event1 = create_product_with_event_type(
        event_name='Rencontre avec Jacques Martin')
    event2 = create_product_with_event_type(
        event_name='Concert de contrebasse')
    thing1 = create_product_with_thing_type(thing_name='Jacques la fripouille')
    thing2 = create_product_with_thing_type(thing_name='Belle du Seigneur')
    venue1 = create_venue(offerer1,
                          name='Bataclan',
                          city='Paris',
                          siret=offerer1.siren + '12345')
    venue2 = create_venue(offerer2,
                          name='Librairie la Rencontre',
                          city='Saint Denis',
                          siret=offerer2.siren + '54321')
    venue3 = create_venue(offerer3,
                          name='Une librairie du méchant concurrent gripsou',
                          city='Saint Denis',
                          siret=offerer3.siren + '54321')
    offer1 = create_offer_with_event_product(venue1, event1)
    offer2 = create_offer_with_event_product(venue1, event2)
    offer3 = create_offer_with_thing_product(venue2, thing1)
    offer4 = create_offer_with_thing_product(venue3, thing2)

    PcObject.save(user_offerer1, user_offerer2, offerer3, offer1, offer2,
                  offer3, offer4)

    # When
    offers = filter_query_where_user_is_user_offerer_and_is_validated(
        Offer.query.join(Venue).join(Offerer), user).all()

    # Then
    offer_ids = [offer.id for offer in offers]
    assert offer1.id in offer_ids
    assert offer2.id in offer_ids
    assert offer3.id in offer_ids
    assert offer4.id not in offer_ids
Ejemplo n.º 9
0
def test_event_offerType_returns_None_if_type_does_not_match_EventType_enum():
    # given
    event_product = create_product_with_event_type(event_type='Workshop')

    # when
    offer_type = event_product.offerType

    # then
    assert offer_type == None
Ejemplo n.º 10
0
def _create_event_stock_and_offer_for_date(venue, date):
    product = create_product_with_event_type()
    offer = create_offer_with_event_product(venue, product)
    event_occurrence = create_event_occurrence(offer,
                                               beginning_datetime=date,
                                               end_datetime=date +
                                               timedelta(hours=1))
    stock = create_stock_from_event_occurrence(event_occurrence,
                                               booking_limit_date=date)
    return stock
Ejemplo n.º 11
0
def test_date_range_matches_the_occurrence_if_only_one_occurrence():
    # given
    offer = Offer()
    offer.product = create_product_with_event_type()
    offer.stocks = [
        create_stock(offer=offer,
                     beginning_datetime=two_days_ago,
                     end_datetime=five_days_from_now)
    ]

    # then
    assert offer.dateRange == DateTimes(two_days_ago, five_days_from_now)
Ejemplo n.º 12
0
    def test_offer_is_marked_as_isthing_property(self):
        # Given
        event_product = create_product_with_event_type(
            event_type=EventType.CINEMA)
        offerer = create_offerer()
        digital_venue = create_venue(offerer, is_virtual=False, siret=None)

        # When
        offer = create_offer_with_thing_product(digital_venue, event_product)

        # Then
        assert offer.isEvent == True
        assert offer.isThing == False
Ejemplo n.º 13
0
def test_create_filter_matching_all_keywords_in_any_models_with_several_partial_keywords_at_mixed_venue_or_offerer_level(
        app):
    # given
    event_product = create_product_with_event_type()
    thing_product = create_product_with_thing_type()
    offerer1 = create_offerer(name="Marxisme et Compagnie")
    offerer2 = create_offerer(name='Test', siren='123456788')
    offerer3 = create_offerer(name='Test', siren='123456787')
    offerer4 = create_offerer(name='Test', siren='123456786')
    ok_venue1 = create_venue(offerer1,
                             name='Librairie Mimosa',
                             siret=offerer1.siren + '54321')
    ko_venue2 = create_venue(offerer2,
                             name='Pif et Hercule',
                             siret=offerer2.siren + '12345')
    ko_venue3 = create_venue(offerer3,
                             name='Librairie la Rencontre',
                             city='Saint Denis',
                             siret=offerer3.siren + '54321')
    ko_venue4 = create_venue(offerer4,
                             name='Bataclan',
                             city='Paris',
                             siret=offerer4.siren + '12345')
    ok_offer1 = create_offer_with_event_product(ok_venue1, event_product)
    ko_offer2 = create_offer_with_event_product(ko_venue2, event_product)
    ok_offer3 = create_offer_with_thing_product(ok_venue1, thing_product)
    ko_offer4 = create_offer_with_thing_product(ko_venue2, thing_product)
    ko_offer5 = create_offer_with_event_product(ko_venue3, event_product)
    ko_offer6 = create_offer_with_event_product(ko_venue4, event_product)
    ko_offer7 = create_offer_with_thing_product(ko_venue3, thing_product)
    ko_offer8 = create_offer_with_thing_product(ko_venue4, thing_product)
    PcObject.save(ok_offer1, ko_offer2, ok_offer3, ko_offer4, ko_offer5,
                  ko_offer6, ko_offer7, ko_offer8)

    # when
    query = filter_offers_with_keywords_string(build_offer_search_base_query(),
                                               'Libra Marx')

    # then
    found_offers = query.all()

    found_offers_id = [found_offer.id for found_offer in found_offers]
    assert ok_offer1.id in found_offers_id
    assert ko_offer2.id not in found_offers_id
    assert ok_offer3.id in found_offers_id
    assert ko_offer4.id not in found_offers_id
    assert ko_offer5.id not in found_offers_id
    assert ko_offer6.id not in found_offers_id
    assert ko_offer7.id not in found_offers_id
    assert ko_offer8.id not in found_offers_id
Ejemplo n.º 14
0
    def test_success_when_is_event_but_durationMinute_is_empty(self, app):
        # Given
        event_product = create_product_with_event_type(duration_minutes=None)
        offerer = create_offerer()
        venue = create_venue(offerer)
        PcObject.save(venue)
        offer = create_offer_with_event_product(venue, event_product)

        # When
        PcObject.save(offer)

        # Then
        assert offer.durationMinutes is None
        assert offer.product.durationMinutes is None
Ejemplo n.º 15
0
    def test_returns_included_properties_on_joined_relationships(self, app):
        # given
        offerer = create_offerer()
        venue = create_venue(offerer)
        event_product = create_product_with_event_type(event_name='My Event')
        offer = create_offer_with_event_product(venue, product=event_product)
        mediation = create_mediation(offer)
        PcObject.save(mediation)
        EVENT_INCLUDES = [{"key": "mediations", "includes": ["thumbUrl"]}]

        # when
        dict_result = as_dict(offer, includes=EVENT_INCLUDES)

        # then
        assert 'thumbUrl' in dict_result['mediations'][0]
Ejemplo n.º 16
0
def test_create_filter_matching_all_keywords_in_any_models_with_several_partial_keywords_at_venue_public_name_level(
        app):
    # given
    event = create_product_with_event_type()
    thing = create_product_with_thing_type()
    ok_offerer1 = create_offerer(name="La Rencontre")
    offerer2 = create_offerer(siren='123456788')
    offerer3 = create_offerer(siren='123456787')
    offerer4 = create_offerer(siren='123456786')
    ok_venue1 = create_venue(ok_offerer1,
                             siret=ok_offerer1.siren + '54321',
                             publicName='Un lieu trop chouette de ouf')
    venue2 = create_venue(offerer2, siret=offerer2.siren + '12345')
    ok_venue3 = create_venue(offerer3,
                             name='Librairie la Rencontre',
                             city='Saint Denis',
                             siret=offerer3.siren + '54321',
                             publicName='chouette endroit de ouf')
    venue4 = create_venue(offerer4,
                          name='Bataclan',
                          city='Paris',
                          siret=offerer4.siren + '12345')
    ok_offer1 = create_offer_with_event_product(ok_venue1, event)
    ko_offer2 = create_offer_with_event_product(venue2, event)
    ok_offer3 = create_offer_with_thing_product(ok_venue1, thing)
    ko_offer4 = create_offer_with_thing_product(venue2, thing)
    ok_offer5 = create_offer_with_event_product(ok_venue3, event)
    ko_offer6 = create_offer_with_event_product(venue4, event)
    ok_offer7 = create_offer_with_thing_product(ok_venue3, thing)
    ko_offer8 = create_offer_with_thing_product(venue4, thing)
    PcObject.save(ok_offer1, ko_offer2, ok_offer3, ko_offer4, ok_offer5,
                  ko_offer6, ok_offer7, ko_offer8)

    # when
    query = filter_offers_with_keywords_string(build_offer_search_base_query(),
                                               'chou ou')

    # then
    found_offers = query.all()
    found_offers_id = [found_offer.id for found_offer in found_offers]
    assert ok_offer1.id in found_offers_id
    assert ko_offer2.id not in found_offers_id
    assert ok_offer3.id in found_offers_id
    assert ko_offer4.id not in found_offers_id
    assert ok_offer5.id in found_offers_id
    assert ko_offer6.id not in found_offers_id
    assert ok_offer7.id in found_offers_id
    assert ko_offer8.id not in found_offers_id
Ejemplo n.º 17
0
def test_get_keywords_analyzer(app):
    # given
    event_name = "Rencontre avec Jacques Nuance"
    product_event = create_product_with_event_type(event_name=event_name)
    offerer_name = "L'atelier du nuage"
    offerer = create_offerer(name=offerer_name)
    venue = create_venue(offerer, name="Le nuage magique")
    offer = create_offer_with_event_product(venue=venue, product=product_event)
    PcObject.save(offer)

    # when
    keywords_analyzer = get_keywords_analyzer(offer, 'nua')

    # then
    assert keywords_analyzer['Product_description'] is False
    assert keywords_analyzer['Product_name'] is False
    assert keywords_analyzer['Offerer_name'] is False
    assert keywords_analyzer['Venue_name'] is False
Ejemplo n.º 18
0
    def test_returns_an_event_if_it_is_given_in_department_list(self, app):
        # given
        product = create_product_with_event_type('Voir une pièce',
                                                 is_national=False)
        offerer = create_offerer()
        venue = create_venue(offerer,
                             is_virtual=False,
                             postal_code='29000',
                             departement_code='29')
        offer = create_offer_with_event_product(venue, product)
        PcObject.save(offer)
        query = Product.query.filter_by(name='Voir une pièce')

        # when
        query = department_or_national_offers(query, ['29'])

        # then
        assert query.count() == 1
Ejemplo n.º 19
0
    def test_returns_national_event_with_different_department(self, app):
        # given
        product = create_product_with_event_type('Voir une pièce',
                                                 is_national=True)
        offerer = create_offerer()
        venue = create_venue(offerer,
                             is_virtual=False,
                             postal_code='29000',
                             departement_code='29')
        offer = create_offer_with_event_product(venue, product)
        PcObject.save(offer)
        query = Product.query.filter_by(name='Voir une pièce')

        # when
        query = department_or_national_offers(query, ['93'])

        # then
        assert product in query.all()
Ejemplo n.º 20
0
        def when_creating_a_new_offer_from_an_existing_event(self, app):
            # given
            user = create_user(email='*****@*****.**')
            offerer = create_offerer()
            user_offerer = create_user_offerer(user, offerer)
            venue = create_venue(offerer)
            event_product = create_product_with_event_type()
            PcObject.save(user_offerer, venue, event_product)

            data = {
                'venueId': humanize(venue.id),
                'productId': humanize(event_product.id)
            }
            auth_request = TestClient(app.test_client()).with_auth(email='*****@*****.**')

            # when
            response = auth_request.post('/offers', json=data)

            # then
            assert response.status_code == 201
Ejemplo n.º 21
0
        def when_user_is_not_attached_to_offerer(self, app):
            # Given
            user = create_user()
            offerer = create_offerer()
            event_product = create_product_with_event_type(
                event_name='Old name')
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(venue, event_product)

            PcObject.save(event_product, offer, user, venue)

            json = {'name': 'New name', 'venueId': humanize(venue.id)}

            # When
            response = TestClient(app.test_client()).with_auth(
                user.email).patch(f'{API_URL}/offers/{humanize(offer.id)}',
                                  json=json)

            # Then
            assert response.status_code == 403
            assert response.json['global'] == [
                "Vous n'avez pas les droits d'accès suffisant pour accéder à cette information."
            ]
Ejemplo n.º 22
0
def test_date_range_starts_at_first_beginning_date_time_and_ends_at_last_end_date_time(
):
    # given
    offer = Offer()
    offer.product = create_product_with_event_type()
    offer.stocks = [
        create_stock(offer=offer,
                     beginning_datetime=two_days_ago,
                     end_datetime=five_days_from_now),
        create_stock(offer=offer,
                     beginning_datetime=four_days_ago,
                     end_datetime=five_days_from_now),
        create_stock(offer=offer,
                     beginning_datetime=four_days_ago,
                     end_datetime=ten_days_from_now),
        create_stock(offer=offer,
                     beginning_datetime=two_days_ago,
                     end_datetime=ten_days_from_now)
    ]

    # then
    assert offer.dateRange == DateTimes(four_days_ago, ten_days_from_now)
    assert offer.dateRange.datetimes == [four_days_ago, ten_days_from_now]
Ejemplo n.º 23
0
    def test_search_by_one_thing_type_returns_only_offers_on_things_of_that_type(
            self, app):
        # Given
        type_label_ok = ThingType.JEUX_VIDEO
        type_label_ko = ThingType.LIVRE_EDITION

        thing_ok1 = create_product_with_thing_type(thing_type=type_label_ok)
        thing_ok2 = create_product_with_thing_type(thing_type=type_label_ok)
        thing_ko = create_product_with_thing_type(thing_type=type_label_ko)
        event_ko = create_product_with_event_type(event_type=EventType.CINEMA)

        offerer = create_offerer()
        venue = create_venue(offerer)

        ok_offer_1 = create_offer_with_thing_product(venue, thing_ok1)
        ok_offer_2 = create_offer_with_thing_product(venue, thing_ok2)
        ko_offer = create_offer_with_thing_product(venue, thing_ko)
        ko_event_offer = create_offer_with_event_product(venue, event_ko)

        ko_event_occurrence = create_event_occurrence(ko_event_offer)

        ok_stock1 = create_stock_from_offer(ok_offer_1)
        ok_stock2 = create_stock_from_offer(ok_offer_2)
        ko_stock1 = create_stock_from_offer(ko_offer)
        ko_stock2 = create_stock_from_event_occurrence(ko_event_occurrence)

        PcObject.save(ok_stock1, ok_stock2, ko_stock1, ko_stock2)

        # When
        offers = get_offers_for_recommendations_search(
            type_values=[str(type_label_ok)], )

        # Then
        assert len(offers) == 2
        assert ok_offer_1 in offers
        assert ok_offer_2 in offers
def test_get_offers_for_recommendations_search_with_distance_less_than_20kms_returns_one_offer_in_venue_with_coordonnates_that_match_with_user_in_Paris(
        app):
    # Given
    offerer75 = create_offerer(
        siren='507633576',
        city='Paris',
        postal_code='75002',
        name='LE GRAND REX PARIS',
        validation_token=None,
    )
    venue75 = create_venue(offerer75,
                           name='LE GRAND REX PARIS',
                           address="1 BD POISSONNIERE",
                           postal_code='75002',
                           city="Paris",
                           departement_code='75',
                           is_virtual=False,
                           longitude="2.4002701",
                           latitude="48.8363788",
                           siret="50763357600075")
    venue77 = create_venue(offerer75,
                           name='Centre Culturel Municipal Jacques Prévert',
                           city="Villeparisis",
                           departement_code='77',
                           is_virtual=False,
                           longitude="2.614391",
                           latitude="48.942623",
                           siret="50763357600077")
    venue78 = create_venue(offerer75,
                           name='CAC Georges Brassens',
                           city="Mantes-la-jolie",
                           departement_code='78',
                           is_virtual=False,
                           longitude="2.713513",
                           latitude="48.985968",
                           siret="50763357600078")
    venue91 = create_venue(offerer75,
                           name='Théâtre de Orsay',
                           city="Orsay",
                           departement_code='91',
                           is_virtual=False,
                           longitude="2.1911928",
                           latitude="48.7034926",
                           siret="50763357600091")
    venue92 = create_venue(offerer75,
                           name='2G – Théâtre de Gennevilliers',
                           city="Gennevilliers",
                           departement_code='92',
                           is_virtual=False,
                           longitude="2.2985554",
                           latitude="48.9143444",
                           siret="50763357600092")
    venue93 = create_venue(offerer75,
                           name='La Salle',
                           city="Aulnay Sous Bois",
                           departement_code='93',
                           is_virtual=False,
                           longitude="2.3458074",
                           latitude="48.9247067",
                           siret="50763357600093")
    venue95 = create_venue(offerer75,
                           name='EMB',
                           city="Sannois",
                           departement_code='95',
                           is_virtual=False,
                           longitude="2.2683263",
                           latitude="48.976826",
                           siret="50763357600095")
    venue94 = create_venue(offerer75,
                           name='Centre Culturel Municipal Jacques Prévert',
                           city="Cachan",
                           departement_code='91',
                           is_virtual=False,
                           longitude="2.3231582",
                           latitude="48.7914281",
                           siret="50763357600094")

    concert_event = create_product_with_event_type('Concert de Gael Faye')

    concert_offer75 = create_offer_with_event_product(venue75, concert_event)
    concert_offer77 = create_offer_with_event_product(venue77, concert_event)
    concert_offer78 = create_offer_with_event_product(venue78, concert_event)
    concert_offer91 = create_offer_with_event_product(venue91, concert_event)
    concert_offer92 = create_offer_with_event_product(venue92, concert_event)
    concert_offer93 = create_offer_with_event_product(venue93, concert_event)
    concert_offer94 = create_offer_with_event_product(venue94, concert_event)
    concert_offer95 = create_offer_with_event_product(venue95, concert_event)

    concert_event_occurrence75 = create_event_occurrence(concert_offer75)
    concert_stock75 = create_stock_from_event_occurrence(
        concert_event_occurrence75)

    concert_event_occurrence77 = create_event_occurrence(concert_offer77)
    concert_stock77 = create_stock_from_event_occurrence(
        concert_event_occurrence77)

    concert_event_occurrence78 = create_event_occurrence(concert_offer78)
    concert_stock78 = create_stock_from_event_occurrence(
        concert_event_occurrence78)

    concert_event_occurrence91 = create_event_occurrence(concert_offer91)
    concert_stock91 = create_stock_from_event_occurrence(
        concert_event_occurrence91)

    concert_event_occurrence92 = create_event_occurrence(concert_offer92)
    concert_stock92 = create_stock_from_event_occurrence(
        concert_event_occurrence92)

    concert_event_occurrence93 = create_event_occurrence(concert_offer93)
    concert_stock93 = create_stock_from_event_occurrence(
        concert_event_occurrence93)

    concert_event_occurrence94 = create_event_occurrence(concert_offer94)
    concert_stock94 = create_stock_from_event_occurrence(
        concert_event_occurrence94)

    concert_event_occurrence95 = create_event_occurrence(concert_offer95)
    concert_stock95 = create_stock_from_event_occurrence(
        concert_event_occurrence95)

    PcObject.save(concert_stock75, concert_stock77, concert_stock78,
                  concert_stock91, concert_stock92, concert_stock93,
                  concert_stock94, concert_stock95)

    # When
    # User in Paris
    offers = get_offers_for_recommendations_search(max_distance=20,
                                                   longitude=2.4002701,
                                                   latitude=48.8363788)

    # Then
    assert concert_offer75 in offers
    assert concert_offer77 in offers
    assert concert_offer78 not in offers
    assert concert_offer91 not in offers
    assert concert_offer92 in offers
    assert concert_offer93 in offers
    assert concert_offer94 in offers
    assert concert_offer95 in offers
def test_get_offers_for_recommendations_search_with_distance_returns_offers_in_virtuals_venues_no_matter_wich_distance_with_user_in_Paris(
        app):
    # Given
    offerer75 = create_offerer(
        siren='507633576',
        city='Paris',
        postal_code='75002',
        name='LE GRAND REX PARIS',
        validation_token=None,
    )
    venue45 = create_venue(offerer75,
                           name='Salle Albert Camus',
                           city="Orléans",
                           departement_code='45',
                           is_virtual=True,
                           longitude="1.9201176",
                           latitude="47.9063667",
                           siret=None)
    venue13 = create_venue(offerer75,
                           name='Friche La Belle de Mai',
                           city="Marseille",
                           departement_code='13',
                           is_virtual=True,
                           longitude="5.3764073",
                           latitude="43.303906",
                           siret=None)
    venue973 = create_venue(offerer75,
                            name='Théâtre de Macouria',
                            city="Cayenne",
                            departement_code='973',
                            is_virtual=True,
                            longitude="-52.423277",
                            latitude="4.9780178",
                            siret=None)

    concert_event = create_product_with_event_type('Concert de Gael Faye')

    concert_offer13 = create_offer_with_event_product(venue13, concert_event)
    concert_offer45 = create_offer_with_event_product(venue45, concert_event)
    concert_offer973 = create_offer_with_event_product(venue973, concert_event)

    concert_event_occurrence13 = create_event_occurrence(concert_offer13)
    concert_stock13 = create_stock_from_event_occurrence(
        concert_event_occurrence13)

    concert_event_occurrence45 = create_event_occurrence(concert_offer45)
    concert_stock45 = create_stock_from_event_occurrence(
        concert_event_occurrence45)

    concert_event_occurrence973 = create_event_occurrence(concert_offer973)
    concert_stock973 = create_stock_from_event_occurrence(
        concert_event_occurrence973)

    PcObject.save(concert_stock13, concert_stock45, concert_stock973)

    # When
    # User in Paris
    offers = get_offers_for_recommendations_search(max_distance=1,
                                                   longitude=2.4002701,
                                                   latitude=48.8363788)

    # Then
    assert concert_offer45 not in offers
    assert concert_offer13 not in offers
    assert concert_offer973 not in offers
Ejemplo n.º 26
0
def create_industrial_event_products():
    logger.info('create_industrial_event_products')

    event_products_by_name = {}

    event_type_dicts = [
        t
        for t in get_formatted_event_or_thing_types(with_activation_type=True)
        if t['type'] == 'Event'
    ]

    activation_index = 0

    for type_index in range(0, EVENT_COUNTS_PER_TYPE):

        for (event_type_dict_index,
             event_type_dict) in enumerate(event_type_dicts):

            mock_index = (type_index + event_type_dict_index) % len(MOCK_NAMES)
            if event_type_dict['value'] == str(EventType.ACTIVATION):
                event_name = '{} {}'.format(MOCK_ACTIVATION_NAME,
                                            activation_index)
                description = MOCK_ACTIVATION_DESCRIPTION
                activation_index += 1
            else:
                event_name = MOCK_NAMES[mock_index]
                description = MOCK_DESCRIPTIONS[mock_index]

            event_type = event_type_dict['value']

            name = "{} / {}".format(event_type_dict['value'], event_name)
            event_product = create_product_with_event_type(
                description=description,
                duration_minutes=60,
                event_name=event_name,
                event_type=event_type,
                thumb_count=0)

            extraData = {}
            extra_data_index = 0
            for conditionalField in event_product.offerType[
                    'conditionalFields']:
                conditional_index = type_index + event_type_dict_index + extra_data_index
                if conditionalField in [
                        'author', 'performer', 'speaker', 'stageDirector'
                ]:
                    mock_first_name_index = conditional_index % len(
                        MOCK_FIRST_NAMES)
                    mock_first_name = MOCK_FIRST_NAMES[mock_first_name_index]
                    mock_last_name_index = conditional_index % len(
                        MOCK_LAST_NAMES)
                    mock_last_name = MOCK_LAST_NAMES[mock_last_name_index]
                    mock_name = '{} {}'.format(mock_first_name, mock_last_name)
                    extraData[conditionalField] = mock_name
                elif conditionalField == "musicType":
                    music_type_index = conditional_index % len(music_types)
                    music_type = music_types[music_type_index]
                    extraData[conditionalField] = str(music_type['code'])
                    music_sub_type_index = conditional_index % len(
                        music_type['children'])
                    music_sub_type = music_type['children'][
                        music_sub_type_index]
                    extraData["musicSubType"] = str(music_sub_type['code'])
                elif conditionalField == "showType":
                    show_type_index = conditional_index % len(show_types)
                    show_type = show_types[show_type_index]
                    extraData[conditionalField] = str(show_type['code'])
                    show_sub_type_index = conditional_index % len(
                        show_type['children'])
                    show_sub_type = show_type['children'][show_sub_type_index]
                    extraData["showSubType"] = str(show_sub_type['code'])
                elif conditionalField == "visa":
                    pass
                extra_data_index += 1
            event_product.extraData = extraData

            event_products_by_name[name] = event_product

        type_index += len(event_type_dicts)

    PcObject.save(*event_products_by_name.values())

    logger.info('created {} event products'.format(
        len(event_products_by_name)))

    return event_products_by_name
def test_get_offers_for_recommendations_search_with_all_distance_and_keywords(
        app):
    # Given
    offerer75 = create_offerer(
        siren='507633576',
        city='Paris',
        postal_code='75002',
        name='LE GRAND REX PARIS',
        validation_token=None,
    )
    venue45 = create_venue(offerer75,
                           name='Salle Albert Camus',
                           city="Orléans",
                           departement_code='45',
                           is_virtual=False,
                           longitude="1.9201176",
                           latitude="47.9063667",
                           siret="50763357600045")
    venue75 = create_venue(offerer75,
                           name='LE GRAND REX PARIS',
                           address="1 BD POISSONNIERE",
                           postal_code='75002',
                           city="Paris",
                           departement_code='75',
                           is_virtual=False,
                           longitude="2.4002701",
                           latitude="48.8363788",
                           siret="50763357600075")
    venue78 = create_venue(offerer75,
                           name='CAC Georges Brassens',
                           city="Mantes-la-jolie",
                           departement_code='78',
                           is_virtual=False,
                           longitude="2.713513",
                           latitude="48.985968",
                           siret="50763357600078")
    venue91 = create_venue(offerer75,
                           name='Théâtre de Orsay',
                           city="Orsay",
                           departement_code='91',
                           is_virtual=False,
                           longitude="2.1911928",
                           latitude="48.7034926",
                           siret="50763357600091")

    concert_event = create_product_with_event_type('Concert de Gael Faye')
    concert_event2 = create_product_with_event_type('Kiwi')

    concert_offer45 = create_offer_with_event_product(venue45, concert_event)
    kiwi_concert_offer75 = create_offer_with_event_product(
        venue75, concert_event2)
    concert_offer78 = create_offer_with_event_product(venue78, concert_event)
    concert_offer91 = create_offer_with_event_product(venue91, concert_event)

    concert_event_occurrence45 = create_event_occurrence(concert_offer45)
    concert_stock45 = create_stock_from_event_occurrence(
        concert_event_occurrence45)

    kiwi_concert_event_occurrence75 = create_event_occurrence(
        kiwi_concert_offer75)
    kiwi_concert_stock75 = create_stock_from_event_occurrence(
        kiwi_concert_event_occurrence75)

    concert_event_occurrence78 = create_event_occurrence(concert_offer78)
    concert_stock78 = create_stock_from_event_occurrence(
        concert_event_occurrence78)

    concert_event_occurrence91 = create_event_occurrence(concert_offer91)
    concert_stock91 = create_stock_from_event_occurrence(
        concert_event_occurrence91)

    PcObject.save(concert_stock45, kiwi_concert_stock75, concert_stock78,
                  concert_offer91)

    # When
    # User in Paris
    offers = get_offers_for_recommendations_search(max_distance=20000,
                                                   longitude=2.4002701,
                                                   latitude=48.8363788,
                                                   keywords_string='Kiwi')

    # Then
    assert concert_offer45 not in offers
    assert kiwi_concert_offer75 in offers
    assert concert_offer78 not in offers
    assert concert_offer91 not in offers
def test_get_offers_for_recommendations_search_with_all_distances_should_returns_all_offers(
        app):
    # Given
    offerer75 = create_offerer(
        siren='507633576',
        city='Paris',
        postal_code='75002',
        name='LE GRAND REX PARIS',
        validation_token=None,
    )
    venue13 = create_venue(offerer75,
                           name='Friche La Belle de Mai',
                           city="Marseille",
                           departement_code='13',
                           is_virtual=False,
                           longitude="5.3764073",
                           latitude="43.303906",
                           siret="50763357600013")
    venue75 = create_venue(offerer75,
                           name='LE GRAND REX PARIS',
                           address="1 BD POISSONNIERE",
                           postal_code='75002',
                           city="Paris",
                           departement_code='75',
                           is_virtual=False,
                           longitude="2.4002701",
                           latitude="48.8363788",
                           siret="50763357600075")
    venue78 = create_venue(offerer75,
                           name='CAC Georges Brassens',
                           city="Mantes-la-jolie",
                           departement_code='78',
                           is_virtual=False,
                           longitude="2.713513",
                           latitude="48.985968",
                           siret="50763357600078")
    venue92 = create_venue(offerer75,
                           name='2G – Théâtre de Gennevilliers',
                           city="Gennevilliers",
                           departement_code='92',
                           is_virtual=False,
                           longitude="2.2985554",
                           latitude="48.9143444",
                           siret="50763357600092")
    venue77 = create_venue(offerer75,
                           name='Centre Culturel Municipal Jacques Prévert',
                           city="Villeparisis",
                           departement_code='77',
                           is_virtual=False,
                           longitude="2.614391",
                           latitude="48.942623",
                           siret="50763357600077")
    venue91 = create_venue(offerer75,
                           name='Théâtre de Longjumeau',
                           city="Longjumeau",
                           departement_code='91',
                           is_virtual=False,
                           longitude="2.2881266",
                           latitude="48.6922895",
                           siret="50763357600091")
    venue93 = create_venue(offerer75,
                           name='La Salle',
                           city="Aulnay Sous Bois",
                           departement_code='93',
                           is_virtual=False,
                           longitude="2.3458074",
                           latitude="48.9247067",
                           siret="50763357600093")
    venue94 = create_venue(offerer75,
                           name='Centre Culturel Municipal Jacques Prévert',
                           city="Cachan",
                           departement_code='91',
                           is_virtual=False,
                           longitude="2.3231582",
                           latitude="48.7914281",
                           siret="50763357600094")
    venue95 = create_venue(offerer75,
                           name='EMB',
                           city="Sannois",
                           departement_code='95',
                           is_virtual=False,
                           longitude="2.2683263",
                           latitude="48.976826",
                           siret="50763357600095")
    venue973 = create_venue(offerer75,
                            name='Théâtre de Macouria',
                            city="Cayenne",
                            departement_code='973',
                            is_virtual=False,
                            longitude="-52.423277",
                            latitude="4.9780178",
                            siret="50763357600973")

    concert_event = create_product_with_event_type('Concert de Gael Faye')

    concert_offer13 = create_offer_with_event_product(venue13, concert_event)
    concert_offer75 = create_offer_with_event_product(venue75, concert_event)
    concert_offer77 = create_offer_with_event_product(venue77, concert_event)
    concert_offer78 = create_offer_with_event_product(venue78, concert_event)
    concert_offer91 = create_offer_with_event_product(venue91, concert_event)
    concert_offer92 = create_offer_with_event_product(venue92, concert_event)
    concert_offer93 = create_offer_with_event_product(venue93, concert_event)
    concert_offer94 = create_offer_with_event_product(venue94, concert_event)
    concert_offer95 = create_offer_with_event_product(venue95, concert_event)
    concert_offer973 = create_offer_with_event_product(venue973, concert_event)

    concert_event_occurrence13 = create_event_occurrence(concert_offer13)
    concert_stock13 = create_stock_from_event_occurrence(
        concert_event_occurrence13)

    concert_event_occurrence91 = create_event_occurrence(concert_offer91)
    concert_stock91 = create_stock_from_event_occurrence(
        concert_event_occurrence91)

    concert_event_occurrence93 = create_event_occurrence(concert_offer93)
    concert_stock93 = create_stock_from_event_occurrence(
        concert_event_occurrence93)

    concert_event_occurrence94 = create_event_occurrence(concert_offer94)
    concert_stock94 = create_stock_from_event_occurrence(
        concert_event_occurrence94)

    concert_event_occurrence95 = create_event_occurrence(concert_offer95)
    concert_stock95 = create_stock_from_event_occurrence(
        concert_event_occurrence95)

    concert_event_occurrence973 = create_event_occurrence(concert_offer973)
    concert_stock973 = create_stock_from_event_occurrence(
        concert_event_occurrence973)

    PcObject.save(concert_stock13, concert_stock95, concert_stock91,
                  concert_stock93, concert_stock94, concert_stock973)

    # When
    # User in Mantes-la-jolie
    offers = get_offers_for_recommendations_search(max_distance=20000,
                                                   longitude=2.713513,
                                                   latitude=48.985968)

    # Then
    assert concert_offer13 in offers
    assert concert_offer91 in offers
    assert concert_offer93 in offers
    assert concert_offer94 in offers
    assert concert_offer95 in offers
    assert concert_offer973 in offers
Ejemplo n.º 29
0
    def test_search_by_one_event_type_returns_only_offers_on_events_of_that_type(
            self, app):
        # Given
        type_label = EventType.CONFERENCE_DEBAT_DEDICACE
        other_type_label = EventType.MUSIQUE

        conference_event1 = create_product_with_event_type(
            'Rencontre avec Franck Lepage', event_type=type_label)
        conference_event2 = create_product_with_event_type(
            'Conférence ouverte', event_type=type_label)
        concert_event = create_product_with_event_type(
            'Concert de Gael Faye', event_type=other_type_label)

        offerer = create_offerer(
            siren='507633576',
            address='1 BD POISSONNIERE',
            city='Paris',
            postal_code='75002',
            name='LE GRAND REX PARIS',
            validation_token=None,
        )
        venue = create_venue(offerer,
                             name='LE GRAND REX PARIS',
                             address="1 BD POISSONNIERE",
                             postal_code='75002',
                             city="Paris",
                             departement_code='75',
                             is_virtual=False,
                             longitude="2.4002701",
                             latitude="48.8363788",
                             siret="50763357600016")

        conference_offer1 = create_offer_with_event_product(
            venue, conference_event1)
        conference_offer2 = create_offer_with_event_product(
            venue, conference_event2)
        concert_offer = create_offer_with_event_product(venue, concert_event)

        conference_event_occurrence1 = create_event_occurrence(
            conference_offer1)
        conference_event_occurrence2 = create_event_occurrence(
            conference_offer2)
        concert_event_occurrence = create_event_occurrence(concert_offer)

        conference_stock1 = create_stock_from_event_occurrence(
            conference_event_occurrence1)
        conference_stock2 = create_stock_from_event_occurrence(
            conference_event_occurrence2)
        concert_stock = create_stock_from_event_occurrence(
            concert_event_occurrence)

        PcObject.save(conference_stock1, conference_stock2, concert_stock)

        # When
        offers = get_offers_for_recommendations_search(
            type_values=[str(type_label)], )

        # Then
        assert conference_offer1 in offers
        assert conference_offer2 in offers
        assert concert_offer not in offers
def test_get_offers_for_recommendations_search_with_distance_less_than_1km_returns_one_offer_in_venue_with_coordonnates_that_match(
        app):
    # Given
    offerer75 = create_offerer(
        siren='507633576',
        city='Paris',
        postal_code='75002',
        name='LE GRAND REX PARIS',
        validation_token=None,
    )
    venue75 = create_venue(offerer75,
                           name='LE GRAND REX PARIS',
                           address="1 BD POISSONNIERE",
                           postal_code='75002',
                           city="Paris",
                           departement_code='75',
                           is_virtual=False,
                           longitude="2.4002701",
                           latitude="48.8363788",
                           siret="50763357600075")
    venue77 = create_venue(offerer75,
                           name='Centre Culturel Municipal Jacques Prévert',
                           city="Villeparisis",
                           departement_code='77',
                           is_virtual=False,
                           longitude="2.614391",
                           latitude="48.942623",
                           siret="50763357600077")
    venue78 = create_venue(offerer75,
                           name='CAC Georges Brassens',
                           city="Mantes-la-jolie",
                           departement_code='78',
                           is_virtual=False,
                           longitude="2.713513",
                           latitude="48.985968",
                           siret="50763357600078")
    venue92 = create_venue(offerer75,
                           name='2G – Théâtre de Gennevilliers',
                           city="Gennevilliers",
                           departement_code='92',
                           is_virtual=False,
                           longitude="2.2985554",
                           latitude="48.9143444",
                           siret="50763357600092")

    concert_event = create_product_with_event_type('Concert de Gael Faye')

    concert_offer75 = create_offer_with_event_product(venue75, concert_event)
    concert_offer78 = create_offer_with_event_product(venue78, concert_event)
    concert_offer77 = create_offer_with_event_product(venue77, concert_event)
    concert_offer92 = create_offer_with_event_product(venue92, concert_event)

    concert_event_occurrence75 = create_event_occurrence(concert_offer75)
    concert_stock75 = create_stock_from_event_occurrence(
        concert_event_occurrence75)

    concert_event_occurrence77 = create_event_occurrence(concert_offer77)
    concert_stock77 = create_stock_from_event_occurrence(
        concert_event_occurrence77)

    concert_event_occurrence78 = create_event_occurrence(concert_offer78)
    concert_stock78 = create_stock_from_event_occurrence(
        concert_event_occurrence78)

    concert_event_occurrence92 = create_event_occurrence(concert_offer92)
    concert_stock92 = create_stock_from_event_occurrence(
        concert_event_occurrence92)

    PcObject.save(concert_stock75, concert_stock77, concert_stock78,
                  concert_stock92)

    # When
    # User in Mantes-la-jolie
    offers = get_offers_for_recommendations_search(max_distance=1,
                                                   longitude=2.713513,
                                                   latitude=48.985968)

    # Then
    assert concert_offer75 not in offers
    assert concert_offer77 not in offers
    assert concert_offer78 in offers
    assert concert_offer92 not in offers