Exemple #1
0
    def test_requires_password(self):
        serializer = RegisterSerializer(data={
            'email': '*****@*****.**',
            'public_key': serialize_public_key(PUBLIC_KEY)
        })

        assert not serializer.is_valid()
        assert serializer.errors == {'password': ['This field is required.']}
Exemple #2
0
    def test_create(self):
        serializer = RegisterSerializer(data={
            'password': '******',
            'email': '*****@*****.**',
            'public_key': serialize_public_key(PUBLIC_KEY),
        })

        assert serializer.is_valid()

        user = serializer.save()
        assert user.email == '*****@*****.**'
        assert user.devices.count() == 1
        assert user.devices.first().fingerprint == 'e777 c552 5bab 7d95  58dc bb8d 6cd5 daf0'
Exemple #3
0
    def test_register_invalid_email_unique(self):
        url = reverse('api:register')

        User.objects.create(email='*****@*****.**')
        response = APIClient().post(url, data={
            'email': '*****@*****.**',
            'password': '******',
            'public_key': serialize_public_key(PUBLIC_KEY)
        })

        assert response.status_code == 400
        assert response.json() == {
            'email': ['User with this Email already exists.']
        }
Exemple #4
0
    def test_simple_register(self):
        url = reverse('api:register')

        response = APIClient().post(url, data={
            'email': '*****@*****.**',
            'password': '******',
            'public_key': serialize_public_key(PUBLIC_KEY)
        })

        assert response.status_code == 201
        assert response.json() == {
            'email': '*****@*****.**',
            'device_id': mock.ANY
        }
        assert User.objects.filter(email='*****@*****.**').exists()
Exemple #5
0
    def test_validates_password(self):
        serializer = RegisterSerializer(data={
            'password': '******',
            'email': '*****@*****.**',
            'public_key': serialize_public_key(PUBLIC_KEY)
        })

        assert not serializer.is_valid()

        # We're configuring to at least 10 characters.
        assert serializer.errors == {
            'password': [
                'This password is too short. It must contain at '
                'least 10 characters.'
            ]
        }
Exemple #6
0
    def test_register_invalid_email(self):
        url = reverse('api:register')

        response = APIClient().post(url, data={
            'email': 'test',
            'password': '******',
            'public_key': serialize_public_key(PUBLIC_KEY)
        })

        assert response.status_code == 400
        assert response.json() == {
            'email': ['Enter a valid email address.']
        }

        assert User.objects.all().count() == 0
        assert Device.objects.all().count() == 0
Exemple #7
0
    def test_register_invalid_password(self):
        url = reverse('api:register')

        response = APIClient().post(url, data={
            'email': '*****@*****.**',
            'password': '******',
            'public_key': serialize_public_key(PUBLIC_KEY)
        })

        assert response.status_code == 400
        assert response.json() == {
            'password': [
                'This password is too short. It must contain at least 10 characters.',
                'This password is too common.',
                'This password is entirely numeric.'
            ]
        }

        # Make sure we never created a user or device
        assert User.objects.all().count() == 0
        assert Device.objects.all().count() == 0