You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/exercises/mailroom/mailroom_with_tests.rst
+17-5Lines changed: 17 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,18 +35,24 @@ For unit testing framework you should use `pytest <https://docs.pytest.org/en/la
35
35
Mailroom Code Structure
36
36
-----------------------
37
37
38
-
Your code should have 3 main features so far:
38
+
Your code should have 2 main features so far:
39
39
40
40
* Send a thank you (adds a new donor or updates existing donor info)
41
41
* Create a report
42
-
* Send letters (creates files)
43
42
44
43
45
44
Send Thank You
46
45
...............
47
46
48
47
Even though every mailroom implementation will be unique, most likely this function will require a significant refactor for most of you.
49
-
You can break up the code into components that handle user interaction and data manipulation logic. Your unit tests should test the data manipulation logic code: generating the thank you text, adding or updating donors, and listing donors.
48
+
49
+
You can break up the code into components that handle user interaction and data manipulation logic. Your unit tests should test the data manipulation logic code:
50
+
51
+
* generating the thank you text
52
+
53
+
* adding or updating donors
54
+
55
+
* listing donors
50
56
51
57
52
58
Create Report
@@ -71,8 +77,14 @@ Here you would write a unit test for ``get_report`` function. Remember: TDD -- w
71
77
Send Letters
72
78
............
73
79
74
-
This function should require very little or no change to make it unit-testable.
80
+
After adding unit tests, in a future assignment, you will be extending mailroom to save the thank you letters to files on disk.
81
+
82
+
Don't worry about that now -- but when you get there, keep testing in mind!
83
+
84
+
This function should be easy to make unit-testable.
85
+
75
86
To make it testable, you'll need to follow the same "separation of concerns" approach: the code that creates the letters should be separate from the code that prints them to the screen.
87
+
76
88
This both allows you to test the letter creation, and leaves the door open to do something else with the letters: save to to a file, send as an email, etc.
77
89
So the code that makes a letter likely will return a string with the entire letter contents.
78
90
@@ -106,7 +118,7 @@ But trust me -- that is a Good Thing™
106
118
107
119
.. note:: Testing print() is rearely neccesasry if you factor your code correctly. But it would be able to test your menu code with `input()` in it. This is a pretty advanced topic, but if you want to give it a try, there is more on advanced testing here: :ref:`advanced_testing`
0 commit comments