From the course: Test-Driven Development in Django

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Hash testing

Hash testing

From the course: Test-Driven Development in Django

Start my 1-month free trial

Hash testing

- [Instructor] The next thing that we need to test is whether we have a hashing function that actually works. And so, what we're going to do is type in a given phrase and type in what we expect the given hash to be, and then be able to test for that. So, inside of our test up high, we need to import a new library that will allow us to do some hashing. So we're going to say import, and we want hashlib, just all lowercase, one word, hashlib. Then, we're going to create a new test. So let's go ahead and make a new one down here. You're going to have def test underscore. Now, the name for this one, let's do something like hashfunctionworks or something like that. We can call this hash_func_works, okay. So we'll go ahead and pass (self) into there with a colon, and what we're looking for is something like, we'll say text_hash =, and this is where we're going to use that hashlib, we'll say hashlib.sha256, that's the particular hashing function that we're going to be using. We'll do the…

Contents