Esempio n. 1
0
    def test_register_submit_i18n(self, mock_iplookup):
        from tests.utils import gettext_for
        _ = gettext_for('ja')

        mock_iplookup.return_value = {
            'country_code': 'JP',
            'city': 'Tokyo',
            'latitude': '35.6895',
            'longitude': '139.6917',
        }

        self.assertLength(self.User.query.all(), 0)

        user = self.GoUserFactory()

        environ_base = {
            'HTTP_ACCEPT_LANGUAGE': 'ja',
            'REMOTE_ADDR': '127.0.0.1',
        }
        self.post(
            url_for('users.register'),
            data={
                'name': user.name,
                'email': user.email,
                'password': user.plaintext_password,
                'confirm': user.plaintext_password,
            },
            environ_base=environ_base,
        )

        self.assertLength(self.User.query.all(), 1)
        created_user = self.User.query.first()

        # Page should be localized from HTTP_ACCEPT_LANGUAGE header
        # and stored into user.locale
        self.assertIn('{} {}'.format(_('Welcome'), user.name),
                      self.get(url_for('home')))

        # Page unlocalized, not passing in header and user logged out
        self.get(url_for('users.logout'))
        self.assertIn('Login', self.get(url_for('home')))

        self.assertEqual(created_user.name, user.name)
        self.assertEqual(created_user.email, user.email)
        self.assertEqual(created_user.email_confirmed, False)
        self.assertNotEqual(created_user.password, user.password)
        self.assertIsNotNone(created_user.last_login_date)
        self.assertEqual(created_user.locale, 'ja')
        self.assertEqual(created_user.country_code, 'JP')
        self.assertEqual(created_user.city, 'Tokyo')
        self.assertEqual(created_user.latitude, 35.6895)
        self.assertEqual(created_user.longitude, 139.6917)
Esempio n. 2
0
    def test_register_submit_i18n(self, mock_iplookup):
        from tests.utils import gettext_for
        _ = gettext_for('ja')

        mock_iplookup.return_value = {
            'country_code': 'JP', 'city': 'Tokyo',
            'latitude': '35.6895', 'longitude': '139.6917',
        }

        self.assertLength(self.User.query.all(), 0)

        user = self.GoUserFactory()

        environ_base = {
            'HTTP_ACCEPT_LANGUAGE': 'ja',
            'REMOTE_ADDR': '127.0.0.1',
        }
        self.post(
            url_for('users.register'),
            data={
                'name': user.name,
                'email': user.email,
                'password': user.plaintext_password,
                'confirm': user.plaintext_password,
            },
            environ_base=environ_base,
        )

        self.assertLength(self.User.query.all(), 1)
        created_user = self.User.query.first()

        # Page should be localized from HTTP_ACCEPT_LANGUAGE header
        # and stored into user.locale
        self.assertIn('{} {}'.format(_('Welcome'), user.name),
                      self.get(url_for('home')))

        # Page unlocalized, not passing in header and user logged out
        self.get(url_for('users.logout'))
        self.assertIn('Login', self.get(url_for('home')))

        self.assertEqual(created_user.name, user.name)
        self.assertEqual(created_user.email, user.email)
        self.assertEqual(created_user.email_confirmed, False)
        self.assertNotEqual(created_user.password, user.password)
        self.assertIsNotNone(created_user.last_login_date)
        self.assertEqual(created_user.locale, 'ja')
        self.assertEqual(created_user.country_code, 'JP')
        self.assertEqual(created_user.city, 'Tokyo')
        self.assertEqual(created_user.latitude, 35.6895)
        self.assertEqual(created_user.longitude, 139.6917)
Esempio n. 3
0
 def setUpClass(cls):
     super(TestViews_ja, cls).setUpClass()
     from tests.utils import gettext_for
     cls._ = gettext_for('ja')
Esempio n. 4
0
 def name(user, n):
     game = gettext_for(locale)(str(user.game))
     return fmt.format(
         game=game.decode('utf-8'),
         n=n,
     )
Esempio n. 5
0
 def name(club, n):
     game = gettext_for(locale)(Club.label_for_choice('game', club.game))
     return fmt.format(
         game=game,
         n=n,
     )