Answer the question
In order to leave comments, you need to log in
I am writing a class + test, I can’t understand why everything breaks?
Hey guys, I'm writing a class and I want to test it.
There is a class. Removed everything superfluous from here, the main thing is to understand the meaning.
from appmodule.database.db import connection
class Task:
@classmethod
def delete(cls, task_id):
try:
cursor = connection.cursor()
sql = 'DELETE FROM task WHERE task_id = 64'
cursor.execute(sql)
connection.close()
except Exception as e:
print(e)
return False
return True
@classmethod
def getById(cls, task_id):
try:
cursor = connection.cursor()
sql = 'SELECT * FROM task WHERE task_id = %s'
cursor.execute(sql, (task_id))
select_rez = cursor.fetchall()
connection.close()
except Exception as e:
return False
return select_rez
class TaskTestCase(unittest.TestCase):
def test_1(self):
rez_get = Task.getById(55)
print(rez_get) # всегда возвращает False
def test_deleteTask(self):
print ( "id: " + self .id())
self.assertFalse(Task.delete('string'))
self.assertTrue(Task.delete(65))
.id: __main__.TaskTestCase.test_deleteTask
(0, '')
(0, '')
self.assertFalse(Task.delete('string'))
self.assertFalse(Task.delete(9999999999999))
if not task_id.isdigit():
return False
if int(task_id) <= 0:
return False
Answer the question
In order to leave comments, you need to log in
well, how many times to repeat that you don’t need to do this, you have an Exception there, and you hush it up
except Exception as e:
return False
(task_id)
(task_id, )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question