예제 #1
0
    def post(self, request, format=None):
        response_data = {}
        serializer = UserRegistrationSerializer(data=request.data)
        if serializer.is_valid(raise_exception=True):
            account = serializer.save()
            response_data['response'] = 'successfully registered new user.'
        else:
            response_data = serializer.errors

        return Response(response_data)
예제 #2
0
    def create(self, request, *args, **kwargs):
        serializer = UserRegistrationSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user = serializer.save()

        # TODO
        # send email

        return Response(
            {"message": f"Registration successful, check your email: {user}"},
            status=status.HTTP_201_CREATED,
        )
예제 #3
0
 def test_fields(self):
     serializer = UserRegistrationSerializer()
     self.assert_fields_required(True, serializer, self.required_fields)
     self.assert_fields_required(False, serializer,
                                 self.not_required_fields)
     self.assertEqual(
         len(serializer.fields),
         len(self.required_fields) + len(self.not_required_fields))
예제 #4
0
    def post(self, request, format=None):
        response_data = {}
        serializer = UserRegistrationSerializer(data=request.data)
        if serializer.is_valid(raise_exception=True):
            account = serializer.save()
            response_data['response'] = 'successfully registered new user.'
            response_data['email'] = account.email
            response_data['username'] = account.username
            response_data['pk'] = account.pk
            signals.user_registered.send(sender=self.__class__,
                                         user=account,
                                         request=self.request)
            #after creating user send and activation mail to user
            context = {"user": account}
            to = [get_user_email(account)]
            ActivationEmail(self.request, context).send(to)
        else:
            response_data = serializer.errors

        return Response(response_data)
예제 #5
0
    def test_get_list(self):
        search_for = 'lice'
        res = User.objects.filter(
            Q(first_name__icontains=search_for)
            | Q(last_name__icontains=search_for)).distinct()

        serializer = UserRegistrationSerializer(res, many=True)

        url = api_reverse('accounts:user-list') + f'?first_name={ search_for }'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()[0]["first_name"],
                         serializer.data[0]["first_name"])
예제 #6
0
def test_user_registration_serializer(user_data, users_reg_key):
    serializer = UserRegistrationSerializer(instance=user_data)
    data = serializer.data
    assert set(data.keys()) == set(users_reg_key)
    for key in users_reg_key:
        assert data[key] == user_data[key]