def test_save_answer(): create_tables() create_user() new_question = QuestionModel('My simple title', 'My simple question') new_question.save(1) samp_answer = AnswerModel("This is my sample answer") samp_answer.add_answer(1, 'lazarus') teardown()
def test_delete(): create_tables() create_user() new_question = QuestionModel('My simple title', 'My simple question') new_question.save(1) samp_answer = AnswerModel("This is my sample answer") samp_answer.add_answer(1, 'lazarus') answer = AnswerModel.find_by_id(1, 1) assert answer.delete(1) == True teardown()
def test_json(): create_tables() create_user() my_question = QuestionModel('Json title', 'Json description') my_question.save(1) question_query = QuestionModel.find_by_id(1) assert question_query.json() == { "title": 'Json title', "description": 'Json description' } teardown()
def test_delete(): """ GIVEN a new question saved WHEN a new query is passed for deletion THEN it should return True """ create_tables() create_user() new_question = QuestionModel('This is a sample title', 'This is a sample description') new_question.save(1) question = QuestionModel.find_by_id(1) assert question.delete() == True teardown()
def test_question_find_by_description(): """ Given a new question saved When a query is called by description Then a boolean is returned, check if the fields are correct """ create_tables() create_user() new_question = QuestionModel('This is a sample 1 title', 'This is a sample 1 description') new_question.save(1) #It's the first to be stored hence id == 1 question = QuestionModel.find_by_description( 'This is a sample 1 description') assert question == True teardown()
def setUp(self): """Set up test variables.""" # initialize the test client self.app = app self.client = self.app.test_client # This is the user test json data with a predefined email and password self.new_user = { 'username': '******', "email": "*****@*****.**", 'password': '******' } with self.app.app_context(): teardown()
def setUp(self): self.app = app self.client = app.test_client self.question = { "title": "This is title 1", "description": "This is description 1" } self.question1 = { "title": "This is title 1", "description": "This is description 2" } self.answer = { "answer": "This is answer 1" } self.answer1 = { "answer": "This is answer 2" } with self.app.app_context(): teardown()
def test_question_find_by_id(): """ Given a new question saved When a query is called by id Then a new object should be returned, check if the fields are correct """ create_tables() create_user() new_question = QuestionModel('This is a sample 1 title', 'This is a sample 1 description') new_question.save(1) #It's the first to be stored hence id == 1 question = QuestionModel.find_by_id(1) assert question.title == 'This is a sample 1 title' new_question1 = QuestionModel('This is a sample 2 title', 'This is a sample 2 description') new_question1.save(1) question1 = QuestionModel.find_by_id(2) assert question1.title == 'This is a sample 2 title' teardown()