Comments (3)
@guinslym sorry for the late answer, didn't see the email notifications and I was sick for the past four weeks or so.
- first, we need to create an instance of the view with
views.PostUpdateView.as_view()
- this call toas_view()
will basically turn the class based view into a function. Then we need to actually call that function in order to execute the code in our view, so we do that with(req, pk=post.pk)
- these are the arguments, that would be passed into thedispatch
function of your class based view. - No. Never use self.client.get() because that's slow as hell. I never ever use it. We don't test templates. Ideally, our whole frontend is rendered by ReactJS, which has it's own powerful testing capabilities with something like Jest, for example, so we aren't even using Django's templating language (which is also slow as hell and not suitable for large scale projects which might have hundreds of small partial template components).
- We can't write an assertion for exceptions. When the exception is thrown, it bubbles up all the way right into the test and then the test crashes with that exception. So if we want to test for 404, we need to use the context processor (
with pytest.raises(Http404):
). I haven't found a good way to also provide a nice test failure message. I usually just put a code-comment into the context processor code-block, so when the test crashes, the developer will open the test file and then see the comment. - The point of this test was to check that one user cannot edit the object of another user. So we created the first user, and we created a Post. The Post will automatically create it's own user, so we will have two users in the system. Then we attached the first user to the request and tried to call the view, but for the object that belongs to the second user. This should raise a 404.
from django-testing-cookbook.
OMG!!! sorry I didn't see your reply. I am not using Github intensively now as I used to in the summer. Thanks for the reply. I will put your explication into practice.
from django-testing-cookbook.
@guinslym don't worry. Github gets overwhelming with messages quickly, so most people reply with huge delay (especially myself). It's normal :)
from django-testing-cookbook.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-testing-cookbook.