How to test Models in Django with Foreign Keys

I want to make sure I am testing Models/Objects in isolation and not as one huge system. If I have an Order object and it has Foreign Keys to Customers, Payments, OrderItems, etc. and I want to...

How to mock chained function calls in python?

I'm using the mock library written by Michael Foord to help with my testing on a django application. I'd like to test that I'm setting up my query properly, but I don't think I need to actually...

Why does Django give me different results for the same query?

For a mock web service I wrote a little Django app, that serves as a web API, which my android application queries. When I make requests tp the API, I am also able to hand over an offset and limit...

Mocking Django query using Mox

I'm trying to mock a django filter query using Mox. I am following the instructions on Mox website, however, since my django query is a chained method, it complains that the AndReturn() method...

how to use django-valuate?

I am using a system of punctuation, this site, I'm just using the example that comes, I have not created any app just use the example, I've done syncdb, add in the admin. LikeDislike Like...

How do you assert that Django's QuerySet.count() method was called on a Mock?

I'm using Mock to replace a Django Model, and it is configured as follows: >>> config = {'objects.filter.return_value.count.return_value': 1} >>> MockModel = Mock(**config) I can query for some...

Cleanly Mocking Remote Servers and APIs for Django Unittests

I have a thorny problem that I can't seem to get to grips with. I am currently writing unit tests for a django custom auth-backend. On our system we actually have two backends: one the built-in...

When is a Django QuerySet evaluated?

I've read django queryset are lazy. But does that mean lazy in that I can chain multiple operations on one statement or lazy in that the query is delayed to when the results are needed. For...

How to unittest a database wrapper?

I've written a database wrapper for RethinkDB, in Python, a wrapper that introduces models (something similar to what Django delivers regarding models and managers). How do I write unittests for...

Django Test Client does not create database entries

I'm creating unit tests for my views using Django's built-in Test Client to create mock requests. The view I'm calling should create an object in the database. However, when I query the database...

Mock a request for asynchronous processing

I want to implement asynchronous versions of some existing DRF API methods (particularly list methods) that can take a long time. My idea is to capture the authenticated user ID, what method he...

How to mock Django Model Queries

I would like to mock the following CanonPerson model def compute(self, is_send_emails, test_email_address): cpses = CanonPerson.objects.filter(persons__vpd=6, ...

How to pass Django mock instance to class method?

The Mock testing library is the one Django topic I just can't seem to wrap my head around. For example, in the following code, why don't the mock User instances that I create in my unit test...

exception in tests after upgrading from django 1.5 to 1.7

this is the test that broke: def test_registering_user_twice_cause_error_msg(self): user=User(name='pyRock',email='[email protected]') user.save() #create the request used to test the...

Using Pytest and Mock to test view that queries database

I'm trying to write a unittest for a view that my Django app uses. The view itself takes data from the database by way of a custom model (code snippet of the view below). views.py def...

readthedocs app won't start with apache and django

Im trying to get readthedocs to run as an apache application. I'm following all the instructions, but ive boiled it down to this error in my apache logs. mod_wsgi (pid=2372): Target WSGI script...

Mocking django ORM to unit test queryset

I have a function that dynamically generates a queryset of users by creating a bunch of Q objects and ORing/ANDing them together in a .filter(). Its reasonably complicated and involves queries on...

Mocking pymongo for unit testing

I have a simple application in Django REST, I am using Pymongo to connect to MongoDB. My directory structure is like this:- appauth/ ├── apps.py ├── controllers.py ├──...

Proper usage of viewset queryset

According to Django REST framework documentation, the following two code snippets should behave identically. class UserViewSet(viewsets.ViewSet): """ A simple ViewSet for listing or...

Not able to mock the database Django chain queries

I am trying to mock the django chain queries. These are 1. MyModel.objects.filter(userId=userId).exists() 2. mrvDb = MyModel.objects.filter(userId=userId).order_by('-dateViewed') . I am trying...

Not able to mock the django query object that is iterating through for loop

I am trying to mock the django query object while iterating through for loop. for row in MyModel.objects.filter(ListId=id): I am getting the 'TypeError: 'Mock' object is not iterable' Below...

Mocking an API call with Vue and Jest/Vue test utils

I'm using Vue for the frontend and Python/Django for the backend. I would like to write tests to ensure that my API calls to my backend are working as expected but I'm having trouble mocking out...