def user_detail(request, id): """ Retrieve, update or delete a server assets instance. """ try: snippet = User.objects.get(id=id) except User.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': serializer = serializers.UserSerializer(snippet) return Response(serializer.data) elif request.method == 'POST': serializer = serializers.UserSerializer(snippet, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) elif request.method == 'DELETE': if not request.user.has_perm('OpsManage.delete_user'): return Response(status=status.HTTP_403_FORBIDDEN) snippet.delete() return Response(status=status.HTTP_204_NO_CONTENT)
def user_list(request, ): """ List all order, or create a server assets order. """ if request.method == 'GET': snippets = User.objects.all() serializer = serializers.UserSerializer(snippets, many=True) return Response(serializer.data) elif request.method == 'POST': serializer = serializers.UserSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def test_serialization(): """A simple serialization test case.""" user = baker.make(get_user_model()) serializer = serializers.UserSerializer(user) data = serializer.data assert data == { 'id': user.pk, 'username': user.username, 'first_name': user.first_name, 'last_name': user.last_name, 'email': user.email, 'quotes': [], }
def test_serialization(): """A simple serialization test case.""" user = baker.make(get_user_model()) serializer = serializers.UserSerializer(user) data = serializer.data assert data == { "id": user.pk, "username": user.username, "first_name": user.first_name, "last_name": user.last_name, "email": user.email, "quotes": [], }
def testSerialization(self): """A simple serialization test case.""" user = mommy.make(get_user_model(), flattr='flttr', twitter='twttr') serializer = serializers.UserSerializer(user) data = serializer.data url = reverse('api:user_detail', args=(user.pk, )) self.assertEqual( data, { 'url': url, 'username': user.username, 'first_name': user.first_name, 'last_name': user.last_name, 'email': user.email, 'flattr': 'flttr', 'twitter': 'twttr' })