from django.core.management import call_command
from django.test import TestCase
from django.utils.six import StringIO

from hobbies.models import Hobbie


class RandomUserTest(TestCase):
    def test_command_output(self):
        hobbies = [
            'Natacion', 'Voleibol', 'Futbol', 'Correr', 'Estudiar', 'Comer',
            'Caminar', 'Musica', 'Programar'
        ]

        for hobbie in hobbies:
            hob = Hobbie(name=hobbie)
            hob.save()
        out = StringIO()
        call_command('random_user', 4, stdout=out)
        self.assertIn('Successfully created users', out.getvalue())

@@ -1,20 +1,32 @@
+import json%0A
 from django.core.man
@@ -86,16 +86,48 @@
 estCase%0A
+from django.urls import reverse%0A
 from dja
@@ -155,16 +155,94 @@
 StringIO
+%0Afrom rest_framework import status%0Afrom rest_framework.test import APITestCase
 %0A%0Afrom h
@@ -270,16 +270,42 @@
 Hobbie%0A%0A
+from .models import User%0A%0A
 %0Aclass R
@@ -364,16 +364,60 @@
 (self):%0A
+        %22%22%22Creation new hobbies for test%22%22%22%0A
         
@@ -560,17 +560,16 @@
       %5D%0A
-%0A
         
@@ -728,16 +728,16 @@
 ut=out)%0A
-
         
@@ -796,8 +796,1173 @@
 alue())%0A
+%0A%0Aclass AccountTests(APITestCase):%0A    def test_create_user(self):%0A        %22%22%22%0A        Ensure we can create a new User.%0A        %22%22%22%0A        url = reverse('users-list')%0A        data = %7B%0A            %22age%22: 30,%0A            %22genre%22: %22Male%22,%0A            %22hobbies%22: %5B%0A                %7B%0A                    %22name%22: %22Prueba%22%0A                %7D,%0A                %7B%0A                    %22name%22: %22test%22%0A                %7D%0A            %5D,%0A            %22last_name%22: %22Rosales%22,%0A            %22name%22: %22Alejandro%22%0A        %7D%0A        response = self.client.post(url, data, format='json')%0A        json_response = json.loads(response.content.decode(%22utf-8%22))%0A        # Add Id%0A        data%5B'id'%5D = 1%0A        # Comparation result%0A        self.assertEqual(response.status_code, status.HTTP_201_CREATED)%0A        self.assertEqual(json_response, data)%0A        self.assertEqual(User.objects.count(), 1)%0A        self.assertEqual(User.objects.get().age, 30)%0A        self.assertEqual(User.objects.get().genre.name, 'Male')%0A        self.assertEqual(User.objects.get().id, 1)%0A        self.assertEqual(User.objects.get().last_name, 'Rosales')%0A        self.assertEqual(User.objects.get().name, 'Alejandro')%0A

Create Test for api