Beispiel #1
0
 def test_get_value_as_type_boolean_expression_without_type(self):
     # bug 1221736
     query = Query(field='should_be_a_string',
                   op='eq',
                   value='True or False')
     expected = 'True or False'
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #2
0
 def test_get_value_as_type_with_float(self):
     query = Query(field='metadata.size',
                   op='eq',
                   value='123.456',
                   type='float')
     expected = 123.456
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #3
0
 def test_get_value_as_type_with_boolean(self):
     query = Query(field='metadata.is_public',
                   op='eq',
                   value='True',
                   type='boolean')
     expected = True
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #4
0
 def test_get_value_as_type_with_string(self):
     query = Query(field='metadata.name',
                   op='eq',
                   value='linux',
                   type='string')
     expected = 'linux'
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #5
0
 def test_get_value_as_type_with_boolean(self):
     query = Query(field='metadata.is_public',
                   op='eq',
                   value='True',
                   type='boolean')
     expected = True
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #6
0
 def test_get_value_as_type_with_string(self):
     query = Query(field='metadata.name',
                   op='eq',
                   value='linux',
                   type='string')
     expected = 'linux'
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #7
0
 def test_get_value_as_type_with_integer(self):
     query = Query(field='metadata.size',
                   op='eq',
                   value='123',
                   type='integer')
     expected = 123
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #8
0
 def test_get_value_as_type_with_float(self):
     query = Query(field='metadata.size',
                   op='eq',
                   value='123.456',
                   type='float')
     expected = 123.456
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #9
0
 def test_get_value_as_type_boolean_expression_without_type(self):
     # bug 1221736
     query = Query(field='should_be_a_string',
                   op='eq',
                   value='True or False')
     expected = 'True or False'
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #10
0
 def test_get_value_as_type_integer_expression_without_type(self):
     # bug 1221736
     query = Query(field='should_be_a_string',
                   op='eq',
                   value='123-1')
     expected = '123-1'
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #11
0
 def test_get_value_as_type_with_integer(self):
     query = Query(field='metadata.size',
                   op='eq',
                   value='123',
                   type='integer')
     expected = 123
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #12
0
 def test_get_value_as_type_with_syntax_error_colons(self):
     # bug 1221736
     value = 'Ref::StackId'
     query = Query(field='field_name',
                   op='eq',
                   value=value)
     expected = value
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #13
0
 def test_get_value_as_type_with_syntax_error(self):
     # bug 1221736
     value = 'WWW-Layer-4a80714f-0232-4580-aa5e-81494d1a4147-uolhh25p5xxm'
     query = Query(field='group_id',
                   op='eq',
                   value=value)
     expected = value
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #14
0
 def test_sample_filter_meta(self):
     q = [
         Query(field='metadata.size', op='eq', value='20'),
         Query(field='resource_metadata.id', op='eq', value='meta_id')
     ]
     kwargs = api._query_to_kwargs(q, storage.SampleFilter.__init__)
     self.assertEqual(len(kwargs), 1)
     self.assertEqual(len(kwargs['metaquery']), 2)
     self.assertEqual(kwargs['metaquery']['metadata.size'], 20)
     self.assertEqual(kwargs['metaquery']['metadata.id'], 'meta_id')
Beispiel #15
0
 def test_sample_filter_timestamp(self):
     ts_start = timeutils.utcnow()
     ts_end = ts_start + datetime.timedelta(minutes=5)
     q = [
         Query(field='timestamp', op='lt', value=str(ts_end)),
         Query(field='timestamp', op='gt', value=str(ts_start))
     ]
     kwargs = api._query_to_kwargs(q, storage.SampleFilter.__init__)
     self.assertEqual(len(kwargs), 4)
     self.assertTimestampEqual(kwargs['start'], ts_start)
     self.assertTimestampEqual(kwargs['end'], ts_end)
     self.assertEqual(kwargs['start_timestamp_op'], 'gt')
     self.assertEqual(kwargs['end_timestamp_op'], 'lt')
Beispiel #16
0
 def test_sample_filter_non_equality_on_metadata(self):
     queries = [
         Query(field='resource_metadata.image_id',
               op='gt',
               value='image',
               type='string'),
         Query(field='metadata.ramdisk_id',
               op='le',
               value='ramdisk',
               type='string')
     ]
     with mock.patch('pecan.request') as request:
         request.headers.return_value = {'X-ProjectId': 'foobar'}
         self.assertRaises(wsme.exc.InvalidInput, api._query_to_kwargs,
                           queries, storage.SampleFilter.__init__)
Beispiel #17
0
 def test_sample_filter_multi(self):
     q = [
         Query(field='user_id', op='eq', value='uid'),
         Query(field='project_id', op='eq', value='pid'),
         Query(field='resource_id', op='eq', value='rid'),
         Query(field='source', op='eq', value='source_name'),
         Query(field='meter', op='eq', value='meter_name')
     ]
     kwargs = api._query_to_kwargs(q, storage.SampleFilter.__init__)
     self.assertEqual(len(kwargs), 5)
     self.assertEqual(kwargs['user'], 'uid')
     self.assertEqual(kwargs['project'], 'pid')
     self.assertEqual(kwargs['resource'], 'rid')
     self.assertEqual(kwargs['source'], 'source_name')
     self.assertEqual(kwargs['meter'], 'meter_name')
Beispiel #18
0
 def test_sample_filter_self_always_excluded(self):
     queries = [Query(field='user_id', op='eq', value='20')]
     with mock.patch('pecan.request') as request:
         request.headers.return_value = {'X-ProjectId': 'foobar'}
         kwargs = api._query_to_kwargs(queries,
                                       storage.SampleFilter.__init__)
         self.assertFalse('self' in kwargs)
Beispiel #19
0
 def test_sample_filter_translation(self):
     queries = [
         Query(field=f, op='eq', value='fake_%s' % f, type='string')
         for f in ['user_id', 'project_id', 'resource_id']
     ]
     with mock.patch('pecan.request') as request:
         request.headers.return_value = {'X-ProjectId': 'foobar'}
         kwargs = api._query_to_kwargs(queries,
                                       storage.SampleFilter.__init__)
         for o in ['user', 'project', 'resource']:
             self.assertEqual(kwargs.get(o), 'fake_%s_id' % o)
Beispiel #20
0
 def test_sample_filter_exclude_internal(self):
     queries = [
         Query(field=f, op='eq', value='fake', type='string')
         for f in ['y', 'on_behalf_of', 'x']
     ]
     with mock.patch('pecan.request') as request:
         request.headers.return_value = {'X-ProjectId': 'foobar'}
         self.assertRaises(wsme.exc.ClientSideError,
                           api._query_to_kwargs,
                           queries,
                           storage.SampleFilter.__init__,
                           internal_keys=['on_behalf_of'])
Beispiel #21
0
 def test_sample_filter_invalid_op(self):
     q = [Query(field='user_id', op='lt', value='20')]
     self.assertRaises(wsme.exc.InvalidInput, api._query_to_kwargs, q,
                       storage.SampleFilter.__init__)
Beispiel #22
0
 def test_sample_filter_timestamp_invalid_op(self):
     ts_start = timeutils.utcnow()
     q = [Query(field='timestamp', op='eq', value=str(ts_start))]
     self.assertRaises(wsme.exc.InvalidInput, api._query_to_kwargs, q,
                       storage.SampleFilter.__init__)
Beispiel #23
0
 def test_sample_filter_invalid_field(self):
     q = [Query(field='invalid', op='eq', value='20')]
     self.assertRaises(wsme.exc.UnknownArgument, api._query_to_kwargs, q,
                       storage.SampleFilter.__init__)
Beispiel #24
0
 def test_get_value_as_type_with_syntax_error_colons(self):
     # bug 1221736
     value = "Ref::StackId"
     query = Query(field="field_name", op="eq", value=value)
     expected = value
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #25
0
 def test_get_value_as_type_boolean_expression_without_type(self):
     # bug 1221736
     query = Query(field="should_be_a_string", op="eq", value="True or False")
     expected = "True or False"
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #26
0
 def test_get_value_as_type_with_float_without_type(self):
     query = Query(field="metadata.size", op="eq", value="123.456")
     expected = 123.456
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #27
0
 def test_sample_filter_single(self):
     q = [Query(field='user_id', op='eq', value='uid')]
     kwargs = api._query_to_kwargs(q, storage.SampleFilter.__init__)
     self.assertIn('user', kwargs)
     self.assertEqual(len(kwargs), 1)
     self.assertEqual(kwargs['user'], 'uid')
Beispiel #28
0
 def test_get_value_as_type_with_string_without_type(self):
     query = Query(field="metadata.name", op="eq", value="linux")
     expected = "linux"
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #29
0
 def test_get_value_as_type_integer_expression_without_type(self):
     # bug 1221736
     query = Query(field="should_be_a_string", op="eq", value="123-1")
     expected = "123-1"
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #30
0
 def test_get_value_as_type_with_bad_value(self):
     query = Query(field='metadata.size',
                   op='eq',
                   value='fake',
                   type='integer')
     self.assertRaises(wsme.exc.ClientSideError, query._get_value_as_type)
Beispiel #31
0
 def test_get_value_as_type_with_boolean_without_type(self):
     query = Query(field="metadata.is_public", op="eq", value="True")
     expected = True
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #32
0
 def test_get_value_as_type_with_syntax_error(self):
     # bug 1221736
     value = 'WWW-Layer-4a80714f-0232-4580-aa5e-81494d1a4147-uolhh25p5xxm'
     query = Query(field='group_id', op='eq', value=value)
     expected = value
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #33
0
 def test_get_value_as_type_with_syntax_error_colons(self):
     # bug 1221736
     value = 'Ref::StackId'
     query = Query(field='field_name', op='eq', value=value)
     expected = value
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #34
0
 def test_get_value_as_type_integer_expression_without_type(self):
     # bug 1221736
     query = Query(field='should_be_a_string', op='eq', value='123-1')
     expected = '123-1'
     self.assertEqual(query._get_value_as_type(), expected)
Beispiel #35
0
 def test_get_value_as_type_with_integer(self):
     query = Query(field="metadata.size", op="eq", value="123", type="integer")
     expected = 123
     self.assertEqual(query._get_value_as_type(), expected)