Пример #1
0
def _create_mock_scoring_project():
    """Create a mock scoring_project."""

    _db = mongomock.MongoClient().test
    user_profile = user_pb2.UserProfile()
    project = project_pb2.Project()
    return scoring.ScoringProject(project, user_profile, None, _db)
Пример #2
0
    def send_reset_password_token(self, email):
        """Sends an email to user with a reset token so that they can reset their password."""
        user_dict = self._db.user.find_one({'profile.email': email})
        if not user_dict:
            flask.abort(403, "Nous n'avons pas d'utilisateur avec cet email : %s" % email)
        user_auth_dict = self._db.user_auth.find_one({'_id': user_dict['_id']})
        if not user_auth_dict or not user_auth_dict.get('hashedPassword'):
            flask.abort(
                403, 'Utilisez Facebook ou Google pour vous connecter, comme la première fois.')

        hashed_old_password = user_auth_dict.get('hashedPassword')
        auth_token = _timestamped_hash(
            int(time.time()), email + str(user_dict['_id']) + hashed_old_password)

        user_profile = user_pb2.UserProfile()
        proto.parse_from_mongo(user_dict.get('profile'), user_profile)

        reset_link = parse.urljoin(flask.request.url, '/?' + parse.urlencode({
            'email': email,
            'resetToken': auth_token}))
        template_vars = {
            'resetLink': reset_link,
            'firstName': user_profile.name,
        }
        result = mail.send_template(
            '71254', user_profile, template_vars, monitoring_category='reset_password')
        if result.status_code != 200:
            logging.error('Failed to send an email with MailJet:\n %s', result.text)
            flask.abort(result.status_code)
Пример #3
0
    def test_status_update_link(self) -> None:
        """Test the status update function."""

        user_id = '02499e64387edfcc2ab7a948'
        profile = user_pb2.UserProfile(gender=user_pb2.FEMININE, can_tutoie=True, locale='fr@tu')
        status_update_link = campaign.get_status_update_link(user_id, profile)
        base_url = f'https://www.bob-emploi.fr/statut/mise-a-jour?user={user_id}'
        self.assertRegex(
            status_update_link,
            rf'^{re.escape(base_url)}&token=\d+\.[a-f0-9]+&gender=FEMININE&'
            'can_tutoie=true&hl=fr%40tu$')
Пример #4
0
def _send_data_by_email(user_data: ali_pb2.User) -> ali_pb2.EmailStatuses:
    user_email = user_data.user_email
    user_profile = user_pb2.UserProfile(email=user_email)
    counselor_email = user_data.counselor_email
    mails_sent = ali_pb2.EmailStatuses()
    template_vars = {
        'counselorEmail': counselor_email,
        'counselorName': user_data.counselor_name,
        'directLink': user_data.results_url,
        'userEmail': user_email,
    }

    if user_profile.email:
        mails_sent.has_user_email = _send_email('1107108', user_profile,
                                                template_vars)
    if counselor_email:
        counselor_profile = user_pb2.UserProfile(email=counselor_email)
        mails_sent.has_counselor_email = _send_email('1109007',
                                                     counselor_profile,
                                                     template_vars)
    return mails_sent
Пример #5
0
 def setUp(self):
     super(_BaseTestCase, self).setUp()
     self.database = mongomock.MongoClient().test
     self.database.action_templates.insert_one({
         '_id': 'rec1CWahSiEtlwEHW',
         'goal': 'Reorientation !',
     })
     self.user = user_pb2.User(
         features_enabled=user_pb2.Features(advisor=user_pb2.ACTIVE),
         profile=user_pb2.UserProfile(name='Margaux',
                                      gender=user_pb2.FEMININE))
     advisor.clear_cache()
Пример #6
0
    def clone(self):
        """Clone this persona.

        This is useful if you want a slightly modified persona: you clone an
        existing one and then can modify its protobufs without modifying the
        original one.
        """
        name = '{} cloned'.format(self.name)
        user_profile = user_pb2.UserProfile()
        user_profile.CopyFrom(self.user_profile)
        project = project_pb2.Project()
        project.CopyFrom(self.project)
        return _Persona(name=name, user_profile=user_profile, project=project)
Пример #7
0
    def test_status_update_link(self):
        """Test the status update function."""

        user_id = '02499e64387edfcc2ab7a948'
        profile = user_pb2.UserProfile(gender=user_pb2.FEMININE,
                                       can_tutoie=True)
        status_update_link = campaign.get_status_update_link(user_id, profile)
        self.assertRegex(
            status_update_link,
            r'^{}&token=\d+\.[a-f0-9]+&gender=FEMININE&can_tutoie=true$'.
            format(
                re.escape(
                    'https://www.bob-emploi.fr/statut/mise-a-jour?user={}'.
                    format(user_id))))
Пример #8
0
    def setUp(self) -> None:
        super().setUp()
        self.database = mongomock.MongoClient().test
        self.database.action_templates.insert_one({
            '_id': 'rec1CWahSiEtlwEHW',
            'goal': 'Reorientation !',
        })
        self.database.translations.insert_one({
            'string': 'de {job_name}',
            'fr@tu': 'de {job_name}',
        })

        self.user = user_pb2.User(
            features_enabled=user_pb2.Features(advisor=user_pb2.ACTIVE,
                                               workbench=user_pb2.ACTIVE),
            profile=user_pb2.UserProfile(name='Margaux',
                                         gender=user_pb2.FEMININE,
                                         email='*****@*****.**',
                                         locale='fr@tu'))
        proto.CachedCollection.update_cache_version()
Пример #9
0
 def load_set(cls, filename):
     """Load a set of personas from a JSON file."""
     with open(filename) as personas_file:
         personas_json = json.load(personas_file)
     personas = {}
     for name, blob in personas_json.items():
         user_profile = user_pb2.UserProfile()
         assert proto.parse_from_mongo(blob['user'], user_profile)
         features_enabled = user_pb2.Features()
         if 'featuresEnabled' in blob:
             assert proto.parse_from_mongo(blob['featuresEnabled'],
                                           features_enabled)
         project = project_pb2.Project()
         assert proto.parse_from_mongo(blob['project'], project)
         assert name not in personas
         personas[name] = cls(name,
                              user_profile=user_profile,
                              project=project,
                              features_enabled=features_enabled)
     return personas
Пример #10
0
 def setUp(self):
     super(PopulateProjectTemplateTest, self).setUp()
     # Pre-populate project's fields that are usualldy set. Individual tests
     # should not count on those values.
     self.project = project_pb2.Project()
     self.project.target_job.name = 'Boulanger / Boulangère'
     self.project.target_job.masculine_name = 'Boulanger'
     self.project.target_job.feminine_name = 'Boulangère'
     self.project.target_job.job_group.rome_id = 'Z9007'
     self.project.mobility.city.city_id = '69123'
     self.project.mobility.city.departement_id = '69'
     self.project.mobility.city.region_id = '84'
     self.project.mobility.city.postcodes = '69001-69002-69003-69004'
     self.project.mobility.city.name = 'Lyon'
     self.database = mongomock.MongoClient().test
     self.database.regions.insert_one({
         '_id': '84',
         'prefix': 'en ',
         'name': 'Auvergne-Rhône-Alpes',
     })
     self.scoring_project = scoring.ScoringProject(
         self.project, user_pb2.UserProfile(), user_pb2.Features(), self.database)