From the course: Building Angular and Django Apps
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Unit testing validation for the REST API
From the course: Building Angular and Django Apps
Unit testing validation for the REST API
- [Instructor] We're going to write a test to ensure that validation of form fields is working correctly. First we create a user. And then we create the off header by creating an access token for this user. And then we set up the form data. The start date will be in the incorrect format. So when we post this data to try and create a new package, we should get a 400 status code. And then we'll check the regex of the error message that we received for start. And we expect it to tell us that it is the wrong format. When we adjust the format of the start date in the form data, we're going to be expecting a 201 status code, meaning that the package was created successfully. Let's run the test. Cool.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.