Skip to content

Commit 6ee8940

Browse files
committed
more listing fixes in 22
1 parent c9c12de commit 6ee8940

File tree

2 files changed

+43
-31
lines changed

2 files changed

+43
-31
lines changed

chapter_22_outside_in.asciidoc

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ Currently there's no place in our base template for us to put any new content.
386386
Also, the "My Lists" page doesn't need the new item form,
387387
so we'll put that into a block too, making it optional:
388388

389+
390+
389391
[role="sourcecode"]
390392
.src/lists/templates/base.html (ch22l011-1)
391393
====
@@ -442,6 +444,8 @@ so we'll put that into a block too, making it optional:
442444
Meanwhile, in _my_lists.html_ we override the `list_form`
443445
and say it should be empty...
444446

447+
// TODO: proper commits for these
448+
445449
[role="sourcecode"]
446450
.src/lists/templates/my_lists.html
447451
====
@@ -540,18 +544,20 @@ In this case, the list owner:
540544
[source,python]
541545
----
542546
from django.contrib.auth import get_user_model
547+
543548
User = get_user_model()
544549
[...]
545-
class MyListsTest(TestCase):
546550
551+
552+
class MyListsTest(TestCase):
547553
def test_my_lists_url_renders_my_lists_template(self):
548554
[...]
549555
550556
def test_passes_correct_owner_to_template(self):
551-
User.objects.create(email='[email protected]')
552-
correct_user = User.objects.create(email='[email protected]')
553-
response = self.client.get('/lists/users/[email protected]/')
554-
self.assertEqual(response.context['owner'], correct_user)
557+
User.objects.create(email="[email protected]")
558+
correct_user = User.objects.create(email="[email protected]")
559+
response = self.client.get("/lists/users/[email protected]/")
560+
self.assertEqual(response.context["owner"], correct_user)
555561
----
556562
====
557563

@@ -569,12 +575,14 @@ So:
569575
[source,python]
570576
----
571577
from django.contrib.auth import get_user_model
578+
572579
User = get_user_model()
573580
[...]
574581
582+
575583
def my_lists(request, email):
576584
owner = User.objects.get(email=email)
577-
return render(request, 'my_lists.html', {'owner': owner})
585+
return render(request, "my_lists.html", {"owner": owner})
578586
----
579587
====
580588

@@ -588,7 +596,7 @@ the previous test. We just need to add a user for it as well:
588596
[source,python]
589597
----
590598
def test_my_lists_url_renders_my_lists_template(self):
591-
User.objects.create(email='[email protected]')
599+
User.objects.create(email="[email protected]")
592600
[...]
593601
----
594602
====
@@ -666,7 +674,8 @@ But it won't actually work, because we don't know how to save a list owner yet:
666674

667675

668676
----
669-
self.assertEqual(list_.owner, user)
677+
self.assertEqual(new_list.owner, user)
678+
^^^^^^^^^^^^^^
670679
AttributeError: 'List' object has no attribute 'owner'
671680
----
672681

@@ -722,30 +731,31 @@ Let's write a test for that:
722731

723732

724733
[role="sourcecode"]
725-
.lists/tests/test_models.py (ch22l018)
734+
.src/lists/tests/test_models.py (ch22l018)
726735
====
727736
[source,python]
728737
----
729738
from django.contrib.auth import get_user_model
739+
730740
User = get_user_model()
731741
[...]
732742
733-
class ListModelTest(TestCase):
734743
744+
class ListModelTest(TestCase):
735745
def test_get_absolute_url(self):
736746
[...]
737747
738748
def test_lists_can_have_owners(self):
739-
user = User.objects.create(email='[email protected]')
740-
list_ = List.objects.create(owner=user)
741-
self.assertIn(list_, user.list_set.all())
749+
user = User.objects.create(email="[email protected]")
750+
mylist = List.objects.create(owner=user)
751+
self.assertIn(mylist, user.list_set.all())
742752
----
743753
====
744754

745755
And that gives us a new unit test failure:
746756

747757
----
748-
list_ = List.objects.create(owner=user)
758+
mylist = List.objects.create(owner=user)
749759
[...]
750760
TypeError: 'owner' is an invalid keyword argument for this function
751761
----
@@ -768,7 +778,7 @@ that too:
768778

769779

770780
[role="sourcecode"]
771-
.lists/tests/test_models.py (ch22l020)
781+
.src/lists/tests/test_models.py (ch22l020)
772782
====
773783
[source,python]
774784
----
@@ -780,7 +790,7 @@ that too:
780790
The correct implementation is this:
781791

782792
[role="sourcecode"]
783-
.lists/models.py (ch22l021)
793+
.src/lists/models.py (ch22l021)
784794
====
785795
[source,python]
786796
----
@@ -845,7 +855,7 @@ Django represents users using a class called `AnonymousUser`, whose
845855

846856

847857
[role="sourcecode"]
848-
.lists/views.py (ch22l023)
858+
.src/lists/views.py (ch22l023)
849859
====
850860
[source,python]
851861
----
@@ -891,7 +901,7 @@ which wanted to be able to access a list "name" based on the text of
891901
its first item:
892902

893903
[role="sourcecode"]
894-
.lists/tests/test_models.py (ch19l024)
904+
.src/lists/tests/test_models.py (ch19l024)
895905
====
896906
[source,python]
897907
----
@@ -905,7 +915,7 @@ its first item:
905915

906916

907917
[role="sourcecode"]
908-
.lists/models.py (ch19l025)
918+
.src/lists/models.py (ch19l025)
909919
====
910920
[source,python]
911921
----

tests/test_chapter_22_outside_in.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,32 @@
66

77

88
class Chapter19Test(ChapterTest):
9-
chapter_name = 'chapter_22_outside_in'
10-
previous_chapter = 'chapter_21_server_side_debugging'
9+
chapter_name = "chapter_22_outside_in"
10+
previous_chapter = "chapter_21_server_side_debugging"
1111

1212
def test_listings_and_commands_and_output(self):
1313
self.parse_listings()
14-
#self.prep_virtualenv()
14+
# self.prep_virtualenv()
1515

1616
# sanity checks
17-
self.assertEqual(self.listings[0].type, 'code listing with git ref')
18-
self.assertEqual(self.listings[1].type, 'code listing with git ref')
19-
self.assertEqual(self.listings[3].type, 'code listing currentcontents')
17+
self.assertEqual(self.listings[0].type, "code listing with git ref")
18+
self.assertEqual(self.listings[1].type, "code listing with git ref")
19+
self.assertEqual(self.listings[3].type, "code listing currentcontents")
2020

2121
# skips
22-
#self.skip_with_check(22, 'switch back to master') # comment
22+
# self.skip_with_check(22, 'switch back to master') # comment
2323

2424
self.start_with_checkout()
2525
self.prep_database()
2626

2727
# hack fast-forward
2828
if os.environ.get("SKIP"):
29-
self.pos = 53
30-
self.sourcetree.run_command('git checkout {}'.format(
31-
self.sourcetree.get_commit_spec('ch19l025')
32-
))
29+
self.pos = 28
30+
self.sourcetree.run_command(
31+
"git checkout {}".format(
32+
self.sourcetree.get_commit_spec("ch19l011"),
33+
)
34+
)
3335

3436
while self.pos < len(self.listings):
3537
print(self.pos, self.listings[self.pos].type)
@@ -39,5 +41,5 @@ def test_listings_and_commands_and_output(self):
3941
self.check_final_diff(ignore=["moves", "Generated by Django 1.11"])
4042

4143

42-
if __name__ == '__main__':
44+
if __name__ == "__main__":
4345
unittest.main()

0 commit comments

Comments
 (0)