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

feat(testing): Add TestClient class and a pytest example #862

Merged
merged 2 commits into from Aug 18, 2016

Conversation

kgriffs
Copy link
Member

@kgriffs kgriffs commented Aug 12, 2016

Add a contextual wrapper for the simulate_* methods and a pytest
example demonstrating its use.

Also deprecate "api" in favor of "app" in TestCase, since these utils
can work with any WSGI app (not just those that express HTTP APIs). This
terminology makes TestCase more consistent with the new simulate_*
functions and with TestClient.

Finally, deprecate "api_class" in TestCase and update the docstring
for the testing module to demonstrate a less hacky alternative for
controlling the api instance type. As a bonus, this avoids having to
try and alias api_class (a class variable).

Partially implements #16

@@ -16,23 +16,51 @@

This package contains various test classes and utility functions to
support functional testing for both Falcon-based apps and the Falcon
framework itself::
framework itself. Both unittest-style and pytest-style tests are
supported::
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please carefully review the example code below for correctness. Thanks!

@codecov-io
Copy link

codecov-io commented Aug 12, 2016

Current coverage is 100% (diff: 100%)

Merging #862 into master will not change coverage

@@           master   #862   diff @@
====================================
  Files          30     30          
  Lines        1867   1875     +8   
  Methods         0      0          
  Messages        0      0          
  Branches      305    305          
====================================
+ Hits         1867   1875     +8   
  Misses          0      0          
  Partials        0      0          

Powered by Codecov. Last update 2b63419...a6672ee

class MyTestCase(testing.TestCase):
def setUp(self):
super(MyTestCase, self).setUp()
self.app = api.create()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I'm just missing something, but where is create() defined? is that just hypothetical for the example?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just hypothetical... let me try to add a comment or something to avoid confusion. 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I tweaked this. Let me know if it makes more sense!

super(TestMyApp, self).setUp()
self.api = app.create_api()
super(MyTestCase, self).setUp()
self.app = api.create()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to add that comment about create() here as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nice catch! Will do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Kurt Griffiths added 2 commits August 16, 2016 23:58
Add a contextual wrapper for the simulate_* methods and a pytest
example demonstrating its use.

Also deprecate "api" in favor of "app" in TestCase, since these utils
can work with any WSGI app (not just those that express HTTP APIs). This
terminology makes TestCase more consistent with the new simulate_*
functions and with TestClient.

Finally, deprecate "api_class" in TestCase and update the docstring
for the testing module to demonstrate a less hacky alternative for
controlling the api instance type. As a bonus, this avoids having to
try and alias api_class (a class variable).

Partially implements falconry#16
@jmvrbanac
Copy link
Member

👍

@jmvrbanac jmvrbanac merged commit fb7ca62 into falconry:master Aug 18, 2016
@kgriffs kgriffs deleted the issue-16-pytest branch August 4, 2017 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants