How to use the djet.restframework function in djet

To help you get started, we’ve selected a few djet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sunscrapers / djoser / testproject / testapp / tests.py View on Github external
def test_djoser_simple_setting_overriden(self):
        from djoser.conf import settings as djoser_settings
        self.assertTrue(djoser_settings.USE_HTML_EMAIL_TEMPLATES)


    @override_settings(DJOSER=dict(settings.DJOSER, **{'SERIALIZERS': {'user': 'some.serializer'}}))
    def test_djoser_dict_setting_overriden(self):
        from djoser.conf import settings as djoser_settings
        self.assertEqual(djoser_settings.SERIALIZERS['user'], 'some.serializer')

    def test_djoser_settings_compat_method(self):
        from djoser.conf import settings as djoser_settings
        self.assertFalse(djoser_settings.get('USE_HTML_EMAIL_TEMPLATES'))


class TestDjoserViewsSupportActionAttribute(restframework.APIViewTestCase):
    # any arbitraty view from djoser
    view_class = djoser.views.UserView

    def test_action_reflect_http_method(self):
        request = self.factory.get()

        view = self.view_class()
        view.action_map = {'get': 'retrieve'}

        # reproduce DRF wrapping
        with override_method(view, Request(request), 'GET') as request:
            view.dispatch(request)
            self.assertEqual(view.action, 'retrieve')
github sunscrapers / django-rest-multitoken / testproject / testapp / tests.py View on Github external
'username': 'wrong username',
            'password': 'wrong password',
            'client': 'my-device',
        }
        user_logged_in.connect(self.signal_receiver)
        request = self.factory.post(data=data)

        response = self.view(request)

        self.assert_status_equal(response, status.HTTP_400_BAD_REQUEST)
        with self.assertRaises(models.Token.DoesNotExist):
            user.auth_tokens.get()
        self.assertFalse(self.signal_sent)


class LogoutViewTest(restframework.APIViewTestCase,
                     assertions.StatusCodeAssertionsMixin):
    view_class = views.InvalidateTokenView

    def test_post_should_logout_logged_in_user(self):
        user = create_user()
        token = models.Token.objects.create(user=user, client='my-device')

        request = self.factory.post(user=user, token=token)
        response = self.view(request)

        self.assert_status_equal(response, status.HTTP_200_OK)
        self.assertEqual(response.data, None)
        with self.assertRaises(models.Token.DoesNotExist):
            utils.refresh(token)

    def test_post_should_deny_logging_out_when_user_not_logged_in(self):
github mapoio / TaskApp / TaskApp / tests.py View on Github external
def test_post_should_not_register_if_fails_password_validation(self):
        data = {
            'username': 'john',
            'password': '',
            'csrftoken': 'asdf',
        }
        request = self.factory.post(data=data)

        response = self.view(request)

        self.assert_status_equal(response, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, {'password': ['该字段不能为空。']})


class LoginViewTest(restframework.APIViewTestCase,
                    assertions.StatusCodeAssertionsMixin,
                    assertions.InstanceAssertionsMixin):
    view_class = djoser.views.LoginView

    def setUp(self):
        self.signal_sent = False

    def signal_receiver(self, *args, **kwargs):
        self.signal_sent = True

    def test_post_should_login_user(self):
        user = create_user()
        data = {
            'username': user.username,
            'password': user.raw_password,
        }