Exemple #1
0
    def test_user_default_language(self):
        # type: () -> None
        """
        Check if the default language of new user is the default language
        of the realm.
        """
        username = "******"
        email = "*****@*****.**"
        domain = "zulip.com"
        password = "******"
        realm = get_realm(domain)
        do_set_realm_default_language(realm, "de")

        result = self.client_post('/accounts/home/', {'email': email})
        self.assertEquals(result.status_code, 302)
        self.assertTrue(result["Location"].endswith(
                "/accounts/send_confirm/%s@%s" % (username, domain)))
        result = self.client_get(result["Location"])
        self.assert_in_response("Check your email so we can get started.", result)

        # Visit the confirmation link.
        from django.core.mail import outbox
        for message in reversed(outbox):
            if email in message.to:
                confirmation_link_pattern = re.compile(settings.EXTERNAL_HOST + "(\S+)>")
                confirmation_url = confirmation_link_pattern.search(
                    message.body).groups()[0]
                break
        else:
            raise ValueError("Couldn't find a confirmation email.")

        result = self.client_get(confirmation_url)
        self.assertEquals(result.status_code, 200)
        # Pick a password and agree to the ToS.
        result = self.submit_reg_form_for_user(username, password, domain)
        self.assertEquals(result.status_code, 302)

        user_profile = get_user_profile_by_email(email)
        self.assertEqual(user_profile.default_language, realm.default_language)
        outbox.pop()
Exemple #2
0
    def test_send_notification(self):
        User.objects.create_user(username='******',
                                 password='******',
                                 email='*****@*****.**')

        usr = UserProfile.objects.all()[0]
        usr.tags.add(u'자전거')
        usr.tags.add(u'악기')

        self.client.get('/api-berlin/send_notification/', format='json')
        from django.core.mail import outbox
        mail = outbox.pop()
        self.assertIsNotNone(mail.body)
Exemple #3
0
    def test_facebook_read_action(self, mock_requests):
        mock_requests.method.return_value = '{"id":"641729025968976"}'
        mock_requests.status_code = 200
        mock_requests.raise_for_status.return_value = 'ok'

        UserSocialAuth.objects.create(user=self.usr,
                                      uid=self.profile.sns_id)

        res = self.client.post('/api-hoodpub/read/',
                               {'isbn': self.book1.isbn}, format='json')

        json_output = json.loads(res.content)
        self.assertIn('msg', json_output['hoodpub'].keys())
        from django.core.mail import outbox
        mail = outbox.pop()
        self.assertIsNotNone(mail.body)
    def test_project_join_request_email_sent(self):

        from django.core.mail import outbox

        pre_request_message_len = len(outbox)

        project_join_request(self.test_project, self.test_user)

        post_request_message_len = len(outbox)

        self.assertEqual(pre_request_message_len, post_request_message_len - 1)

        message = outbox.pop()

        self.assertEqual(message.subject, "ES-DOC Questionnaire project join request")
        self.assertIn(self.test_user.username, message.body)
        self.assertIn(self.test_project.name, message.body)
Exemple #5
0
    def test_compile_order_via_api(self):

        order_dict = {
            'username': '******',
            'phone': '123213',
            'email': 'hello@com',
            'books': 325,
            'locations': 3
        }
        endpoint = '/api-order/'
        url = urllib.quote(endpoint.encode('utf-8'), safe='')
        res = self.client.post(url, order_dict, format='json')
        self.assertTrue('username' in res.content)

        from django.core.mail import outbox
        mail = outbox.pop()
        self.assertIsNotNone(mail.body)
        self.assertTrue('email' not in mail.subject)
Exemple #6
0
    def test_register_first_user_with_invites(self):
        """
        The first user in a realm has a special step in their signup workflow
        for inviting coworkers. Do as realistic an end-to-end test as we can
        without Tornado running.
        """
        username = "******"
        password = "******"
        domain = "test.com"
        email = "*****@*****.**"

        # Create a new realm to ensure that we're the first user in it.
        Realm.objects.create(domain=domain, name="Test Inc.")

        # Start the signup process by supplying an email address.
        result = self.client.post('/accounts/home/', {'email': email})

        # Check the redirect telling you to check your mail for a confirmation
        # link.
        self.assertEquals(result.status_code, 302)
        self.assertTrue(result["Location"].endswith(
            "/accounts/send_confirm/%s@%s" % (username, domain)))
        result = self.client.get(result["Location"])
        self.assertIn("Check your email so we can get started.",
                      result.content)

        # Visit the confirmation link.
        from django.core.mail import outbox
        for message in reversed(outbox):
            if email in message.to:
                confirmation_link_pattern = re.compile(settings.EXTERNAL_HOST +
                                                       "(\S+)>")
                confirmation_url = confirmation_link_pattern.search(
                    message.body).groups()[0]
                break
        else:
            raise ValueError("Couldn't find a confirmation email.")

        result = self.client.get(confirmation_url)
        self.assertEquals(result.status_code, 200)

        # Pick a password and agree to the ToS.
        result = self.submit_reg_form_for_user(username, password, domain)
        self.assertEquals(result.status_code, 302)
        self.assertTrue(result["Location"].endswith("/invite/"))

        # Invite coworkers to join you.
        result = self.client.get(result["Location"])
        self.assertIn("You're the first one here!", result.content)

        # Reset the outbox for our invites.
        outbox.pop()

        invitees = ['alice@' + domain, 'bob@' + domain]
        params = {'invitee_emails': ujson.dumps(invitees)}
        result = self.client.post('/json/bulk_invite_users', params)
        self.assert_json_success(result)

        # We really did email these users, and they have PreregistrationUser
        # objects.
        email_recipients = [message.recipients()[0] for message in outbox]
        self.assertEqual(len(outbox), len(invitees))
        self.assertItemsEqual(email_recipients, invitees)

        user_profile = get_user_profile_by_email(email)
        self.assertEqual(
            len(invitees),
            PreregistrationUser.objects.filter(
                referred_by=user_profile).count())
Exemple #7
0
    def test_register_first_user_with_invites(self):
        # type: () -> None
        """
        The first user in a realm has a special step in their signup workflow
        for inviting other users. Do as realistic an end-to-end test as we can
        without Tornado running.
        """
        username = "******"
        password = "******"
        domain = "test.com"
        email = "*****@*****.**"

        # Create a new realm to ensure that we're the first user in it.
        Realm.objects.create(domain=domain, name="Test Inc.")

        # Start the signup process by supplying an email address.
        result = self.client_post('/accounts/home/', {'email': email})

        # Check the redirect telling you to check your mail for a confirmation
        # link.
        self.assertEquals(result.status_code, 302)
        self.assertTrue(result["Location"].endswith(
                "/accounts/send_confirm/%s@%s" % (username, domain)))
        result = self.client_get(result["Location"])
        self.assert_in_response("Check your email so we can get started.", result)

        # Visit the confirmation link.
        from django.core.mail import outbox
        for message in reversed(outbox):
            if email in message.to:
                confirmation_link_pattern = re.compile(settings.EXTERNAL_HOST + "(\S+)>")
                confirmation_url = confirmation_link_pattern.search(
                    message.body).groups()[0]
                break
        else:
            raise ValueError("Couldn't find a confirmation email.")

        result = self.client_get(confirmation_url)
        self.assertEquals(result.status_code, 200)

        # Pick a password and agree to the ToS.
        result = self.submit_reg_form_for_user(username, password, domain)
        self.assertEquals(result.status_code, 302)
        self.assertTrue(result["Location"].endswith("/invite/"))

        # Invite other users to join you.
        result = self.client_get(result["Location"])
        self.assert_in_response("You're the first one here!", result)

        # Reset the outbox for our invites.
        outbox.pop()

        invitees = ['alice@' + domain, 'bob@' + domain]
        params = {
            'invitee_emails': ujson.dumps(invitees)
        }
        result = self.client_post('/json/bulk_invite_users', params)
        self.assert_json_success(result)

        # We really did email these users, and they have PreregistrationUser
        # objects.
        email_recipients = [message.recipients()[0] for message in outbox]
        self.assertEqual(len(outbox), len(invitees))
        self.assertEqual(sorted(email_recipients), sorted(invitees))

        user_profile = get_user_profile_by_email(email)
        self.assertEqual(len(invitees), PreregistrationUser.objects.filter(
                referred_by=user_profile).count())