test_Random.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from baangt.TestSteps.TestStepMaster import TestStepMaster
  2. from baangt.TestSteps.RandomValues import RandomValues
  3. import datetime
  4. TestStepMaster.testcaseDataDict = {}
  5. TestStepMaster.randomValues = RandomValues()
  6. def test_name():
  7. name = TestStepMaster.replaceVariables(TestStepMaster, '$(random{"type":"name"})')
  8. assert len(name) > 0 and len(name.split()) > 1
  9. def test_string():
  10. string1 = TestStepMaster.replaceVariables(TestStepMaster, '$(random{"type":"string"})')
  11. assert len(string1) > 0
  12. string2 = TestStepMaster.replaceVariables(TestStepMaster, '$(random{"type":"string", "min":10, "max":100})')
  13. assert len(string2) > 0 and len(string2) < 101
  14. def test_int():
  15. integer = TestStepMaster.replaceVariables(TestStepMaster, '$(random{"type":"int", "min":100, "max":1000})')
  16. assert int(integer) > 99 and int(integer) < 1001
  17. def test_float():
  18. flt = TestStepMaster.replaceVariables(TestStepMaster, '$(random{"type":"float", "min":100, "max":1000})')
  19. assert float(flt) > 99 and float(flt) < 1001
  20. def test_date():
  21. date = TestStepMaster.replaceVariables(
  22. TestStepMaster, '$(random{"type":"date", "min":"20/1/2020", "max":"30/6/2020", "format":"%d/%m/%Y"})')
  23. date_obj = datetime.datetime.strptime(date, "%d/%m/%Y")
  24. assert type(date_obj) is datetime.datetime and date_obj.year == 2020
  25. def test_time():
  26. time = TestStepMaster.replaceVariables(
  27. TestStepMaster, '$(random{"type":"time", "min":"10.30.00", "max":"15.00.00", "format": "%H.%M.%S"}')
  28. time_obj = datetime.datetime.strptime(time, "%H.%M.%S")
  29. assert type(time_obj) is datetime.datetime and 9 < time_obj.hour < 15