How to use the djet.assertions.InstanceAssertionsMixin 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 / django-rest-multitoken / testproject / testapp / tests.py View on Github external
def create_user(**kwargs):
    data = {
        'username': 'john',
        'password': 'secret',
        'email': 'john@beatles.com',
    }
    data.update(kwargs)
    user = get_user_model().objects.create_user(**data)
    user.raw_password = data['password']
    return user


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

    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,
            'client': 'my-device',
        }
        user_logged_in.connect(self.signal_receiver)
github mapoio / TaskApp / TaskApp / tests.py View on Github external
def create_user(**kwargs):
    data = {
        'username': 'john',
        'password': 'secret',
        'email': 'john@beatles.com',
    }
    data.update(kwargs)
    user = get_user_model().objects.create_user(**data)
    user.raw_password = data['password']
    return user


class RegistrationViewTest(restframework.APIViewTestCase,
                           assertions.StatusCodeAssertionsMixin,
                           assertions.EmailAssertionsMixin,
                           assertions.InstanceAssertionsMixin):
    view_class = djoser.views.RegistrationView

    def test_post_should_create_user_without_login(self):
        data = {
            'username': 'john',
            'password': 'secret',
            'csrftoken': 'asdf',
        }
        request = self.factory.post(data=data)

        response = self.view(request)

        self.assert_status_equal(response, status.HTTP_201_CREATED)
        self.assertTrue('password' not in response.data)
        self.assert_instance_exists(get_user_model(), username=data['username'])
        user = get_user_model().objects.get(username=data['username'])
github mapoio / TaskApp / TaskApp / tests.py View on Github external
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,
        }
        user_logged_in.connect(self.signal_receiver)
        request = self.factory.post(data=data)
github sunscrapers / djoser / testproject / testapp / tests.py View on Github external
def test_get_should_return_urls_mapping(self):
        request = self.factory.get()
        view_object = self.create_view_object(request)

        response = view_object.dispatch(request)

        self.assert_status_equal(response, status.HTTP_200_OK)
        for key in view_object.get_urls_mapping().keys():
            self.assertIn(key, response.data)


class RegistrationViewTest(restframework.APIViewTestCase,
                           assertions.StatusCodeAssertionsMixin,
                           assertions.EmailAssertionsMixin,
                           assertions.InstanceAssertionsMixin):
    view_class = djoser.views.RegistrationView

    def test_post_should_create_user_without_login(self):
        data = {
            'username': 'john',
            'password': 'secret',
            'csrftoken': 'asdf',
        }
        request = self.factory.post(data=data)

        response = self.view(request)

        self.assert_status_equal(response, status.HTTP_201_CREATED)
        self.assertTrue('password' not in response.data)
        self.assert_instance_exists(get_user_model(), username=data['username'])
        user = get_user_model().objects.get(username=data['username'])
github sunscrapers / djoser / testproject / testapp / tests.py View on Github external
'email': 'john@beatles.com',
            'password': 'secret',
        }

        request = self.factory.post(data=data)
        response = self.view(request)

        self.assert_status_equal(response, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data, [djoser.constants.CANNOT_CREATE_USER_ERROR]
        )


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,
        }
        user_logged_in.connect(self.signal_receiver)
        request = self.factory.post(data=data)
github sunscrapers / djet / djet / assertions.py View on Github external
>>> with self.assert_instance_deleted(Article, slug='lorem-ipsum'):
        ...     Article.objects.get(slug='lorem-ipsum').delete()
        """
        return _InstanceContext(
            self.assert_instance_exists,
            self.assert_instance_does_not_exist,
            model_class,
            **kwargs
        )


class CompleteAssertionsMixin(
    StatusCodeAssertionsMixin,
    EmailAssertionsMixin,
    MessagesAssertionsMixin,
    InstanceAssertionsMixin,
):
    pass