TwilioDevEd / appointment-reminders-flask

Use Twilio to send SMS reminders to your customers about upcoming appointments
https://www.twilio.com/docs/tutorials/walkthrough/appointment-reminders/python/flask
MIT License
75 stars 34 forks source link

Write a test for the Celery task #5

Closed atbaker closed 9 years ago

atbaker commented 9 years ago

Right now the test coverage for the app is pretty good - 91% by my measurement:

Name                           Stmts   Miss  Cover
--------------------------------------------------
application                       46      3    93%
config/__init__                    0      0   100%
forms/__init__                     0      0   100%
forms/new_appointment             13      0   100%
models/__init__                    0      0   100%
models/appointment                24      1    96%
reminders                          6      0   100%
runapp                             2      2     0%
tasks                             17      7    59%
tests/appointment_test            31      0   100%
views/__init__                     0      0   100%
views/appointment                 32      3    91%
--------------------------------------------------
TOTAL                            171     16    91%

We don't have a test that covers the task module well, however:

image

Since this is an important part of the app, we should definitely cover it with at least one test.

The CELERY_ALWAYS_EAGER setting is helpful for running tests because it forces Celery to execute tasks synchronously instead of sending them to the message broker:

http://docs.celeryproject.org/en/2.5/configuration.html?highlight=celery_always_eager#std:setting-CELERY_ALWAYS_EAGER

I didn't use py.test in my Django unit tests, but my code for testing the Celery task in that app might still be helpful as you write yours:

https://github.com/TwilioDevEd/appointment-reminders-django/blob/master/reminders/tests.py#L89-L112

jsantos17 commented 9 years ago

Now we have 100% coverage in tasks :)

Name    Stmts   Miss  Cover
---------------------------
tasks      17      0   100%

96% for everything

Name                           Stmts   Miss  Cover
--------------------------------------------------
application                       46      1    98%
config/__init__                    0      0   100%
forms/__init__                     0      0   100%
forms/new_appointment             13      0   100%
models/__init__                    0      0   100%
models/appointment                24      1    96%
reminders                          6      0   100%
runapp                             2      2     0%
tasks                             17      0   100%
tests/appointment_test            21      0   100%
tests/base_test                   15      0   100%
tests/tasks_test                  31      1    97%
views/__init__                     0      0   100%
views/appointment                 33      3    91%
--------------------------------------------------
TOTAL                            208      8    96%

Is it okay to close this issue now @atbaker?

atbaker commented 9 years ago

Yes! I'll close this out.