TDD with Python (4) - Chapter 3-2

第3章の後半へ。

Test-Driven Development with Python

ViewのUnit Test

まずはテストを拡張しますと。

関数が1つ増えてて、見る限りはresponse.contentがで始まり、で終わる。つまりhtmlファイルになっていて、なおかつTo-Do listsというタグが含まれていることという条件を付加したわけですね。

ここで実行すると、当然怒られるわけで。

$ python3 manage.py test
Creating test database for alias 'default'...
E/Users/ken/Documents/workspace/PycharmProjects/TDDPython/superlists/superlists/urls.py:22: RemovedInDjango110Warning: Support for string view arguments to url() is deprecated and will be removed in Django 1.10 (got lists.views.home_page). Pass the callable instead.
  url(r'^$', 'lists.views.home_page', name='home'),

.
======================================================================
ERROR: test_home_page_returns_correct_html (lists.tests.HomePageTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/ken/Documents/workspace/PycharmProjects/TDDPython/superlists/lists/tests.py", line 14, in test_home_page_returns_correct_html
    response = home_page(request)
TypeError: home_page() takes 0 positional arguments but 1 was given

----------------------------------------------------------------------
Ran 2 tests in 0.008s

FAILED (errors=1)
Destroying test database for alias 'default'...

これに対応するコードを追加していきましょうという感じでサイクルを回せとおっしゃる。

ここまで直すと、

$ python3 manage.py test
Creating test database for alias 'default'...
./Users/ken/Documents/workspace/PycharmProjects/TDDPython/superlists/superlists/urls.py:22: RemovedInDjango110Warning: Support for string view arguments to url() is deprecated and will be removed in Django 1.10 (got lists.views.home_page). Pass the callable instead.
  url(r'^$', 'lists.views.home_page', name='home'),

.
----------------------------------------------------------------------
Ran 2 tests in 0.005s

OK
Destroying test database for alias 'default'...

テストが通りますと。

でもね、functional_test.pyを試すと

$ python3 functional_test.py
F
======================================================================
FAIL: test_can_start_a_list_and_retrive_it_later (__main__.NewVistorTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "functional_test.py", line 19, in test_can_start_a_list_and_retrive_it_later
    self.assertIn("To-Do", self.browser.title)   #5
AssertionError: 'To-Do' not found in 'プライバシーをしっかり守るFirefox'

----------------------------------------------------------------------
Ran 1 test in 9.118s

FAILED (failures=1)

怒られる。

$ git commit -am"Basic view now returns minimal HTML"
[master 21b6ea4] Basic view now returns minimal HTML
 Committer: Ken <ken@Kens-Macbook-Air-2010.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 2 files changed, 14 insertions(+), 5 deletions(-)
Kens-Macbook-Air-2010:superlists ken$ git log --oneline
21b6ea4 Basic view now returns minimal HTML
0dc4101 First unit test and url mapping, dummy view
93ee6be Add app for lists, with deliberately failing unit test
42c68f5 Implemented improvements in Chapter 2
292cd28 First commit: First FT and basic Django config

(つづく)