Reputation: 73
For few days I'm trying to lern how to properly use unittest library in Python. I've got some basics but I've made myself a challenge - test two functions that I made before. These are the functions:
def PatternMatch(self, message, number):
ret_status = 2 # 'No match'
ret_pattern = -1
for pattern in self.PatternList:
if pattern.active == 1 and pattern.LA == number:
try:
RegExp = re.compile(pattern.regex)
if RegExp.match(message):
ret_status = 1
ret_pattern = pattern.ID
break
return ret_status, ret_pattern
def GetPattern(self, patternID):
pattern = None
db = Database()
query = 'CALL PATTERN_GET'
query += '(@sql_err_code, @my_status, @my_msg, %s)'
ret = db.query(query, [patternID])
if len(ret['data']) == 2:
pattern = Pattern(ret['data'][1])
else:
pattern = Pattern()
result = {'status': ret['data'][0]}
return pattern, result
How should i start? I have mocked the database connection using the mox library and it works but what about the functionality? I appreciate any help.
Upvotes: 2
Views: 99
Reputation: 28370
Given the generality of the question only general advice is possible - basically you need to prepare test data &/or inputs that will perform the following:
Upvotes: 5