Skip to content
Snippets Groups Projects

test: Adds testing parameter randomness and improves overall structure

Open Jan Delember requested to merge feature/improved_tests into develop
10 unresolved threads

Merge request reports

Checking pipeline status.

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
9 import pytest
10 from enum import Enum
11 import requests
12 import random
13 from config import *
14
15
16 #Receives an enum or a string and converts it to a string. Throws an error if its neither a string nor an enum with a string.
17 def convert_enum_or_string_to_string(input):
18 if isinstance(input, Enum):
19 input = input.value
20
21 if isinstance(input, str):
22 return input
23 else:
24 return ValueError("Dict key is neither of type String nor Enum!")
  • Comment on lines +17 to +24
    Author Contributor
    Suggested change
    17 def convert_enum_or_string_to_string(input):
    18 if isinstance(input, Enum):
    19 input = input.value
    20
    21 if isinstance(input, str):
    22 return input
    23 else:
    24 return ValueError("Dict key is neither of type String nor Enum!")
    17 def convert_enum_or_string_to_string(input):
    18 if isinstance(input, Enum) and isinstance(input.value, str):
    19 return input.value
    20
    21 if isinstance(input, str):
    22 return input
    23
    24 return ValueError("Dict key is neither of type String nor Enum!")

    I would argue that this style is more readable as each if is selfcontained in the things it does. Therefore when reading it, it is easier to comprehend what is happening.

    By Marcel Krüger on 2022-05-19T13:33:59 (imported from GitLab)

  • Jan Delember changed this line in version 5 of the diff

    changed this line in version 5 of the diff

    By Timon Römer on 2022-05-20T11:37:55 (imported from GitLab)

  • Please register or sign in to reply
  • 10 from enum import Enum
    11 import requests
    12 import random
    13 from config import *
    14
    15
    16 #Receives an enum or a string and converts it to a string. Throws an error if its neither a string nor an enum with a string.
    17 def convert_enum_or_string_to_string(input):
    18 if isinstance(input, Enum):
    19 input = input.value
    20
    21 if isinstance(input, str):
    22 return input
    23 else:
    24 return ValueError("Dict key is neither of type String nor Enum!")
    25
  • 69 def apply_enabled_list(self, list):
    70 assert(len(self) == len(list))
    71
    72 def __len__(self):
    73 return len(self.parameters)
    74
    75 def __getitem__(self, key):
    76 return self.get_value(key)
    77
    78 def apply_enabled_list(self, enable_list):
    79 assert(len(self) == len(enable_list))
    80
    81 for i, key in enumerate(self.parameters):
    82 assert(isinstance(enable_list[i], bool))
    83 self.set_enabled(key, enable_list[i])
    84
    • Author Contributor

      Comment please. What is returned here? Boolean combination of what? What is the return value? Field names, List of boolean?

      By Marcel Krüger on 2022-05-19T13:33:59 (imported from GitLab)

    • Please register or sign in to reply
  • 77
    78 def apply_enabled_list(self, enable_list):
    79 assert(len(self) == len(enable_list))
    80
    81 for i, key in enumerate(self.parameters):
    82 assert(isinstance(enable_list[i], bool))
    83 self.set_enabled(key, enable_list[i])
    84
    85 def boolean_combinations(self):
    86 all_combinations = list(itertools.product([True,False], repeat = len(self)))
    87 for combination in all_combinations:
    88 new_queryparameters = deepcopy(self)
    89 new_queryparameters.apply_enabled_list(combination)
    90 yield new_queryparameters
    91
    92 def __str__(self):
    • Author Contributor

      Especially for printing it is always nice to have a comment describing what is printed. E.g.: prints a list of the query parameters as:

      key value enables
      k1  v1    e1
      k2  v2    e2

      By Marcel Krüger on 2022-05-19T13:33:59 (imported from GitLab)

    • Please register or sign in to reply
  • 85 def boolean_combinations(self):
    86 all_combinations = list(itertools.product([True,False], repeat = len(self)))
    87 for combination in all_combinations:
    88 new_queryparameters = deepcopy(self)
    89 new_queryparameters.apply_enabled_list(combination)
    90 yield new_queryparameters
    91
    92 def __str__(self):
    93 str_result = "{: >20} \t\t {: >20} \t\t {: >20} \n\n".format("key","value","enabled")
    94 for key, (value, enabled) in self.parameters.items():
    95 str_result += "{: >20} \t\t {: >20} \t\t {: >20} \n".format(key,value,enabled)
    96 #return str_result
    97 return str(self.parameters)
    98
    99
    100 #Builds and returns a HTTP-Query String including the given parameters and values
  • 136 @staticmethod
    137 def get_url():
    138 return QueryDebugger.url
    139
    140 @staticmethod
    141 def get_params():
    142 return QueryDebugger.params
    143
    144 @staticmethod
    145 def get_result():
    146 return QueryDebugger.json_result
    147
    148 @staticmethod
    149 def get_status():
    150 return QueryDebugger.status_code
    151
  • 141 def get_params():
    142 return QueryDebugger.params
    143
    144 @staticmethod
    145 def get_result():
    146 return QueryDebugger.json_result
    147
    148 @staticmethod
    149 def get_status():
    150 return QueryDebugger.status_code
    151
    152 @staticmethod
    153 def generate_long_string():
    154 return QueryDebugger.generate_short_string() + "\nResponse:\n" + str(QueryDebugger.json_result)
    155
    156 def generate_short_string():
    • Author Contributor

      Comment please how the resulting string looks like. Also why is this the only function not static?

      By Marcel Krüger on 2022-05-19T13:33:59 (imported from GitLab)

    • Please register or sign in to reply
  • 112 if is_first_parameter:
    113 query_string += "?"
    114 is_first_parameter = False
    115 else:
    116 query_string += "&"
    117
    118 query_string += param_name + "="
    119
    120 if (isinstance(param_value,list)):
    121 query_string += ','.join(map(str,param_value))
    122 else:
    123 query_string += str(param_value)
    124
    125 return query_string
    126
    127
  • 2 import enum
    3 import itertools
    4 import json
    5 from nturl2path import url2pathname
    6 import time
    7 import numbers
    8 import math
    9 import pytest
    10 from enum import Enum
    11 import requests
    12 import random
    13 from test_config import *
    14
    15
    16 #Receives an enum or a string and converts it to a string. Throws an error if its neither a string nor an enum with a string.
    17 def convert_enum_or_string_to_string(input):
  • 12 import random
    13 from test_config import *
    14
    15
    16 #Receives an enum or a string and converts it to a string. Throws an error if its neither a string nor an enum with a string.
    17 def convert_enum_or_string_to_string(input):
    18 if isinstance(input, Enum):
    19 input = input.value
    20
    21 if isinstance(input, str):
    22 return input
    23 else:
    24 return ValueError("Dict key is neither of type String nor Enum!")
    25
    26 #Builds and returns a HTTP-Query String including the given parameters and values
    27 def build_query_string(prefix_string, query_params = None):
  • Jan Delember added 5 commits

    added 5 commits

    • e4f24ee7 - removes test_get_gids
    • b81e261b - simplifies structure of enum to string conversion
    • c8fad339 - adds comment to utility_functions class
    • dfb0b5ca - adds comments regarding the class QueryParameters
    • 45049677 - comments creation of query string

    Compare with previous version

    By Timon Römer on 2022-05-20T11:37:55 (imported from GitLab)

  • Jan Delember added 4 commits

    added 4 commits

    • 45956156 - Removes references to get_gids endpoint
    • 60dfcbb7 - Removes references to get_gid endpoint
    • 32228cbd - Merge branch 'feature/improved_tests' of...
    • 50454936 - adds comments for QueryDebugger class

    Compare with previous version

    By Timon Römer on 2022-05-20T14:04:48 (imported from GitLab)

  • Jan Delember added 1 commit

    added 1 commit

    • 3f6c6030 - Removes duplicate usage of helper_functions

    Compare with previous version

    By Timon Römer on 2022-06-01T15:15:26 (imported from GitLab)

  • Please register or sign in to reply
    Loading