def test_with_master(self, mock_randint): mock_randint.return_value = 0 self.assertEqual( dj_db.router.db_for_read(HamModel), "default-0" ) with pindb.master("default"): self.assertEqual( dj_db.router.db_for_read(HamModel), "default" ) self.assertEqual( dj_db.router.db_for_read(HamModel), "default-0" ) @pindb.with_masters(["default"]) def to_master(): mock_randint.return_value = 2 self.assertEqual( dj_db.router.db_for_read(HamModel), "default" )
def create_one_pin(request): with pindb.master("default"): HamModel.objects.create() EggModel.objects.create() return HttpResponse("create one pin")
def create_no_pins(request): with pindb.master("default"): HamModel.objects.create() return HttpResponse("create no pins")