Skip to content

Tag: unit-testing

Mocking FastText model for utest

I am using fasttext models in my python library (from the official fasttext library). To run my u-tests, I need at some point a model (fasttext.FastText._FastText object), as light as possible so that I can version it in my repo. I have tried to create a fake text dataset with 5 lines “fake.txt” a…

Mock property method on class

I have the following dataclass: I’d like to change the behavior of qux during testing. I’m aware of PropertyMock, and could write something like: I’d instead like to substitute the property method (undecorated), something like: I’ve tried various combinations of new_callable, new, etc.…

Querying the database in a Django unit test

I am creating a web application which has a POST endpoint, that does two things: Saves the POSTed data (a university review) in the database. Redirects the user to an overview page. Here is the code for it: I haven’t yet implemented passing the user data to the endpoint, and that’s why I’m s…