示例#1
0
    def test_create_user_with_too_long_username(self):

        long_name = \
            ("badnametoolongasdfjdsklafjdklsajf"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj"
             "lkjdslakfjkldsajflkjdsalkjfldskaflksj")
        data = {
            'username': long_name,
            'email': '*****@*****.**',
            'password': '******'
        }

        request = self.factory.post(self.create_url, data, format='json')
        view = UserViewSet.as_view({"post": "create"})
        response = view(request)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(User.objects.count(), 1)
        self.assertEqual(response.data, "username too long")
示例#2
0
    def test_create_user_with_no_email(self):
        data = {'username': '******', 'email': '', 'password': '******'}

        request = self.factory.post(self.create_url, data, format='json')
        view = UserViewSet.as_view({"post": "create"})
        response = view(request)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(User.objects.count(), 1)
        self.assertEqual(response.data, "missing email address")
示例#3
0
    def test_create_user_with_preexisting_email(self):
        data = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******'
        }

        request = self.factory.post(self.create_url, data, format='json')
        view = UserViewSet.as_view({"post": "create"})
        response = view(request)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(User.objects.count(), 1)
        self.assertEqual(response.data,
                         "email '*****@*****.**' is already in use")
示例#4
0
    def test_create_user_with_short_password(self):
        """
        Ensures user is not created for password lengths less than 8.
        """

        data = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******'
        }

        request = self.factory.post(self.create_url, data, format='json')
        view = UserViewSet.as_view({"post": "create"})
        response = view(request)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(User.objects.count(), 1)
        self.assertEqual(response.data, "password too short")
示例#5
0
    def test_create_user(self):
        """
        Ensure we can create a new user and a valid token is created with it.
        """
        data = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******'
        }

        request = self.factory.post(self.create_url, data, format='json')
        view = UserViewSet.as_view({"post": "create"})
        response = view(request)
        self.assertEqual(User.objects.count(), 2)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(response.data['username'], data['username'])
        self.assertEqual(response.data['email'], data['email'])
        self.assertFalse('password' in response.data)