Revision aa29e95f test/ganeti.query_unittest.py

b/test/ganeti.query_unittest.py
23 23

  
24 24
import re
25 25
import unittest
26
import random
26 27

  
27 28
from ganeti import constants
28 29
from ganeti import utils
......
752 753
                          "ADMIN_down"]))
753 754

  
754 755

  
756
class TestQueryFields(unittest.TestCase):
757
  def testAllFields(self):
758
    for fielddefs in [query.NODE_FIELDS, query.INSTANCE_FIELDS]:
759
      result = query.QueryFields(fielddefs, None)
760
      self.assert_(isinstance(result, dict))
761
      response = objects.QueryFieldsResponse.FromDict(result)
762
      self.assertEqual([(fdef.name, fdef.title) for fdef in response.fields],
763
        [(fdef2.name, fdef2.title)
764
         for (fdef2, _, _) in utils.NiceSort(fielddefs.values(),
765
                                             key=lambda x: x[0].name)])
766

  
767
  def testSomeFields(self):
768
    rnd = random.Random(5357)
769

  
770
    for _ in range(10):
771
      for fielddefs in [query.NODE_FIELDS, query.INSTANCE_FIELDS]:
772
        fields = [fdef
773
                  for (fdef, _, _) in rnd.sample(fielddefs.values(),
774
                                                 rnd.randint(5, 20))]
775
        result = query.QueryFields(fielddefs, [fdef.name for fdef in fields])
776
        self.assert_(isinstance(result, dict))
777
        response = objects.QueryFieldsResponse.FromDict(result)
778
        self.assertEqual([(fdef.name, fdef.title) for fdef in response.fields],
779
                         [(fdef2.name, fdef2.title) for fdef2 in fields])
780

  
781

  
755 782
if __name__ == "__main__":
756 783
  testutils.GanetiTestProgram()

Also available in: Unified diff