Example #1
0
    def test_get_enabled_providers_for_pro(self, app):
        # given
        provider1 = Provider()
        provider1.name = 'Open Agenda'
        provider1.localClass = 'OpenAgenda'
        provider1.isActive = False
        provider1.enabledForPro = False

        provider2 = Provider()
        provider2.name = 'Tite Live'
        provider2.localClass = 'TiteLive'
        provider2.isActive = True
        provider2.enabledForPro = True
        PcObject.save(provider1, provider2)

        # when
        enabled_providers = get_enabled_providers_for_pro()

        # then
        assert enabled_providers == [provider2]

        # clean
        db.session.delete(provider1)
        db.session.delete(provider2)
        db.session.commit()
def test_nOffers_with_one_venue_provider(app):
    # given
    provider = Provider()
    provider.name = 'Open Agenda'
    provider.localClass = 'OpenAgenda'
    provider.isActive = True
    provider.enabledForPro = True
    PcObject.save(provider)

    offerer = create_offerer()
    venue = create_venue(offerer)
    venue_provider = create_venue_provider(venue, provider)
    offer_1 = create_offer_with_thing_product(venue,
                                              last_provider_id=provider.id,
                                              id_at_providers='offer1')
    offer_2 = create_offer_with_event_product(venue,
                                              last_provider_id=provider.id,
                                              id_at_providers='offer2')
    offer_3 = create_offer_with_event_product(venue,
                                              last_provider_id=provider.id,
                                              id_at_providers='offer3')
    offer_4 = create_offer_with_thing_product(venue,
                                              last_provider_id=provider.id,
                                              id_at_providers='offer4')
    PcObject.save(offer_1, offer_2, offer_3, offer_4, venue_provider)

    # when
    n_offers = venue_provider.nOffers

    # then
    assert n_offers == 4
Example #3
0
    def test_raise_errors_if_venue_provider_already_exists(self, app):
        # given
        provider = Provider()
        provider.name = 'Open Agenda'
        provider.localClass = 'OpenAgenda'
        provider.isActive = True
        provider.enabledForPro = True
        offerer = create_offerer()
        user = create_user()
        user_offerer = create_user_offerer(user, offerer, is_admin=True)
        venue = create_venue(offerer, name='Librairie Titelive', siret='77567146400110')
        venue_provider = create_venue_provider(venue, provider, venue_id_at_offer_provider="775671464")
        PcObject.save(provider, user_offerer, venue, venue_provider)

        payload = {
            'providerId': humanize(provider.id),
            'venueId': humanize(venue.id),
            'venueIdAtOfferProvider': '775671464'
        }

        # when
        with pytest.raises(ApiErrors) as errors:
            validate_new_venue_provider_information(payload)

        # then
        assert errors.value.status_code == 400
        assert errors.value.errors['venueProvider'] == ["Votre lieu est déjà lié à cette source"]
Example #4
0
    def test_returns_true_when_all_information_are_present_and_well_formed(self, app):
        # given
        provider = Provider()
        provider.name = 'Open Agenda'
        provider.localClass = 'OpenAgenda'
        provider.isActive = True
        provider.enabledForPro = True
        offerer = create_offerer()
        user = create_user()
        user_offerer = create_user_offerer(user, offerer, is_admin=True)
        venue = create_venue(offerer, name='Librairie Titelive', siret='77567146400110')
        PcObject.save(provider, user_offerer, venue)

        payload = {
            'providerId': humanize(provider.id),
            'venueId': humanize(venue.id),
            'venueIdAtOfferProvider': '567890'
        }

        # when
        try:
            validate_new_venue_provider_information(payload)
        except ApiErrors:
            # then
            assert False
Example #5
0
    def setUp(self):

       u = get_user_model()()
       u.id = 1
       u.username = '******'
       u.first_name = 'test'
       u.last_name = 'test'
       u.email = 'test'
       u.set_password('test') 
       u.save()

       p = Provider()
       p.id = 1
       p.user = u
       p.name = "test"  
       p.email = "*****@*****.**" 
       p.phone = 12312312
       p.currency = "USD"
       p.language = "DE"
       p.save()

       u = get_user_model()()
       u.id = 2
       u.username = '******'
       u.first_name = 'test2'
       u.last_name = 'test2'
       u.email = '*****@*****.**'
       u.set_password('test') 
       u.save()

       p = Provider()
       p.id = 2
       p.user = u
       p.name = "test2"  
       p.email = "*****@*****.**" 
       p.phone = 123123212
       p.currency = "USD"
       p.language = "EN"
       p.save()

       self.url = reverse("provider:provider-detail",kwargs={"pk":1})
def test_nOffers_with_two_venue_providers_from_different_providers(app):
    # given
    provider1 = Provider()
    provider1.name = 'Open Agenda'
    provider1.localClass = 'OpenAgenda'
    provider1.isActive = True
    provider1.enabledForPro = True
    provider2 = Provider()
    provider2.name = 'TiteLive'
    provider2.localClass = 'TiteLive'
    provider2.isActive = True
    provider2.enabledForPro = True
    PcObject.save(provider1, provider2)

    offerer = create_offerer()
    venue = create_venue(offerer)
    venue_provider1 = create_venue_provider(venue, provider1)
    venue_provider2 = create_venue_provider(venue, provider2)
    offer_1 = create_offer_with_thing_product(venue,
                                              last_provider_id=provider1.id,
                                              id_at_providers='offer1')
    offer_2 = create_offer_with_event_product(venue,
                                              last_provider_id=provider2.id,
                                              id_at_providers='offer2')
    offer_3 = create_offer_with_event_product(venue,
                                              last_provider_id=provider1.id,
                                              id_at_providers='offer3')
    offer_4 = create_offer_with_thing_product(venue,
                                              last_provider_id=provider1.id,
                                              id_at_providers='offer4')
    PcObject.save(offer_1, offer_2, offer_3, offer_4, venue_provider1,
                  venue_provider2)

    # when
    n_offers_for_venue_provider1 = venue_provider1.nOffers
    n_offers_for_venue_provider2 = venue_provider2.nOffers

    # then
    assert n_offers_for_venue_provider1 == 3
    assert n_offers_for_venue_provider2 == 1
Example #7
0
def service_provider(request, id= ''):
    """
        endpoint: /provider/<id>/
        method: GET
        response: Service provider object stored in Database
        method: Post
        body: Json (name,email,phone,currency)
        response: 201, Newly created Service provider object
        method: Put
        body: Json (name,email,phone,currency)
        response: 200, Updated Service Provider Object
        method: Delete
        response: 204, No content
        ________________________________________________________________________________________
        endpoint: /provider/all
        method: GET
        response: Array of all service provider objects
    """
    try:
        if request.method == "POST":
            data = json.loads(request.body)
            provider = Provider(name=data['name'], email=data['email'], phone=data['phone'],
                                currency=data['currency'],service_area=[])
            provider.save()
            return json_response(provider.to_json(), 201)
        if request.method == "GET":
            if id is None or id == '':
                providers= Provider.objects.all()
                return json_response(providers.to_json(), 200)
            else:
                provider = Provider.objects.get(pk=id)
                return json_response(provider.to_json(), 200)
        provider = Provider.objects.get(pk=id)
        if request.method == "PUT":
            data = json.loads(request.body)
            provider.name = data['name']
            provider.email = data['email']
            provider.phone = data['phone']
            provider.currency = data['currency']
            provider.save()
            return json_response(provider.to_json(), 200)
        if request.method == "DELETE":
            provider.delete()
            return json_response('',204)
    except Exception as e:
        response = error_handler(e)
        return response
Example #8
0
    def test_raise_errors_if_provider_is_not_enable_for_pro(self, app):
        # given
        provider = Provider()
        provider.name = 'Open Agenda'
        provider.localClass = 'OpenAgenda'
        provider.isActive = True
        provider.enabledForPro = False
        PcObject.save(provider)

        payload = {
            'providerId': humanize(provider.id),
            'venueId': 'B9',
            'venueIdAtOfferProvider': '567890'
        }

        # when
        with pytest.raises(ApiErrors) as errors:
            validate_new_venue_provider_information(payload)

        # then
        assert errors.value.status_code == 400
        assert errors.value.errors['provider'] == ["Cette source n'est pas disponible"]
    def test_return_venue_provider_when_exists(self, app):
        # given
        provider = Provider()
        provider.name = 'Open Agenda'
        provider.localClass = 'OpenAgenda'
        provider.isActive = True
        provider.enabledForPro = True
        offerer = create_offerer()
        user = create_user()
        user_offerer = create_user_offerer(user, offerer, is_admin=True)
        venue = create_venue(offerer,
                             name='Librairie Titelive',
                             siret='77567146400110')
        venue_provider = create_venue_provider(
            venue, provider, venue_id_at_offer_provider="775671464")
        PcObject.save(provider, user_offerer, venue, venue_provider)

        # when
        existing_venue_provider = find_venue_provider(provider.id, venue.id,
                                                      "775671464")

        # then
        assert existing_venue_provider == venue_provider