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

감사합니다 #48

Open
wants to merge 2 commits into
base: practice/start
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/swpp-p7-django-advanced-and-tests.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified toh/db.sqlite3
Binary file not shown.
4 changes: 4 additions & 0 deletions toh/hero/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from django.contrib import admin
from .models import Hero


admin.site.register(Hero)

# Register your models here.
21 changes: 19 additions & 2 deletions toh/hero/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
from django.test import TestCase
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='Superman')
Hero.objects.create(name='Batman')
Hero.objects.create(name='Spiderman')

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

def test_assertCounter(self):
client1 = Client()
response = client1.get('/hero/')
self.assertIn('1', response.content.decode())

response = client1.get('/hero/')
self.assertIn('2', response.content.decode())
2 changes: 1 addition & 1 deletion toh/hero/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from . import views

urlpatterns = [
path('', views.hero_list),
path('', views.index),
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'),
Expand Down
11 changes: 9 additions & 2 deletions toh/hero/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
from json.decoder import JSONDecodeError
from .models import Hero

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

def index(request):
if 'visit_count' not in request.session:
request.session['visit_count'] = 1
else:
request.session['visit_count'] += 1
return HttpResponse('Hello, world! You visited {} times.\n'.format(request.session['visit_count']))


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


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

Expand Down