def test_user_is_pro(self):
        """
        Test that the Pro user is correctly detected in various cases.

        Note : A pro user can be defined by his IP address too but it's not possible to test.
        So, only tests by email are provided
        """
        user_pro = User.create(email='*****@*****.**',
                               gender='male',
                               first_name='John',
                               last_name='Doe')
        user_public = User.create(email='*****@*****.**',
                                  gender='male',
                                  first_name='John',
                                  last_name='Doe')

        with self.test_request_context:
            # User which is not logged in should not be considered a pro user.
            self.assertFalse(pro.user_is_pro())

            # User with a pro email should be considered as a pro user.
            self.login(user_pro)
            self.assertTrue(pro.user_is_pro())
            self.logout()
            self.assertFalse(pro.user_is_pro())

            # User with a non pro email should not be considered a pro user.
            self.login(user_public)
            self.assertFalse(pro.user_is_pro())
            self.logout()
            self.assertFalse(pro.user_is_pro())
Example #2
0
 def assert_pro_version_is_not_enabled(self):
     """
     Utility method to assert pro version is not visible.
     """
     with self.test_request_context(headers=self.headers):
         self.assertFalse(pro.user_is_pro())
         self.assertFalse(pro.pro_version_enabled())
Example #3
0
 def login_as_pro(self):
     user_pro = User.create(email='*****@*****.**',
                            gender='male',
                            first_name='John',
                            last_name='Doe')
     self.login(user_pro)
     self.assertTrue(pro.user_is_pro())
     self.assertFalse(pro.pro_version_enabled())
Example #4
0
 def inject_dict_for_all_templates():
     return {
         'memo_url': settings.MEMO_URL,
         'user_is_pro': pro.user_is_pro(),
         'pro_version_enabled': pro.pro_version_enabled(),
         'last_data_deploy_date': Office.get_date_of_last_data_deploy(),
         'google_site_verification_code':
         settings.GOOGLE_SITE_VERIFICATION_CODE,
         'login_url': auth_utils.login_url,
         'jepostule_globally_enabled': settings.JEPOSTULE_QUOTA > 0,
         'tag_manager_url': settings.TAG_MANAGER_URL,
     }
Example #5
0
    def test_user_is_pro(self):
        """
        Test that the Pro user is correctly detected in various cases.
        """

        # Email detection, without IP detection
        with self.test_request_context():
            # User which is not logged in should not be considered a pro user.
            self.assertFalse(pro.user_is_pro())

            # # User with a pro email should be considered as a pro user.
            self.login(self.pro_user)
            self.assertTrue(pro.user_is_pro())
            self.logout()
            self.assertFalse(pro.user_is_pro())

            # User with a non pro email should not be considered a pro user.
            self.login(self.public_user)
            self.assertFalse(pro.user_is_pro())
            self.logout()
            self.assertFalse(pro.user_is_pro())

        # a public user logging in with the right IP address
        # and NOT from a Pila machine should be considered a pro user.
        with self.test_request_context(headers=self.headers):
            self.assertTrue(pro.user_is_pro())
Example #6
0
def pro_version():
    """
    Enable or disable "Version PRO" which is only visible to "PRO users".
    """
    if not pro.user_is_pro():
        abort(401)

    pro.toggle_pro_version()

    redirect_url = urllib.parse.unquote(request.args.get('next', '/'))

    if not redirect_url or not util.is_decoded_url_safe(redirect_url):
        redirect_url = '/'

    return redirect(redirect_url)
    def test_enable_disable_pro_version_view(self):
        """
        Test that the Pro Version is correctly enabled/disabled.
        """
        # Create a user.
        user_pro = User.create(email='*****@*****.**',
                               gender='male',
                               first_name='John',
                               last_name='Doe')

        next_url_without_domain = '/entreprises/metz-57000/boucherie?sort=score&d=10&h=1&p=0&f_a=0'
        next_url_with_domain = 'http://labonneboite.pole-emploi.fr' + next_url_without_domain
        url = self.url_for('user.pro_version',
                           **{'next': next_url_without_domain})

        with self.test_request_context:

            # Log the user in.
            self.login(user_pro)
            self.assertTrue(pro.user_is_pro())
            self.assertFalse(pro.pro_version_enabled())

            with self.app.session_transaction() as sess:
                self.assertNotIn(pro.PRO_VERSION_SESSION_KEY, sess)

            # Enable pro version.
            rv = self.app.get(url)
            self.assertEqual(rv.status_code, 302)
            self.assertEqual(rv.location, next_url_with_domain)
            # It is unclear what is the root cause of the following test
            # failure. The session object manipulated in the
            # pro_version_enabled function is different from the session
            # provided by the self.app.session_transaction context manager, but
            # I don't know why.
            # self.assertTrue(pro.pro_version_enabled())

            with self.app.session_transaction() as sess:
                self.assertIn(pro.PRO_VERSION_SESSION_KEY, sess)
                self.assertEqual(True, sess[pro.PRO_VERSION_SESSION_KEY])

            # Disable pro version.
            rv = self.app.get(url)
            self.assertEqual(rv.status_code, 302)
            self.assertEqual(rv.location, next_url_with_domain)
            self.assertFalse(pro.pro_version_enabled())

            with self.app.session_transaction() as sess:
                self.assertNotIn(pro.PRO_VERSION_SESSION_KEY, sess)
Example #8
0
 def inject_dict_for_all_templates():
     return {
         'hotjar_tag': hotjar.get_hotjar_tag(),
         'memo_js_url': settings.MEMO_JS_URL,
         'user_is_pro': pro.user_is_pro(),
         'pro_version_enabled': pro.pro_version_enabled(),
         'last_data_deploy_date': Office.get_date_of_last_data_deploy(),
         'google_analytics_id': settings.GOOGLE_ANALYTICS_ID,
         'seo_google_analytics_id': settings.SEO_GOOGLE_ANALYTICS_ID,
         'enable_google_optimize': settings.ENABLE_GOOGLE_OPTIMIZE,
         'google_optimize_id': settings.GOOGLE_OPTIMIZE_ID,
         'tilkee_enabled': settings.TILKEE_ENABLED,
         'google_site_verification_code':
         settings.GOOGLE_SITE_VERIFICATION_CODE,
         'login_url': auth_utils.login_url,
         'jepostule_globally_enabled': settings.JEPOSTULE_QUOTA > 0,
         'enable_isochrones': settings.ENABLE_ISOCHRONES,
     }