コード例 #1
0
def test_only_suspend_pro_users_in_given_emails_providers_list():
    # Given
    fraudulent_emails_providers = ["example.com"]
    admin_user = AdminFactory(email="*****@*****.**")
    pro_fraudulent_user_with_uppercase_domain = ProFactory(
        email="*****@*****.**")
    pro_fraudulent_user_with_subdomain = ProFactory(
        email="*****@*****.**")
    beneficiary_fraudulent_user = BeneficiaryGrant18Factory(
        email="*****@*****.**")
    offerer1 = OffererFactory()
    UserOffererFactory(user=pro_fraudulent_user_with_uppercase_domain,
                       offerer=offerer1)
    offerer2 = OffererFactory()
    UserOffererFactory(user=pro_fraudulent_user_with_subdomain,
                       offerer=offerer2)

    # When
    suspend_fraudulent_pro_by_email_providers(fraudulent_emails_providers,
                                              admin_user,
                                              dry_run=False)

    # Then
    assert not pro_fraudulent_user_with_uppercase_domain.isActive

    # Do not handle sub-domains
    assert pro_fraudulent_user_with_subdomain.isActive
    assert beneficiary_fraudulent_user.isActive
コード例 #2
0
    def when_user_is_a_pro(self, app):
        # Given
        pro = ProFactory(email="*****@*****.**",
                         postalCode=None,
                         dateOfBirth=None)
        pro.suspensionReason = None
        repository.save(pro)

        # When
        response = TestClient(app.test_client()).with_session_auth(
            "*****@*****.**").get("/beneficiaries/current")

        # Then
        assert response.status_code == 200
        assert response.json["suspensionReason"] == None
コード例 #3
0
    def expect_the_current_user_to_have_access_to_new_offerer(
            self, mock_api_entreprise, app):
        # Given
        mock_api_entreprise.return_value = MagicMock(
            status_code=200,
            text="",
            json=MagicMock(
                return_value=copy.deepcopy(api_entreprise_json_mock)))

        pro = ProFactory()
        VirtualVenueTypeFactory()
        body = {
            "name": "Test Offerer",
            "siren": "418166096",
            "address": "123 rue de Paris",
            "postalCode": "93100",
            "city": "Montreuil",
        }

        # when
        response = TestClient(app.test_client()).with_session_auth(
            pro.email).post("/offerers", json=body)

        # then
        assert response.status_code == 201
        offerer = Offerer.query.first()
        assert offerer.UserOfferers[0].user == pro
コード例 #4
0
def test_cancel_bookings_when_offerer_has_one_or_more():
    # Given
    fraudulent_emails_providers = ["example.com"]
    admin_user = AdminFactory(email="*****@*****.**")
    beneficiary1 = BeneficiaryGrant18Factory(email="*****@*****.**")
    beneficiary2 = BeneficiaryGrant18Factory(email="*****@*****.**")
    fraudulent_user = ProFactory(email="*****@*****.**", )
    offerer_with_bookings = OffererFactory()
    UserOffererFactory(user=fraudulent_user, offerer=offerer_with_bookings)
    offer1 = OfferFactory(venue__managingOfferer=offerer_with_bookings)
    offer2 = OfferFactory(venue__managingOfferer=offerer_with_bookings)
    stock1 = StockFactory(offer=offer1)
    stock2 = StockFactory(offer=offer2)
    booking1 = BookingFactory(user=beneficiary1, stock=stock1)
    booking2 = BookingFactory(user=beneficiary2, stock=stock2)

    # When
    suspend_fraudulent_pro_by_email_providers(fraudulent_emails_providers,
                                              admin_user,
                                              dry_run=False)

    # Then
    assert Offerer.query.count() == 1
    assert Venue.query.count() == 2
    assert Offer.query.count() == 2
    assert Stock.query.count() == 2
    assert Booking.query.count() == 2
    assert booking1.isCancelled
    assert booking1.status is BookingStatus.CANCELLED
    assert booking1.cancellationReason is BookingCancellationReasons.FRAUD
    assert booking2.isCancelled
    assert booking2.status is BookingStatus.CANCELLED
    assert booking2.cancellationReason is BookingCancellationReasons.FRAUD
コード例 #5
0
    def when_no_address_is_provided(self, mock_api_entreprise, app):
        # given
        mock_api_entreprise.return_value = MagicMock(
            status_code=200,
            text="",
            json=MagicMock(
                return_value=copy.deepcopy(api_entreprise_json_mock)))

        pro = ProFactory()
        VirtualVenueTypeFactory()
        body = {
            "name": "Test Offerer",
            "siren": "418166096",
            "postalCode": "93100",
            "city": "Montreuil"
        }

        # when
        response = TestClient(app.test_client()).with_session_auth(
            pro.email).post("/offerers", json=body)

        # then
        assert response.status_code == 201
        assert response.json["siren"] == "418166096"
        assert response.json["name"] == "Test Offerer"
コード例 #6
0
    def when_creating_a_virtual_venue(self, mock_api_entreprise, app):
        # given
        mock_api_entreprise.return_value = MagicMock(
            status_code=200,
            text="",
            json=MagicMock(
                return_value=copy.deepcopy(api_entreprise_json_mock)))

        pro = ProFactory()
        digital_venue_type = VirtualVenueTypeFactory()
        body = {
            "name": "Test Offerer",
            "siren": "418166096",
            "address": "123 rue de Paris",
            "postalCode": "93100",
            "city": "Montreuil",
        }

        # when
        response = TestClient(app.test_client()).with_session_auth(
            pro.email).post("/offerers", json=body)

        # then
        assert response.status_code == 201
        assert response.json["siren"] == "418166096"
        assert response.json["name"] == "Test Offerer"
        virtual_venues = list(
            filter(lambda v: v["isVirtual"], response.json["managedVenues"]))
        assert len(virtual_venues) == 1
        assert virtual_venues[0]["venueTypeId"] == humanize(
            digital_venue_type.id)
コード例 #7
0
    def when_successful_and_existing_offerer_creates_editor_user_offerer_and_does_not_log_in(
            self, app):
        # Given
        VirtualVenueTypeFactory()
        offerer = OffererFactory(siren="349974931",
                                 validationToken="not_validated")
        pro = ProFactory(email="*****@*****.**", publicName="bobby")
        UserOffererFactory(user=pro, offerer=offerer)

        data = BASE_DATA_PRO.copy()

        # When
        response = TestClient(app.test_client()).post("/users/signup/pro",
                                                      json=data)

        # Then
        assert response.status_code == 204
        assert "Set-Cookie" not in response.headers
        pro = User.query.filter_by(email="*****@*****.**").first()
        assert pro is not None
        offerer = Offerer.query.filter_by(siren="349974931").first()
        assert offerer is not None
        user_offerer = UserOfferer.query.filter_by(user=pro,
                                                   offerer=offerer).first()
        assert user_offerer is not None
        assert user_offerer.validationToken is not None
コード例 #8
0
    def when_offerer_already_have_user_offerer_new_user_offerer_has_validation_token(
            self, mock_api_entreprise, make_validation_email_object, app):
        # Given
        make_validation_email_object.return_value = {"Html-part": None}
        mock_api_entreprise.return_value = MagicMock(
            status_code=200,
            text="",
            json=MagicMock(
                return_value=copy.deepcopy(api_entreprise_json_mock)))

        pro = ProFactory()
        offerer = OffererFactory()
        UserOffererFactory(offerer=offerer, validationToken=None)
        VirtualVenueTypeFactory()
        body = {
            "name": offerer.name,
            "siren": offerer.siren,
            "address": offerer.address,
            "postalCode": offerer.postalCode,
            "city": offerer.city,
        }

        # when
        response = TestClient(app.test_client()).with_session_auth(
            pro.email).post("/offerers", json=body)

        # then
        assert response.status_code == 201
        offerer = Offerer.query.first()
        created_user_offerer = (UserOfferer.query.filter(
            UserOfferer.offerer == offerer).filter(
                UserOfferer.user == pro).one())
        assert created_user_offerer.validationToken is not None
コード例 #9
0
def test_should_register_new_venue(app):
    # given
    user = ProFactory()
    auth_request = TestClient(app.test_client()).with_session_auth(email=user.email)
    venue_data = create_valid_venue_data(user)

    # when
    response = auth_request.post("/venues", json=venue_data)

    # then
    assert response.status_code == 201
    idx = response.json["id"]

    venue = Venue.query.filter_by(id=dehumanize(idx)).one()

    assert venue.name == venue_data["name"]
    assert venue.publicName == venue_data["publicName"]
    assert venue.siret == venue_data["siret"]
    assert venue.venueTypeId == dehumanize(venue_data["venueTypeId"])
    assert venue.venueLabelId == dehumanize(venue_data["venueLabelId"])
    assert venue.description == venue_data["description"]
    assert venue.audioDisabilityCompliant == venue_data["audioDisabilityCompliant"]
    assert venue.mentalDisabilityCompliant == venue_data["mentalDisabilityCompliant"]
    assert venue.motorDisabilityCompliant == venue_data["motorDisabilityCompliant"]
    assert venue.visualDisabilityCompliant == venue_data["visualDisabilityCompliant"]
    assert venue.contact.email == venue_data["contact"]["email"]

    assert venue.isValidated
    assert not venue.isPermanent
    assert not venue.contact.phone_number
    assert not venue.contact.social_medias
コード例 #10
0
    def test_raise_error_when_offerer_relative_to_csv_not_created(self):
        # given
        blake = ProFactory(email="*****@*****.**", id=123)
        blakes_company = Offerer(siren="362521879", name="MyBletcheyCompany")

        # when
        with pytest.raises(OffererNotCreatedException):
            fill_user_offerer_from(UserOfferer(), blake, blakes_company)
コード例 #11
0
def test_should_return_403_when_user_is_not_managing_offerer_create_venue(app):
    user = ProFactory()
    venue_data = create_valid_venue_data()
    auth_request = TestClient(app.test_client()).with_session_auth(email=user.email)

    response = auth_request.post("/venues", json=venue_data)

    assert response.status_code == 403
    assert response.json["global"] == ["Vous n'avez pas les droits d'accès suffisant pour accéder à cette information."]
コード例 #12
0
def test_update_external_pro_user():
    user = ProFactory()

    n_query_get_user = 1
    n_query_is_pro = 1

    with assert_num_queries(n_query_get_user + n_query_is_pro):
        update_external_user(user)

    assert len(batch_testing.requests) == 0
    assert len(sendinblue_testing.sendinblue_requests) == 1
コード例 #13
0
def test_dont_suspend_users_not_in_given_emails_providers_list():
    # Given
    fraudulent_emails_providers = ["example.com"]
    admin_user = AdminFactory(email="*****@*****.**")
    non_fraudulent_pro = ProFactory(email="*****@*****.**")

    # When
    suspend_fraudulent_pro_by_email_providers(fraudulent_emails_providers,
                                              admin_user,
                                              dry_run=False)

    # Then
    assert non_fraudulent_pro.isActive
コード例 #14
0
    def should_not_modify_pro_user_department_code_when_user_not_in_93(
            self, app):
        # Given
        user = ProFactory(departementCode="72")
        offerer = create_offerer()
        user_offerer = create_user_offerer(user=user, offerer=offerer)
        repository.save(user_offerer)

        # When
        fill_pro_department_code_with_offerer_postal_code()

        # Then
        updated_user = User.query.one()
        assert updated_user.departementCode == "72"
コード例 #15
0
    def should_not_update_user_linked_to_offerer_with_postal_code_outside_75(
            self, app):
        # Given
        user = ProFactory(departementCode="72")
        offerer = create_offerer(postal_code="64000")
        user_offerer = create_user_offerer(user=user, offerer=offerer)
        repository.save(user_offerer)

        # When
        fill_pro_department_code_with_offerer_postal_code()

        # Then
        updated_user = User.query.one()
        assert updated_user.departementCode == "72"
コード例 #16
0
    def should_update_user_department_code_linked_to_offerer_with_postal_code_75(
            self, app):
        # Given
        user = ProFactory(departementCode="93")
        offerer = create_offerer(siren="123456788", postal_code="75016")
        user_offerer = create_user_offerer(user=user, offerer=offerer)
        repository.save(user_offerer)

        # When
        fill_pro_department_code_with_offerer_postal_code()

        # Then
        updated_user = User.query.one()
        assert updated_user.departementCode == "75"
コード例 #17
0
def test_reject_pro_user(app):
    pro = ProFactory()
    initial = {
        "publicName": pro.publicName,
    }
    data = {
        "publicName": "New name",
    }
    client = TestClient(app.test_client()).with_session_auth(email=pro.email)
    response = client.patch("/beneficiaries/current", json=data)

    assert response.status_code == 403
    pro = User.query.get(pro.id)
    assert pro.publicName == initial["publicName"]
コード例 #18
0
    def test_returns_a_user_offerer_built_with_user_and_offerer_relative_to_csv_row(
            self):
        # given
        blake = ProFactory(email="*****@*****.**", id=123)
        blakes_company = OffererFactory(siren="362521879",
                                        name="MyBletcheyCompany",
                                        id=234)

        # when
        user_offerer = fill_user_offerer_from(UserOfferer(), blake,
                                              blakes_company)

        # then
        assert user_offerer.user == blake
        assert user_offerer.offerer == blakes_company
コード例 #19
0
def test_suspend_pro_user_with_many_offerers_and_delete_all_offerers():
    fraudulent_emails_providers = ["example.com"]
    admin_user = AdminFactory(email="*****@*****.**")
    fraudulent_user = ProFactory(email="*****@*****.**", )
    first_offerer = OffererFactory()
    UserOffererFactory(user=fraudulent_user, offerer=first_offerer)
    second_offerer = OffererFactory()
    UserOffererFactory(user=fraudulent_user, offerer=second_offerer)

    suspend_fraudulent_pro_by_email_providers(fraudulent_emails_providers,
                                              admin_user,
                                              dry_run=False)

    assert not fraudulent_user.isActive
    assert Offerer.query.count() == 0
コード例 #20
0
def test_suspend_pros_in_given_emails_providers_list():
    # Given
    fraudulent_emails_providers = ["example.com"]
    admin_user = AdminFactory(email="*****@*****.**")
    fraudulent_user = ProFactory(email="*****@*****.**", )
    offerer = OffererFactory()
    UserOffererFactory(user=fraudulent_user, offerer=offerer)

    # When
    suspend_fraudulent_pro_by_email_providers(fraudulent_emails_providers,
                                              admin_user,
                                              dry_run=False)

    # Then
    assert not fraudulent_user.isActive
コード例 #21
0
    def when_the_user_is_authenticated(self, app):
        # Given
        pro = ProFactory()
        venue_label_1 = VenueLabelFactory(label="Maison des illustres")
        venue_label_2 = VenueLabelFactory(label="Monuments historiques")

        # When
        response = TestClient(app.test_client()).with_session_auth(pro.email).get("/venue-labels")

        # then
        assert response.status_code == 200
        assert len(response.json) == 2
        assert response.json == [
            {"id": humanize(venue_label_1.id), "label": venue_label_1.label},
            {"id": humanize(venue_label_2.id), "label": venue_label_2.label},
        ]
コード例 #22
0
def test_delete_offerer_and_venue():
    # Given
    fraudulent_emails_providers = ["example.com"]
    admin_user = AdminFactory(email="*****@*****.**")
    fraudulent_user = ProFactory(email="*****@*****.**", )
    offerer = OffererFactory()
    UserOffererFactory(user=fraudulent_user, offerer=offerer)
    VenueFactory(managingOfferer=offerer)

    # When
    suspend_fraudulent_pro_by_email_providers(fraudulent_emails_providers,
                                              admin_user,
                                              dry_run=False)

    # Then
    assert Offerer.query.count() == 0
    assert Venue.query.count() == 0
コード例 #23
0
    def should_return_first_linked_offerer(self, app):
        # Given
        user = ProFactory(departementCode="93")
        offerer1 = create_offerer(idx=1,
                                  siren="123456788",
                                  postal_code="75016")
        offerer2 = create_offerer(idx=2,
                                  siren="123456789",
                                  postal_code="23000")
        user_offerer1 = create_user_offerer(idx=2, user=user, offerer=offerer1)
        user_offerer2 = create_user_offerer(idx=1, user=user, offerer=offerer2)
        repository.save(user_offerer1, user_offerer2)

        # When
        offerer = _get_user_initial_linked_offerer(user)

        # Then
        assert offerer == offerer2
コード例 #24
0
def test_mandatory_accessibility_fields(app):
    # given
    user = ProFactory()

    venue_data = create_valid_venue_data(user)
    venue_data.pop("audioDisabilityCompliant")
    venue_data.pop("mentalDisabilityCompliant")
    venue_data.pop("motorDisabilityCompliant")
    venue_data.pop("visualDisabilityCompliant")

    auth_request = TestClient(app.test_client()).with_session_auth(email=user.email)

    # when
    response = auth_request.post("/venues", json=venue_data)

    # then
    assert response.status_code == 400
    assert response.json["global"] == ["L'accessibilité du lieu doit être définie."]
コード例 #25
0
    def test_ok(self, mock_check_image, mock_get_distant_image, app):
        # Given
        body = {"url": "https://example.com/exampleaaa.jpg"}
        user = ProFactory()
        auth_request = TestClient(
            app.test_client()).with_session_auth(email=user.email)
        mock_get_distant_image.return_value = b"aze"
        mock_check_image.return_value = None

        # When
        response = auth_request.post("/offers/thumbnail-url-validation",
                                     json=body)

        # Then
        assert response.status_code == 200
        assert response.json == {
            "errors": [],
            "image": "data:image/png;base64,YXpl"
        }
コード例 #26
0
def test_should_return_401_when_latitude_out_of_range_and_longitude_wrong_format(app):
    # given
    user = ProFactory()
    venue_data = create_valid_venue_data(user)

    venue_data = {
        **venue_data,
        "latitude": -98.82387,
        "longitude": "112°3534",
    }

    auth_request = TestClient(app.test_client()).with_session_auth(email=user.email)

    # when
    response = auth_request.post("/venues", json=venue_data)

    # then
    assert response.status_code == 400
    assert response.json["latitude"] == ["La latitude doit être comprise entre -90.0 et +90.0"]
    assert response.json["longitude"] == ["Format incorrect"]
コード例 #27
0
    def test_image_size_too_large(self, mock_get_distant_image, app):
        # Given
        body = {"url": "https://example.com/wallpaper.jpg"}
        user = ProFactory()
        auth_request = TestClient(
            app.test_client()).with_session_auth(email=user.email)
        mock_get_distant_image.side_effect = exceptions.FileSizeExceeded(
            max_size=10_000_000)

        # When
        response = auth_request.post("/offers/thumbnail-url-validation",
                                     json=body)

        # Then
        assert response.status_code == 200
        assert response.json == {
            "errors":
            ["Utilisez une image dont le poids est inférieur à 10.0 MB"],
            "image": None
        }
コード例 #28
0
    def test_image_too_small(self, mock_get_distant_image, app):
        # Given
        body = {"url": "https://example.com/icon.jpeg"}
        user = ProFactory()
        auth_request = TestClient(
            app.test_client()).with_session_auth(email=user.email)
        mock_get_distant_image.side_effect = exceptions.ImageTooSmall(
            min_width=400, min_height=400)

        # When
        response = auth_request.post("/offers/thumbnail-url-validation",
                                     json=body)

        # Then
        assert response.status_code == 200
        assert response.json == {
            "errors":
            ["Utilisez une image plus grande (supérieure à 400px par 400px)"],
            "image":
            None,
        }
コード例 #29
0
    def test_when_siret_wrong(self, app):
        # Given
        VenueTypeFactory(label="Librairie")
        VirtualVenueTypeFactory()
        ProFactory(email="*****@*****.**")
        csv_row = OrderedDict([
            ("", "104"),
            ("Company ID", "1099515212"),
            ("Email", "*****@*****.**"),
            ("First Name", "Anthony"),
            ("Last Name", "Champion"),
            ("Phone", "01 02 34 56 78"),
            ("Postal Code", "44016.0"),
            ("City", "NANTES CEDEX 1"),
            ("SIRET", "1"),
            ("SIREN", "636710003"),
            ("Département", "44"),
            ("Name", "Fictive"),
            ("Catégorie", "Librairie"),
            ("Street Address", "45 RUE DU JOYEUX LURON"),
            ("nom_structure", "SARL"),
            ("adresse", "45 RUE DU JOYEUX LURON, 44000"),
            ("code_postal", "44000"),
            ("commune", "NANTES"),
            ("geoloc", "[44.455621, -2.546101]"),
            ("nom_lieu", "Ma librairie"),
            ("siege_social", "45 RUE DU JOYEUX LURON, 44000"),
            ("lieu_deja_inscrit", "0"),
            ("structure_deja_inscrite", "0"),
        ])

        # When
        import_new_offerer_from_csv(csv_row)

        # Then
        assert User.query.count() == 1
        assert Offerer.query.count() == 1
        assert UserOfferer.query.count() == 1
        assert Venue.query.count() == 1
コード例 #30
0
    def test_returns_created_user_offerer(self, app):
        # given
        blake = ProFactory(email="*****@*****.**", id=123)
        VirtualVenueTypeFactory()
        blakes_company = OffererFactory(siren="362521879",
                                        name="MyBletcheyCompany",
                                        id=234)
        self.find_user_query.side_effect = [blake]
        self.find_offerer_query.side_effect = [blakes_company]
        self.find_user_offerer_query.side_effect = [None]

        # when
        user_offerer = create_activated_user_offerer(
            self.csv_row,
            find_user=self.find_user_query,
            find_offerer=self.find_offerer_query,
            find_user_offerer=self.find_user_offerer_query,
        )

        # then
        assert user_offerer.userId == 123
        assert user_offerer.offererId == 234