It is now time to write the tests for a profile status view said class and we can actually start by
copying part of the code we used for their profile view said test case class.
So you are below.
Like so this is going to be profile to view said test case.
List you avail is going to be start to say the least.
And you also need to make a couple of adjustments here because we need to create a new start to see
instances so self-doubt starts and of course we're going to need to import both profile starters and
profile starters serialize the like so now we can use FISA to actually create this fantasy instance
so self that start to see what's provided that those not objects that create the user profile equals
self.
Dot user dot profile and of course status content equals status test.
Same as we did here with the profile view said test case class.
We can now check the list end point.
So but this time of course this is going to be Test status least authenticated and test the status least
and authenticated.
Let's now run the tests right away and let's see what happens.
Python manage that by test.
The system is run eight tests.
If you worked as expected.
Awesome.
So we're going back to our classic can now write in other method and let us know try to create a new
start to see instance.
So DFA test starters create self we can define a data dictionary we have status as a matter of fact
we use the.
So starts content a new start.
And yet we can check.
Response equals self client dot post this time clearly self-taught list you add L which in fact in this
case we can just call you at L.
So like so.
So first of all let's check this that was code self-taught assert equal response not status code and
of course we expect start was not HDP to a one created.
We can then check the user profile or self-taught assert equal response that data user profile and we
want you to be there means you of course because that e.g. is the user name of the user that we're using
to authenticate a request.
And finally let's check the status quo into itself.
So self let's assert equal response dot data status content which has to be in your status.
Let's also try to retrieve a single status so DFA test single status retrieve self and one way that
we can do so involves using the serialized class.
So serialize their data equals course it's going to be profile status denies it with instance equals
self dot status that we want the data then yeah we can do a response equals self that's client and dot
get to reverse status detail.
Again remember we get the name for free according to the way we set out router class up.
So keyword arguments equals parameter key one which is of course the status that we've created yet.
Then we can check.
Of course status code is always very important.
And then response data equals GSA dot loads response not content.
Now we can now assert equal.
Well actually self-taught a sort of equal that data
response data.
Let's run out of tests.
So you see we get an error we get an F which stands for fail.
We then read the test that is fail.
And right away we also get the class that are math or these parts of it.
Then we get trace back and a very useful error message.
First of all line 92.
So we know that the error is in line 92.
And then we get a certain error for Android is different then tool 1 and that is because of course we
cannot get an h UDP to a one created without actually creating a new instance which means that we need
to pass data to our End Point let's run the tests.
Once again we now see that it is a small typo yet let's run them one more time and now everything works
just fine.
So as you can see tests are really really useful even just a ladder out of place of maybe forgetting
to pass a parameter to a function will most of the time prevent your application from providing the
functionality that it's supposed to provide.
And of course using automated testing most of the time will allow you to identify a problem and fix
it.
Let's not right the two last methods for our class.
So we can test the update capabilities for our start to see instances.
So therefore Test status update on our self and then we can define a data dictionary something like
content updated India response equals self the client that puts the reverse.
For starters the tail we've keyword arguments being a dictionary primary key one.
And with data equals data we can now check this status code and the response data so stethoscope we
expect H2 to be 200.
OK and the start was content as to be of course content updated.
And now for the final method
we can check and update your random user.
So first of all I'm going to copy the code we've used here.
So
this way.
So content we can set you up have been hacked then we can delete this because if everything works as
it should we can get HP for all 3 for beta then maybe Ecuador's indent this one like so here and here.
Well
let's not run our tests one last time.
So
in this you see of course everything works as expected.
Okay.
So that was it for January's framework level three.
The next section is all about the future.
Yes.
We will make a great introduction learning how to use it.
Get it ready to build a full fledged single page application.
We've got this framework in view in the final project of course.