def test_send_result_email(self, send_email_mock): result = Book.find_for_query('hello') message = utils.format_result(result) subject = 'Results for your query: "hello"' sender = 'noreply@book_search.com' utils.send_result_email('*****@*****.**', 'hello', result) send_email_mock.assert_called_once_with(subject, message, sender, ['*****@*****.**'])
def search_for_query(query, email, time_limit): """Looking for query in all books stored in database. In the end of search sent an email with results. :param query: Query to look for. :param email: Email to send results to. :param time_limit: Limit query in time(seconds). """ logger.info("Search started...") result = Book.find_for_query(query, time_limit) logger.info('Search finished!') send_result_email(email, query, result) logger.info('Message to %s has been sent!', email)
def test_extract_results(self): result = Book.find_for_query('hello') formatted = utils.format_result(result) self.assertTrue( 'Results for query "hello". Matches found: 1' in formatted)
def test_find_for_query_multiple_match(self): result = Book.find_for_query('About') self.assertEqual(len(result['matches']), 2) self.assertEqual(result['matches'][0]['title'], 'Test') self.assertEqual(result['matches'][1]['title'], 'Pro Python')
def test_find_for_query_not_exists(self): result = Book.find_for_query('Not exists') self.assertEqual(len(result['matches']), 0)
def test_find_for_query_exists(self): result = Book.find_for_query('hello') self.assertEqual(len(result['matches']), 1) self.assertEqual(result['matches'][0]['title'], 'Test') self.assertEqual(result['matches'][0]['page'], 1)