Getting Mockito and Powermock to throw error correctly

I have the following code @PrepareForTest({Mongo.class, XYMongo.class, DB.class}) public class XYMongoTest extends UnitTest{ String host = Play.configuration.getProperty("mongo.host"); int...

How can mongomock can be use with motor?

I have a server implemented with Tornado, and Motor, and I've come across this mock of pymongo: https://github.com/vmalloc/mongomock I really like the idea of doing the unit tests of my code with...

Mongoengine + MongoMock do not return data as expected

I am trying to test a response made by the controller. The response is different when I am running it through gunicorn vs a testFramework My server.py looks like the following: app =...

How can I use mock for testing inside greenlet?

I use bottle & gevent for my python (2.7.6) application. # -*- coding: utf-8 -*- from __future__ import unicode_literals from gevent import spawn, monkey from bottle import Bottle from .settings...

self._cursor.next() exception in py.test with mongomock

I have encountered a problem when running py.test for my Django rest framework API using mongodb backend, while the view works in real action. If I start the server, the API works as expected....

mock mongoDB for python unit test

I'm using nosetests for Python code to test code with MongoDB connection, I have used the python mock standard library with mongoMock: https://github.com/vmalloc/mongomock ,I have patched the...

How to set a class or module attribute in a patchmonkey in py.test

I'm starting a small project in Python and I want to create a unittest with py.test. I need to patch a pymongo module or a MongoClient class. So I tried something like...

Sinon / Node / Express / Mongo - TypeError when trying to mock Mongo DB.collection function

I am trying to write unit tests for an Express / Mongo app and am trying to use Sinon to mock the Mongo library so that I can test behavior without needing the database. I am using the co module...

Aggregate - count records with pymongo

I would like to count matching records with pymongo. I have looked up the documentation: https://docs.mongodb.com/manual/reference/operator/aggregation/group/#group-by-month-day-and-year I...

MongoMock and mongoengine not clearing database

During unittesting I'm calling: self.connection = connect(db="testdb", host="mongomock://localhost") self.connection.drop_database("testdb") between tests, however data is persisting. Is there a...

python mongoengine: mongomock drop_collection does not work as expected

When using mongomock to mock mongoengine, the connection.drop_database() method do not work properly: the first time I use it, it works as expected but the second time does not work at all. The...

Tornado, Motor with mongomock for testing

I'm writing a test module for a tornado based web application. The application uses motor as mongodb connector and I wish that my tests run on a temporary database. I am using a mocking technic on...

gomock, Go,mango package ,MongoMock

I am trying to mock the below method using gomock func GetS(tenantName string) (*mgo.Session, error) { ctx := apiContext.TContext{} url, err := connectionURLList.get(tenantName) if err...

Testing $lookup aggregations with Mongomock

I got an aggregation query with $lookup inside it: pipeline = [{ '$match': { '_id': ObjectId(layout_id) } }, { '$lookup': { 'from': 'units', 'localField':...

Mocking module global variable while import

I am writing unit tests for the api, which connects to MongoDB. In my API module it looks like this: from flask import Flask, jsonify from MyApp import MongoData api = Flask(__name__) DB_CONN =...

Using a fake mongoDB for pytest testing

I have code that connects to a MongoDB Client and I'm trying to test it. For testing, I don't want to connect to the actual client, so I'm trying to figure out make a fake one for testing...

Airflow webserver not starting in 1.10

Trying to migrate from Airflow 1.9 to Airflow 1.10. After some effort I was able to install the new version but could not load the web UI. When I try to start webserver It gives an error of file...

Gunicorn SSL exception

I am runninug Gunicorn 19.9.0 and when accessing the webpage I receive an exception. This causes the browser the gunicorn to freeze for a few minutes until it is able to start serving again. These...

Testing Data in mongodb - time varies

I'm currently testing my database accessibility and I run into a serious problem. I'm mocking the database and insert a user object which has a registration date. That date is first written into a...

$sum inside aggregate in mongomock seems not to be working

I have an aggregate Mongo query that projects some fields and calculates two other ones using $sum. The query works as expected, so I created an unit test for it, and to my surprise the test was...

How to mock mongodb when it is called from another function?

I need help while mocking mongodb. I am using mongomock to mock mongodb. My project structure is: -- my_mongo.py -- code.py -- my_test.py my_mongo.py has : from pymongo import MongoClient def...

AttributeError: "Class" object has no attribute ''update_one"

I have a problem with removing and updating with the update_one method. It seems like the method had not been implemented in mongoengine. My objective is to remove a Student field from the...

Test inserting values into mongodb (pyspark, pymongo)

I would like to (locally) test inserting some values into a mongo database. If I run this: import pymongo import mongomock @mongomock.patch( servers=(("mongodb://null:[email protected]/test",...

Insert ObjectId into mongodb

I'm working on a mongo database which, for some reason, has the user id stored as ObjectId. In order to test some functions, I'd like to be able to populate a test database - for example, as...

pytest monkeypatch not able to patch the mongodb collection

I'm trying to unit test the following function with pytest. @login_sys.route("/users/register", methods=["POST"]) def register(): users = mongo.db.users # TRYING TO PATCH THIS ...

Mocking MongoDB for Testing REST API designed in Flask

I have a Flask application, where the REST APIs are built using flask_restful with a MongoDB backend. I want to write Functional tests using pytest and mongomock for mocking the MongoDB to test...

How to use mongomock with unittest python

I try to mock my Mongo database on tests. I find article which I follow, but unfortunately my tests write to real mongo database instead of mocked. I have database.py file with PyMongo...