Пример #1
0
    def test_registration_creates_admin_activated_user(self):
        """api creates admin activated user on POST"""
        settings.override_setting('account_activation', 'admin')

        response = self.client.post(
            self.api_link,
            data={
                'username': '******',
                'email': '*****@*****.**',
                'password': '******',
            },
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json(), {
            'activation': 'admin',
            'username': '******',
            'email': '*****@*****.**',
        })

        auth_json = self.client.get(reverse('misago:api:auth')).json()
        self.assertFalse(auth_json['is_authenticated'])

        UserModel.objects.get_by_username('Bob')
        UserModel.objects.get_by_email('*****@*****.**')

        self.assertIn('Welcome', mail.outbox[0].subject)
    def test_registration_creates_user_with_whitespace_password(self):
        """api creates user with spaces around password"""
        settings.override_setting('account_activation', 'none')

        response = self.client.post(
            self.api_link,
            data={
                'username': '******',
                'email': '*****@*****.**',
                'password': '******',
            },
        )

        self.assertContains(response, 'active')
        self.assertContains(response, 'Bob')
        self.assertContains(response, '*****@*****.**')

        UserModel.objects.get_by_username('Bob')

        test_user = UserModel.objects.get_by_email('*****@*****.**')
        self.assertEqual(Online.objects.filter(user=test_user).count(), 1)

        self.assertTrue(test_user.check_password(' pass123 '))

        response = self.client.get(reverse('misago:index'))
        self.assertContains(response, 'Bob')

        self.assertIn('Welcome', mail.outbox[0].subject)
Пример #3
0
    def test_context_processor_remote_policy(self):
        """context processor has TOS link to remote url"""
        request = MockRequest()

        settings.override_setting('privacy_policy_link', 'http://test.com')
        context_dict = legal_links(request)

        self.assertEqual(context_dict, {
            'privacy_policy': 'http://test.com',
            'terms_of_service': None,
        })
        self.assertEqual(request.frontend_context['url'], {
            'privacy_policy': 'http://test.com',
        })

        # set misago view too
        settings.override_setting('privacy_policy', 'Lorem ipsum')
        context_dict = legal_links(request)

        self.assertEqual(context_dict, {
            'privacy_policy': 'http://test.com',
            'terms_of_service': None,
        })
        self.assertEqual(request.frontend_context['url'], {
            'privacy_policy': 'http://test.com',
        })
Пример #4
0
    def test_registration_creates_active_user(self):
        """api creates active and signed in user on POST"""
        settings.override_setting('account_activation', 'none')

        response = self.client.post(
            self.api_link,
            data={
                'username': '******',
                'email': '*****@*****.**',
                'password': '******',
            },
        )

        self.assertContains(response, 'active')
        self.assertContains(response, 'Bob')
        self.assertContains(response, '*****@*****.**')

        UserModel.objects.get_by_username('Bob')

        test_user = UserModel.objects.get_by_email('*****@*****.**')
        self.assertEqual(Online.objects.filter(user=test_user).count(), 1)

        response = self.client.get(reverse('misago:index'))
        self.assertContains(response, 'Bob')

        self.assertIn('Welcome', mail.outbox[0].subject)
Пример #5
0
    def test_registration_creates_active_user(self):
        """api creates active and signed in user on POST"""
        settings.override_setting('account_activation', 'none')

        response = self.client.post('/api/users/',
                                    data={
                                        'username': '******',
                                        'email': '*****@*****.**',
                                        'password': '******'
                                    })

        self.assertEqual(response.status_code, 200)
        self.assertIn('active', response.content)
        self.assertIn('Bob', response.content)
        self.assertIn('*****@*****.**', response.content)

        User = get_user_model()
        User.objects.get_by_username('Bob')

        test_user = User.objects.get_by_email('*****@*****.**')
        self.assertEqual(Online.objects.filter(user=test_user).count(), 1)

        response = self.client.get(reverse('misago:index'))
        self.assertIn('Bob', response.content)

        self.assertIn('Welcome', mail.outbox[0].subject)
Пример #6
0
    def test_registration_off_request(self):
        """registrations off request errors with code 403"""
        settings.override_setting('account_activation', 'closed')

        response = self.client.post('/api/users/')
        self.assertEqual(response.status_code, 403)
        self.assertIn('closed', response.content)
Пример #7
0
    def test_registration_creates_active_user(self):
        """api creates active and signed in user on POST"""
        settings.override_setting('account_activation', 'none')

        response = self.client.post(
            self.api_link,
            data={
                'username': '******',
                'email': '*****@*****.**',
                'password': '******',
            },
        )

        self.assertContains(response, 'active')
        self.assertContains(response, 'Bob')
        self.assertContains(response, '*****@*****.**')

        UserModel.objects.get_by_username('Bob')

        test_user = UserModel.objects.get_by_email('*****@*****.**')
        self.assertEqual(Online.objects.filter(user=test_user).count(), 1)

        self.assertTrue(test_user.check_password('pass123'))

        auth_json = self.client.get(reverse('misago:api:auth')).json()
        self.assertTrue(auth_json['is_authenticated'])
        self.assertEqual(auth_json['username'], 'Bob')

        self.assertIn('Welcome', mail.outbox[0].subject)

        self.assertEqual(test_user.audittrail_set.count(), 1)
Пример #8
0
    def test_registration_off_request(self):
        """registrations off request errors with code 403"""
        settings.override_setting('account_activation', 'closed')

        response = self.client.post('/api/users/')
        self.assertEqual(response.status_code, 403)
        self.assertIn('closed', response.content)
Пример #9
0
    def test_registration_creates_user_with_whitespace_password(self):
        """api creates user with spaces around password"""
        settings.override_setting('account_activation', 'none')

        response = self.client.post(
            self.api_link,
            data={
                'username': '******',
                'email': '*****@*****.**',
                'password': '******',
            },
        )

        self.assertContains(response, 'active')
        self.assertContains(response, 'Bob')
        self.assertContains(response, '*****@*****.**')

        UserModel.objects.get_by_username('Bob')

        test_user = UserModel.objects.get_by_email('*****@*****.**')
        self.assertEqual(Online.objects.filter(user=test_user).count(), 1)

        self.assertTrue(test_user.check_password(' pass123 '))

        self.assertIn('Welcome', mail.outbox[0].subject)
Пример #10
0
    def test_context_processor_misago_tos(self):
        """context processor has TOS link to Misago view"""
        settings.override_setting('terms_of_service', 'Lorem ipsum')
        context_dict = legal_links(MockRequest())

        self.assertEqual(context_dict, {
            'TERMS_OF_SERVICE_URL': reverse('misago:terms-of-service')
        })
Пример #11
0
    def test_context_processor_misago_tos(self):
        """context processor has TOS link to Misago view"""
        settings.override_setting('terms_of_service', 'Lorem ipsum')
        context_dict = legal_links(MockRequest())

        self.assertEqual(
            context_dict,
            {'TERMS_OF_SERVICE_URL': reverse('misago:terms-of-service')})
Пример #12
0
    def test_context_processor_misago_policy(self):
        """context processor has TOS link to Misago view"""
        settings.override_setting('privacy_policy', 'Lorem ipsum')
        context_dict = legal_links(MockRequest())

        self.assertEqual(
            context_dict,
            {'PRIVACY_POLICY_URL': reverse('misago:privacy-policy')})
Пример #13
0
    def test_context_processor_misago_policy(self):
        """context processor has TOS link to Misago view"""
        settings.override_setting('privacy_policy', 'Lorem ipsum')
        context_dict = legal_links(MockRequest())

        self.assertEqual(context_dict, {
            'PRIVACY_POLICY_URL': reverse('misago:privacy-policy')
        })
Пример #14
0
    def test_registration_off_request(self):
        """registrations off request errors with code 403"""
        settings.override_setting('account_activation', 'closed')

        response = self.client.post(self.api_link)
        self.assertEqual(response.status_code, 403)
        self.assertEqual(response.json(), {
            'detail': "New users registrations are currently closed.",
        })
Пример #15
0
    def test_context_processor_misago_policy(self):
        """context processor has TOS link to Misago view"""
        request = MockRequest()

        settings.override_setting('privacy_policy', 'Lorem ipsum')
        legal_links(request)

        self.assertEqual(request.frontend_context['url'], {
            'privacy_policy': reverse('misago:privacy-policy'),
        })
Пример #16
0
    def test_301_on_link_policy(self):
        """policy view returns 302 redirect when link is set"""
        settings.override_setting('privacy_policy_link', 'http://test.com')
        settings.override_setting('privacy_policy', 'Lorem ipsum')
        self.assertTrue(settings.privacy_policy_link)
        self.assertTrue(settings.privacy_policy)

        response = self.client.get(reverse('misago:privacy-policy'))
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['location'], 'http://test.com')
Пример #17
0
    def test_301_on_link_tos(self):
        """TOS view returns 302 redirect when link is set"""
        settings.override_setting('terms_of_service_link', 'http://test.com')
        settings.override_setting('terms_of_service', 'Lorem ipsum')
        self.assertTrue(settings.terms_of_service_link)
        self.assertTrue(settings.terms_of_service)

        response = self.client.get(reverse('misago:terms-of-service'))
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['location'], 'http://test.com')
Пример #18
0
    def test_301_on_link_tos(self):
        """TOS view returns 302 redirect when link is set"""
        settings.override_setting('terms_of_service_link', 'http://test.com')
        settings.override_setting('terms_of_service', 'Lorem ipsum')
        self.assertTrue(settings.terms_of_service_link)
        self.assertTrue(settings.terms_of_service)

        response = self.client.get(reverse('misago:terms-of-service'))
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['location'], 'http://test.com')
Пример #19
0
    def test_301_on_link_policy(self):
        """policy view returns 302 redirect when link is set"""
        settings.override_setting('privacy_policy_link', 'http://test.com')
        settings.override_setting('privacy_policy', 'Lorem ipsum')
        self.assertTrue(settings.privacy_policy_link)
        self.assertTrue(settings.privacy_policy)

        response = self.client.get(reverse('misago:privacy-policy'))
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['location'], 'http://test.com')
Пример #20
0
    def test_200_on_link_policy(self):
        """policy view returns 200 when custom tos content is set"""
        settings.override_setting('privacy_policy_title', 'Test Policy')
        settings.override_setting('privacy_policy', 'Lorem ipsum dolor')
        self.assertTrue(settings.privacy_policy_title)
        self.assertTrue(settings.privacy_policy)

        response = self.client.get(reverse('misago:privacy-policy'))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'Test Policy')
        self.assertContains(response, 'Lorem ipsum dolor')
Пример #21
0
    def test_api_get_question(self):
        """qa api returns valid QA question"""
        settings.override_setting("qa_question", "Do you like pies?")
        settings.override_setting("qa_help_text", 'Type in "yes".')

        response = self.client.get(self.api_link)
        self.assertEqual(response.status_code, 200)

        response_json = json.loads(response.content)
        self.assertEqual(response_json["question"], "Do you like pies?")
        self.assertEqual(response_json["help_text"], 'Type in "yes".')
Пример #22
0
    def test_200_on_link_tos(self):
        """TOS view returns 200 when custom tos content is set"""
        settings.override_setting('terms_of_service_title', 'Test ToS')
        settings.override_setting('terms_of_service', 'Lorem ipsum dolor')
        self.assertTrue(settings.terms_of_service_title)
        self.assertTrue(settings.terms_of_service)

        response = self.client.get(reverse('misago:terms-of-service'))
        self.assertEqual(response.status_code, 200)
        self.assertIn('Test ToS', response.content)
        self.assertIn('Lorem ipsum dolor', response.content)
Пример #23
0
    def test_200_on_link_tos(self):
        """TOS view returns 200 when custom tos content is set"""
        settings.override_setting('terms_of_service_title', 'Test ToS')
        settings.override_setting('terms_of_service', 'Lorem ipsum dolor')
        self.assertTrue(settings.terms_of_service_title)
        self.assertTrue(settings.terms_of_service)

        response = self.client.get(reverse('misago:terms-of-service'))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'Test ToS')
        self.assertContains(response, 'Lorem ipsum dolor')
Пример #24
0
    def test_api_get_question(self):
        """qa api returns valid QA question"""
        settings.override_setting('qa_question', 'Do you like pies?')
        settings.override_setting('qa_help_text', 'Type in "yes".')

        response = self.client.get(self.api_link)
        self.assertEqual(response.status_code, 200)

        response_json = json.loads(smart_str(response.content))
        self.assertEqual(response_json['question'], 'Do you like pies?')
        self.assertEqual(response_json['help_text'], 'Type in "yes".')
Пример #25
0
    def test_200_on_link_policy(self):
        """policy view returns 200 when custom tos content is set"""
        settings.override_setting('privacy_policy_title', 'Test Policy')
        settings.override_setting('privacy_policy', 'Lorem ipsum dolor')
        self.assertTrue(settings.privacy_policy_title)
        self.assertTrue(settings.privacy_policy)

        response = self.client.get(reverse('misago:privacy-policy'))
        self.assertEqual(response.status_code, 200)
        self.assertIn('Test Policy', response.content)
        self.assertIn('Lorem ipsum dolor', response.content)
Пример #26
0
    def test_api_get_question(self):
        """qa api returns valid QA question"""
        settings.override_setting('qa_question', 'Do you like pies?')
        settings.override_setting('qa_help_text', 'Type in "yes".')

        response = self.client.get(self.api_link)
        self.assertEqual(response.status_code, 200)

        response_json = response.json()
        self.assertEqual(response_json['question'], 'Do you like pies?')
        self.assertEqual(response_json['help_text'], 'Type in "yes".')
Пример #27
0
    def test_register_decorator_calls_valid_view_200(self):
        """register decorator calls valid view"""
        settings.override_setting("account_activation", "disabled")

        response = self.client.get(reverse("misago:register"))
        self.assertEqual(response.status_code, 200)
        self.assertIn("new registrations are not currently accepted", response.content)

        settings.override_setting("account_activation", "none")
        response = self.client.get(reverse("misago:register"))
        self.assertEqual(response.status_code, 200)
        self.assertIn("Register new account", response.content)
Пример #28
0
    def test_context_processor_misago_tos(self):
        """context processor has TOS link to Misago view"""
        request = MockRequest()

        settings.override_setting('terms_of_service', 'Lorem ipsum')
        legal_links(request)

        self.assertEqual(
            request.frontend_context['url'], {
                'tos': reverse('misago:terms-of-service'),
            }
        )
Пример #29
0
    def test_register_decorator_calls_valid_view_200(self):
        """register decorator calls valid view"""
        settings.override_setting('account_activation', 'disabled')

        response = self.client.get(reverse('misago:register'))
        self.assertEqual(response.status_code, 200)
        self.assertIn('new registrations are not currently accepted',
                      response.content)

        settings.override_setting('account_activation', 'none')
        response = self.client.get(reverse('misago:register'))
        self.assertEqual(response.status_code, 200)
        self.assertIn('Register new account', response.content)
Пример #30
0
    def test_context_processor_remote_tos(self):
        """context processor has TOS link to remote url"""
        settings.override_setting('terms_of_service_link', 'http://test.com')
        context_dict = legal_links(MockRequest())

        self.assertEqual(context_dict,
                         {'TERMS_OF_SERVICE_URL': 'http://test.com'})

        # set misago view too
        settings.override_setting('terms_of_service', 'Lorem ipsum')
        context_dict = legal_links(MockRequest())

        self.assertEqual(context_dict,
                         {'TERMS_OF_SERVICE_URL': 'http://test.com'})
Пример #31
0
    def test_context_processor_remote_policy(self):
        """context processor has TOS link to remote url"""
        settings.override_setting('privacy_policy_link', 'http://test.com')
        context_dict = legal_links(MockRequest())

        self.assertEqual(context_dict,
                         {'PRIVACY_POLICY_URL': 'http://test.com'})

        # set misago view too
        settings.override_setting('privacy_policy', 'Lorem ipsum')
        context_dict = legal_links(MockRequest())

        self.assertEqual(context_dict,
                         {'PRIVACY_POLICY_URL': 'http://test.com'})
Пример #32
0
    def test_terms_of_service_responses(self):
        """/legal-pages/terms-of-policy/ returns valid json"""
        settings.override_setting(
            'terms_of_service_link', 'http://somewhere.com')
        settings.override_setting('terms_of_service', 'I am Bob Boberson!')

        response = self.client.get(reverse('misago:api:legal_page', kwargs={
            'page': 'terms-of-service'
        }))
        self.assertEqual(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEqual(data['id'], 'terms-of-service')
        self.assertEqual(data['link'], 'http://somewhere.com')
        self.assertEqual(data['body'], '<p>I am Bob Boberson!</p>')
Пример #33
0
    def test_terms_of_service_responses(self):
        """/legal-pages/terms-of-policy/ returns valid json"""
        settings.override_setting('terms_of_service_link',
                                  'http://somewhere.com')
        settings.override_setting('terms_of_service', 'I am Bob Boberson!')

        response = self.client.get(
            reverse('misago:api:legal_page',
                    kwargs={'page': 'terms-of-service'}))
        self.assertEqual(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEqual(data['id'], 'terms-of-service')
        self.assertEqual(data['link'], 'http://somewhere.com')
        self.assertEqual(data['body'], '<p>I am Bob Boberson!</p>')
Пример #34
0
    def test_context_processor_remote_policy(self):
        """context processor has TOS link to remote url"""
        settings.override_setting('privacy_policy_link', 'http://test.com')
        context_dict = legal_links(MockRequest())

        self.assertEqual(context_dict, {
            'PRIVACY_POLICY_URL': 'http://test.com'
        })

        # set misago view too
        settings.override_setting('privacy_policy', 'Lorem ipsum')
        context_dict = legal_links(MockRequest())

        self.assertEqual(context_dict, {
            'PRIVACY_POLICY_URL': 'http://test.com'
        })
Пример #35
0
    def test_context_processor_remote_tos(self):
        """context processor has TOS link to remote url"""
        settings.override_setting('terms_of_service_link', 'http://test.com')
        context_dict = legal_links(MockRequest())

        self.assertEqual(context_dict, {
            'TERMS_OF_SERVICE_URL': 'http://test.com'
        })

        # set misago view too
        settings.override_setting('terms_of_service', 'Lorem ipsum')
        context_dict = legal_links(MockRequest())

        self.assertEqual(context_dict, {
            'TERMS_OF_SERVICE_URL': 'http://test.com'
        })
Пример #36
0
    def test_register_view_post_creates_admin_activated_user(self):
        """register view creates admin activated user on POST"""
        settings.override_setting("account_activation", "admin")

        response = self.client.post(
            reverse("misago:register"), data={"username": "******", "email": "*****@*****.**", "password": "******"}
        )
        self.assertEqual(response.status_code, 302)

        response = self.client.get(reverse("misago:register_completed"))
        self.assertIn("administrator", response.content)

        User = get_user_model()
        User.objects.get_by_username("Bob")
        User.objects.get_by_email("*****@*****.**")

        self.assertIn("Welcome", mail.outbox[0].subject)
Пример #37
0
    def test_context_processor_remote_tos(self):
        """context processor has TOS link to remote url"""
        request = MockRequest()

        settings.override_setting('terms_of_service_link', 'http://test.com')
        legal_links(request)

        self.assertEqual(request.frontend_context['url'], {
            'tos': 'http://test.com',
        })

        # set misago view too
        settings.override_setting('terms_of_service', 'Lorem ipsum')
        legal_links(request)

        self.assertEqual(request.frontend_context['url'], {
            'tos': 'http://test.com',
        })
Пример #38
0
    def test_registration_creates_inactive_user(self):
        """api creates inactive user on POST"""
        settings.override_setting('account_activation', 'user')

        response = self.client.post(self.api_link, data={
            'username': '******',
            'email': '*****@*****.**',
            'password': '******'
        })

        self.assertContains(response, 'user')
        self.assertContains(response, 'Bob')
        self.assertContains(response, '*****@*****.**')

        User = get_user_model()
        User.objects.get_by_username('Bob')
        User.objects.get_by_email('*****@*****.**')

        self.assertIn('Welcome', mail.outbox[0].subject)
Пример #39
0
    def test_registration_creates_admin_activated_user(self):
        """api creates admin activated user on POST"""
        settings.override_setting('account_activation', 'admin')

        response = self.client.post('/api/users/',
                                    data={'username': '******',
                                          'email': '*****@*****.**',
                                          'password': '******'})

        self.assertEqual(response.status_code, 200)
        self.assertIn('admin', response.content)
        self.assertIn('Bob', response.content)
        self.assertIn('*****@*****.**', response.content)

        User = get_user_model()
        User.objects.get_by_username('Bob')
        User.objects.get_by_email('*****@*****.**')

        self.assertIn('Welcome', mail.outbox[0].subject)
Пример #40
0
    def test_registration_creates_admin_activated_user(self):
        """api creates admin activated user on POST"""
        settings.override_setting('account_activation', 'admin')

        response = self.client.post('/api/users/',
                                    data={'username': '******',
                                          'email': '*****@*****.**',
                                          'password': '******'})

        self.assertEqual(response.status_code, 200)
        self.assertIn('activation_by_admin', response.content)
        self.assertIn('Bob', response.content)
        self.assertIn('*****@*****.**', response.content)

        User = get_user_model()
        User.objects.get_by_username('Bob')
        User.objects.get_by_email('*****@*****.**')

        self.assertIn('Welcome', mail.outbox[0].subject)
Пример #41
0
    def test_registration_creates_admin_activated_user(self):
        """api creates admin activated user on POST"""
        settings.override_setting('account_activation', 'admin')

        response = self.client.post(self.api_link,
                                    data={
                                        'username': '******',
                                        'email': '*****@*****.**',
                                        'password': '******'
                                    })

        self.assertContains(response, 'admin')
        self.assertContains(response, 'Bob')
        self.assertContains(response, '*****@*****.**')

        UserModel.objects.get_by_username('Bob')
        UserModel.objects.get_by_email('*****@*****.**')

        self.assertIn('Welcome', mail.outbox[0].subject)
Пример #42
0
    def test_register_view_post_creates_admin_activated_user(self):
        """register view creates admin activated user on POST"""
        settings.override_setting('account_activation', 'admin')

        response = self.client.post(reverse('misago:register'),
                                    data={
                                        'username': '******',
                                        'email': '*****@*****.**',
                                        'password': '******'
                                    })
        self.assertEqual(response.status_code, 302)

        response = self.client.get(reverse('misago:register_completed'))
        self.assertIn('administrator', response.content)

        User = get_user_model()
        User.objects.get_by_username('Bob')
        User.objects.get_by_email('*****@*****.**')

        self.assertIn('Welcome', mail.outbox[0].subject)
Пример #43
0
    def test_registration_creates_inactive_user(self):
        """api creates inactive user on POST"""
        settings.override_setting('account_activation', 'user')

        response = self.client.post('/api/users/',
                                    data={
                                        'username': '******',
                                        'email': '*****@*****.**',
                                        'password': '******'
                                    })

        self.assertContains(response, 'user')
        self.assertContains(response, 'Bob')
        self.assertContains(response, '*****@*****.**')

        User = get_user_model()
        User.objects.get_by_username('Bob')
        User.objects.get_by_email('*****@*****.**')

        self.assertIn('Welcome', mail.outbox[0].subject)
Пример #44
0
    def test_404_responses(self):
        """/legal-pages/ api returns 404 for unset pages"""
        settings.override_setting('privacy_policy_link', '')
        settings.override_setting('privacy_policy', '')
        settings.override_setting('terms_of_service_link', '')
        settings.override_setting('terms_of_service', '')

        response = self.client.get(reverse('misago:api:legal_page', kwargs={
            'page': 'privacy-policy'
        }))
        self.assertEqual(response.status_code, 404)

        response = self.client.get(reverse('misago:api:legal_page', kwargs={
            'page': 'terms-of-service'
        }))
        self.assertEqual(response.status_code, 404)
Пример #45
0
    def test_404_responses(self):
        """/legal-pages/ api returns 404 for unset pages"""
        settings.override_setting('privacy_policy_link', '')
        settings.override_setting('privacy_policy', '')
        settings.override_setting('terms_of_service_link', '')
        settings.override_setting('terms_of_service', '')

        response = self.client.get(
            reverse('misago:api:legal_page', kwargs={'page':
                                                     'privacy-policy'}))
        self.assertEqual(response.status_code, 404)

        response = self.client.get(
            reverse('misago:api:legal_page',
                    kwargs={'page': 'terms-of-service'}))
        self.assertEqual(response.status_code, 404)
Пример #46
0
    def test_registration_creates_inactive_user(self):
        """api creates inactive user on POST"""
        settings.override_setting('account_activation', 'user')

        response = self.client.post(
            self.api_link,
            data={
                'username': '******',
                'email': '*****@*****.**',
                'password': '******',
            },
        )

        self.assertEqual(response.json(), {
            'activation': 'user',
            'username': '******',
            'email': '*****@*****.**',
        })

        UserModel.objects.get_by_username('Bob')
        UserModel.objects.get_by_email('*****@*****.**')

        self.assertIn('Welcome', mail.outbox[0].subject)
Пример #47
0
    def test_registration_creates_active_user(self):
        """api creates active and signed in user on POST"""
        settings.override_setting('account_activation', 'none')

        response = self.client.post('/api/users/',
                                    data={'username': '******',
                                          'email': '*****@*****.**',
                                          'password': '******'})

        self.assertEqual(response.status_code, 200)
        self.assertIn('active', response.content)
        self.assertIn('Bob', response.content)
        self.assertIn('*****@*****.**', response.content)

        User = get_user_model()
        User.objects.get_by_username('Bob')

        test_user = User.objects.get_by_email('*****@*****.**')
        self.assertEqual(Online.objects.filter(user=test_user).count(), 1)

        response = self.client.get(reverse('misago:index'))
        self.assertIn('Bob', response.content)

        self.assertIn('Welcome', mail.outbox[0].subject)
Пример #48
0
    def test_registration_off_request(self):
        """registrations off request errors with code 403"""
        settings.override_setting('account_activation', 'closed')

        response = self.client.post(self.api_link)
        self.assertContains(response, 'closed', status_code=403)
Пример #49
0
    def test_api_no_qa_is_set(self):
        """qa api returns 404 if no QA question is set"""
        settings.override_setting('qa_question', '')

        response = self.client.get(self.api_link)
        self.assertEqual(response.status_code, 404)
Пример #50
0
    def test_registration_off_request(self):
        """registrations off request errors with code 403"""
        settings.override_setting('account_activation', 'closed')

        response = self.client.post(self.api_link)
        self.assertContains(response, 'closed', status_code=403)
Пример #51
0
    def test_api_no_qa_is_set(self):
        """qa api returns 404 if no QA question is set"""
        settings.override_setting('qa_question', '')

        response = self.client.get(self.api_link)
        self.assertEqual(response.status_code, 404)
Пример #52
0
    def test_api_invalid_qa_id(self):
        """qa api returns QA question only for ID #1"""
        settings.override_setting('qa_question', 'Do you like pies?')

        response = self.client.get(self.api_link.replace('1', '24'))
        self.assertEqual(response.status_code, 404)