Example #1
0
    def test_requires_public_key(self):
        serializer = RegisterSerializer(data={
            'email': '*****@*****.**',
            'password': '******',
        })

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

        assert not serializer.is_valid()
        assert serializer.errors == {'email': ['This field is required.']}
Example #3
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'
Example #4
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.'
            ]
        }