Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done #54

Open
wants to merge 1 commit into
base: practice/start
Choose a base branch
from
Open

done #54

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docker/.bash_history
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ls
cd toh
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
python manage.py runserver 0.0.0.0:80000
python manage.py runserver 0.0.0.0:8000
clear
python manage.py test
pip install coverage
clear
coverage run --source='.' manage.py test hero
coverage report
coverage run --source='.' manage.py test hero
coverage report
coverage run --source='.' manage.py test hero
coverage report
coverage run --source='.' manage.py test hero
coverage report
coverage run --source='.' manage.py test hero
coverage report
python manage.py runserver 0.0.0.0:8000
python manage.py runserver 0.0.0.0:8000
python manage.py makemigrations
python manage.py runserver 0.0.0.0:8000
python manage.py runserver 0.0.0.0:8000
clear
Binary file modified toh/db.sqlite3
Binary file not shown.
Binary file modified toh/hero/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file modified toh/hero/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file modified toh/hero/__pycache__/apps.cpython-39.pyc
Binary file not shown.
Binary file modified toh/hero/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file modified toh/hero/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file modified toh/hero/__pycache__/views.cpython-39.pyc
Binary file not shown.
4 changes: 3 additions & 1 deletion toh/hero/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.contrib import admin

from .models import Hero
# Register your models here.

admin.site.register(Hero)
Binary file modified toh/hero/migrations/__pycache__/0001_initial.cpython-39.pyc
Binary file not shown.
Binary file modified toh/hero/migrations/__pycache__/0002_hero_age.cpython-39.pyc
Binary file not shown.
Binary file modified toh/hero/migrations/__pycache__/0003_team.cpython-39.pyc
Binary file not shown.
Binary file modified toh/hero/migrations/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
31 changes: 29 additions & 2 deletions toh/hero/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
from django.test import TestCase

from http import client
from urllib import response
from django.test import TestCase, Client
from .models import Hero
# Create your tests here.


class HeroTestCase(TestCase):
def setUp(self) -> None:
Hero.objects.create(name='ironman1')
Hero.objects.create(name='ironman2')
Hero.objects.create(name='ironman3')

def test_hero_count(self):
self.assertEqual(Hero.objects.all().count(), 3)

def test_hero_id(self):
client = Client()
response = client.get('/hero/1/')

self.assertEqual(response.status_code, 200)
self.assertIn('1', response.content.decode())

def test_response_id(self):
client = Client()
resp1 = client.get('/hero/1/')
resp2 = client.get('/hero/2/')

self.assertIn('1', resp1.content.decode())
self.assertIn('2', resp2.content.decode())
3 changes: 2 additions & 1 deletion toh/hero/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from . import views

urlpatterns = [
path('token/', views.token, name='token'),
path('', views.hero_list),
path('<int:id>/', views.id, name='hero_id'),
path('<str:name>/', views.name, name='hero_name'),
path('info/<int:id>/', views.hero_info, name='hero_info'),
]
]
16 changes: 14 additions & 2 deletions toh/hero/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
import json
from json.decoder import JSONDecodeError
from .models import Hero
from django.views.decorators.csrf import ensure_csrf_cookie

# def index(request):
# return HttpResponse('Hello, world!')


def id(request, id):
return HttpResponse(f'Your id is {id}!')


def name(request, name):
return HttpResponse(f'Your name is {name}!')

@csrf_exempt

def hero_list(request):
if request.method == 'GET':
hero_all_list = [hero for hero in Hero.objects.all().values()]
Expand All @@ -31,6 +34,7 @@ def hero_list(request):
else:
return HttpResponseNotAllowed(['GET', 'POST'])


@csrf_exempt
def hero_info(request, id):
if request.method == 'GET':
Expand All @@ -50,4 +54,12 @@ def hero_info(request, id):
response_dict = {"id": hero.id, "name": hero.name, "age": hero.age}
return JsonResponse(response_dict, status=200)
else:
return HttpResponseNotAllowed(['GET', 'PUT'])
return HttpResponseNotAllowed(['GET', 'PUT'])


@ensure_csrf_cookie
def token(request):
if request.method == 'GET':
return HttpResponse(status=204)
else:
return HttpResponseNotAllowed(['GET'])
Binary file modified toh/toh/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file modified toh/toh/__pycache__/settings.cpython-39.pyc
Binary file not shown.
Binary file modified toh/toh/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file modified toh/toh/__pycache__/wsgi.cpython-39.pyc
Binary file not shown.