Esempio n. 1
0
 def test_find(self):
     doc = MagicMock()
     self.db.db.docs.find.return_value = [doc]
     results = [x for x in self.db.find(test=1)]
     assert call.find(test=1) == self.db.db.docs.mock_calls[0]
     assert 1 == len(results)
     assert doc == results[0].doc
Esempio n. 2
0
 def test_find(self):
     doc = MagicMock()
     self.db.db.docs.find.return_value = [doc]
     results = [x for x in self.db.find(test=1)]
     assert call.find(test=1) == self.db.db.docs.mock_calls[0]
     assert 1 == len(results)
     assert doc == results[0].doc
Esempio n. 3
0
 def test_status(self):
     mock_req = Mock(spec_set=Request)
     mock_headers = Mock()
     type(mock_req).responseHeaders = mock_headers
     mock_coll = Mock(spec_set=Collection)
     mock_coll.find.return_value = []
     mock_dbconn = Mock()
     cls = TestClass(Mock(), Mock(), mock_dbconn, [])
     cls.dbconn = mock_dbconn
     with patch('%s.get_collection' % pbm, autospec=True) as mock_get_coll:
         with patch('%s.returnValue' % pbm) as mock_retval:
             with patch('%s.logger' % pbm, autospec=True) as mock_logger:
                 mock_get_coll.return_value = mock_coll
                 cls.status(cls, mock_req)
     expected = json.dumps({
         'status': True,
         'dependencies': {'mongodb': True}
     }, sort_keys=True)
     assert mock_headers.mock_calls == [
         call.addRawHeader(
             b"content-type", b"application/json")
     ]
     assert mock_coll.mock_calls == [call.find(limit=1)]
     assert mock_req.mock_calls == [call.setResponseCode(200)]
     assert mock_get_coll.mock_calls == [call(mock_dbconn, COLL_SENSORS)]
     # need to mock out get_collection and the find method on its result
     # also mock the request object and assert on calls
     assert mock_retval.mock_calls == [
         call(expected)
     ]
     assert mock_logger.mock_calls == []
Esempio n. 4
0
 def test_status(self):
     mock_req = Mock(spec_set=Request)
     mock_headers = Mock()
     type(mock_req).responseHeaders = mock_headers
     mock_coll = Mock(spec_set=Collection)
     mock_coll.find.return_value = []
     mock_dbconn = Mock()
     cls = TestClass(Mock(), Mock(), mock_dbconn, [])
     cls.dbconn = mock_dbconn
     with patch('%s.get_collection' % pbm, autospec=True) as mock_get_coll:
         with patch('%s.returnValue' % pbm) as mock_retval:
             with patch('%s.logger' % pbm, autospec=True) as mock_logger:
                 mock_get_coll.return_value = mock_coll
                 cls.status(cls, mock_req)
     expected = json.dumps(
         {
             'status': True,
             'dependencies': {
                 'mongodb': True
             }
         },
         sort_keys=True)
     assert mock_headers.mock_calls == [
         call.addRawHeader(b"content-type", b"application/json")
     ]
     assert mock_coll.mock_calls == [call.find(limit=1)]
     assert mock_req.mock_calls == [call.setResponseCode(200)]
     assert mock_get_coll.mock_calls == [call(mock_dbconn, COLL_SENSORS)]
     # need to mock out get_collection and the find method on its result
     # also mock the request object and assert on calls
     assert mock_retval.mock_calls == [call(expected)]
     assert mock_logger.mock_calls == []
Esempio n. 5
0
 def test_find_unparsed(self):
     doc = MagicMock()
     self.db.db.docs.find.return_value = [doc]
     results = [x for x in self.db.find_unparsed('1')]
     assert call.find({'version': '1'}) \
         == self.db.db.docs.mock_calls[0]
     assert 1 == len(results)
     assert doc == results[0].doc
Esempio n. 6
0
 def test_find_unparsed(self):
     doc = MagicMock()
     self.db.db.docs.find.return_value = [doc]
     results = [x for x in self.db.find_unparsed('1')]
     assert call.find({'version': '1'}) \
         == self.db.db.docs.mock_calls[0]
     assert 1 == len(results)
     assert doc == results[0].doc