def test_create_command(self): target = LoadGenerator() actual = target.create_command(123, 'my_name', {'match_me': 11}, {'sort_me': -1}, 33) self.assertEqual(actual['find'], 'my_name') self.assertEqual(actual['filter']['match_me'], 11) self.assertEqual(actual['sort']['sort_me'], -1) self.assertEqual(actual['limit'], 33) self.assertEqual(actual['comment'], 'load_generator 123')
def test_with_url(self): self.assertEqual( LoadGenerator().with_url('mongodb+srv://localhost/').mongo_url, 'mongodb+srv://localhost/')
def test__generate_query_gte_lt(self): actual = LoadGenerator().with_field('foo', ObjectIdGenSpec(), method='gte_lt')._generate_query() self.assertIsNotNone(actual['foo']['$gte']) self.assertIsNotNone(actual['foo']['$lt'])
def test_with_sort(self): actual = LoadGenerator().with_sort(SORT_SPEC) self.assertEqual(actual.sort_spec, SORT_SPEC)
def test__generate_query_eq(self): actual = LoadGenerator().with_field( 'foo', ObjectIdGenSpec())._generate_query() self.assertIsNotNone(actual['foo']['$eq'])
def test_with_field(self): self.assertTrue('foo' in LoadGenerator().with_field( 'foo', None).query_fields.keys())
def test_with_collection(self): self.assertEqual( LoadGenerator().with_collection('the_collection').collection_name, 'the_collection')
def test_with_db(self): self.assertEqual(LoadGenerator().with_db('db1').db_name, 'db1')
import argparse from load_generator import LoadGenerator parser = argparse.ArgumentParser( description='Run queries against a mongo cluster') parser.add_argument('--url', '--connection', required=True, type=str, help='Mongo connection string') parser.add_argument('--db', required=True, type=str, help='Database name') parser.add_argument('--collection', required=True, type=str, help='Collection name') parser.add_argument('--iteration_count', type=int, help='Collection name', default=100) cli_args = parser.parse_args() generator = LoadGenerator().with_url(cli_args.url).with_db( cli_args.db).with_collection(cli_args.collection)