Skip to content
Permalink
Browse files

Add a mongoclient to RestTestSuite instances and write a test to make…

… sure that using it works
  • Loading branch information
arcrose committed Jan 9, 2020
1 parent 2338d70 commit ef8a1001b5558693274e3bf2c3d0b956ccb31d3f
Showing with 38 additions and 0 deletions.
  1. +5 −0 tests/rest/rest_test_suite.py
  2. +30 −0 tests/rest/test_rest_index.py
  3. +3 −0 tests/suite_helper.py
@@ -3,6 +3,7 @@
import mock
import importlib
from configlib import OptionParser
from pymongo import MongoClient

from mozdef_util.utilities.dot_dict import DotDict

@@ -30,4 +31,8 @@ def setup(self):
importlib.reload(plugins)
from rest import index as rest_index
self.application = rest_index.application

super().setup()

self.mongoclient = MongoClient(
self.options.mongohost, self.options.mongoport)
@@ -16,6 +16,35 @@
from .rest_test_suite import RestTestSuite


class TestMongoConnection(RestTestSuite):
routes = ['/test', '/test/']
status_code = 200

def setup(self):
super().setup()
self.mongoclient.test_database.tests.insert_one({
'name': 'test_item_1',
'value': 32
})

def teardown(self):
super().teardown()
self.mongoclient.test_database.tests.delete_one({
'name': 'test_item_1'
})

def test_route_endpoints(self):
db = self.mongoclient.test_database

db.tests.update_one(
{'name': 'test_item_1'},
{'$inc': {'value': 32}})

found = db.tests.find_one({'name': 'test_item_1'})

assert found.get('value') == 64


class TestTestRoute(RestTestSuite):
routes = ['/test', '/test/']

@@ -284,6 +313,7 @@ def test_route_endpoints(self):
assert type(json_resp[2]['end']) == str
assert parse(json_resp[2]['begin']).tzname() == 'UTC'


# Routes left need to have unit tests written for:
# @route('/veris')
# @route('/veris/')
@@ -43,6 +43,9 @@ def parse_config_file():
options.mqport = getConfig('mqport', 5672, options.configfile)
options.mqack = getConfig('mqack', True, options.configfile)

options.mongohost = getConfig('mongohost', 'localhost', options.configfile)
options.mongoport = getConfig('mongoport', 3002, options.configfile)

CONFIG_FILE_CONTENTS = options

return CONFIG_FILE_CONTENTS

0 comments on commit ef8a100

Please sign in to comment.
You can’t perform that action at this time.