def test_datetime_to_str_list(self): """ Given: list containing datetime object When: converting datetimes to strs Then: validate the value is a string. """ raw = Client.datetime_to_str([self.datetime_obj]) assert [self.datetime_str] == raw
def test_datetime_to_str_str(self): """ Given: datetime object When: converting datetimes to strs Then: validate the value is a string. """ raw = Client.datetime_to_str(self.datetime_obj) assert self.datetime_str == raw
def test_datetime_to_str_str_no_datetime(self): """ Given: 'str' When: converting datetimes to strs Then: validate the value returned is 'str'. """ raw = Client.datetime_to_str('str') assert 'str' == raw
def test_datetime_to_str_dict(self): """ Given: dict containing datetime object When: converting datetimes to strs Then: validate the value is a string. """ raw = Client.datetime_to_str({'time': self.datetime_obj}) assert self.datetime_str == raw['time']
def test_datetime_to_str_list_no_datetime(self): """ Given: list containing an int (5) object When: converting datetimes to strs Then: validate the value returned is 5. """ raw = Client.datetime_to_str([5]) assert [5] == raw
def test_datetime_to_str_dict_no_datetime(self): """ Given: dict containing 5 (int) When: converting datetimes to strs Then: validate the value returned is 5 """ raw = Client.datetime_to_str({'time': 5}) assert 5 == raw['time']
def test_query(mocker): """ Given: Object with datetime and object id in it When: Quering object Then: validate all objects returned are strs. """ client = Client(['aaaaa'], 'a', 'b', 'd') mocker.patch.object(Client, 'get_collection', return_value=MockedQuery) readable_outputs, outputs, raw_response = search_query(client, 'a', '{}', '50') time = raw_response[0]['time'] _id = raw_response[0]['_id'] assert isinstance(_id, str) assert isinstance(time, str)
def test_pipeline_query_command(mocker): """ Given: collection - where to search. pipeline - json pipeline query When: calling `pipeline_query_command` Then: validate the readable output and context """ client = Client(['aaaaa'], 'a', 'b', 'd') return_value = [{ 'title': 'test_title', 'color': 'red', 'year': '2019', '_id': '6034a5a62f605638740dba55' }, { 'title': 'test_title', 'color': 'yellow', 'year': '2020', '_id': '6034a5c52f605638740dba57' }] mocker.patch.object(client, 'pipeline_query', return_value=return_value) readable_outputs, outputs, raw_response = pipeline_query_command( client=client, collection='test_collection', pipeline="[{\"$match\": {\"title\": \"test_title\"}}]") expected_context = list() for item in copy.deepcopy(raw_response): item.update({'collection': 'test_collection'}) expected_context.append(item) assert 'Total of 2 entries were found in MongoDB collection' in readable_outputs assert outputs.get( 'MongoDB.Entry(val._id === obj._id && obj.collection === val.collection)' ) == expected_context
def test_normalize_id(): res = Client.normalize_id({'_id': ObjectId('5e4412f230c5b8f63a7356ba')}) assert '5e4412f230c5b8f63a7356ba' == res['_id']