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

route_url does not have access to the urls in the app during unit testing #2734

Closed
mark0978 opened this issue Aug 8, 2016 · 3 comments
Closed

Comments

@mark0978
Copy link
Contributor

mark0978 commented Aug 8, 2016

The solution is to just add routes in the setUp of your test, but this is not a good idea. I have an email template that is being rendered, and it needs to generate a verification URL to be sent to an end user. The name of that view config is currently 'verify_name'.

So, in my test I'm expected to config.add_route('verify_name', '/verify_name/{token}') so that it will reverse successfully. Problem is, I can misspell the name in one place or the other and my tests will pass, but in production my site fails because my unit test isn't testing my config, its testing a tightly coupled mock config.

My router is intimately coupled to my application and to just leave it out while unit testing is inviting errors. What if I want to return a redirect?

Django doesn't make this kind of mistake, the routes that the app uses are available for "reversing" in Django parlance. Why on earth would Pyramid not have that kind of state available while testing?

@robertlagrant
Copy link

robertlagrant commented Aug 8, 2016

You need to understand the basics of unit testing, and that there are other types of tests.

Unit testing is testing a unit of code, and mocking around it. There are other types of test (e.g. integration tests) that may be more appropriate for some of what you're describing.

Also, in case you're unfamiliar with Github and, you know, people, this is not a place for you to insult a free product and then get free advice from the people who make it.

Go to Stack Overflow and ask your programming question, with a minimal, complete and verifiable example, and do it without complaining that Pyramid isn't Django.

@mmerickel
Copy link
Member

Closing this as we covered the issues in the linked comments as well as above. Thanks @robertlagrant .

#1202 (comment)

@lemontree210
Copy link

In case someone still faces this problem, I would suggest my solution: in tests that use your app's route URLs, you could use app_request fixture instead of dummy_request. That way you will be testing your actual app with the routes configured for it.

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

No branches or pull requests

4 participants