def test_make_text_list_categories(self): add_example_user(session) add_example_category_earning(session) expected = f"1. {example_category_earning['category']}\n" self.assertEqual( EarningCategoryManager.make_text_list_categories( session, example_user['telegram_user_id']), expected)
def test_update_category(self): new_category = 'Подработка' add_example_category_earning(session) category = session.query(CategoryEarning).get(1) category.update_category(session, new_category) category = session.query(CategoryEarning).get(1) self.assertEqual(category.category, new_category)
def test_get_all_categories_by_text(self): add_example_user(session) add_example_category_earning(session) expected = [example_category_earning['category']] answer = EarningCategoryManager.get_all_categories_by_text( session, example_user['telegram_user_id']) self.assertEqual(answer, expected)
def test_make_text_delete_transaction(self): add_example_category_earning(session) add_example_earning(session) earning = session.query(Earning).get(1) expected = f"Вы уверены, что хотите удалить доход в размере <b>{example_earning['amount_money']} " \ f"рублей</b> категории <b>{example_category_earning['category']}</b>, созданный в " \ f"<b>{earning.get_str_time_creation()}</b>?" self.assertEqual(self.deleter.make_text_delete_transaction(session), expected)
def test_edit_category_in_db(self): add_example_user(session) add_example_category_earning(session) new_category = 'расход какой то' EarningCategoryManager.edit_category_in_db( session, example_user['telegram_user_id'], example_category_earning['category'], new_category) answer = session.query(CategoryEarning).get(1) self.assertEqual(answer.category, new_category)
def test_get_all_categories(self): add_example_user(session) add_example_category_earning(session) expected = [ CategoryEarning(id=1, user_id=example_user['id'], category=example_category_earning['category']) ] answer = session.query(CategoryEarning).all() self.assertEqual(answer, expected)
def test_delete_category_in_db(self): add_example_user(session) add_example_category_earning(session) EarningCategoryManager.delete_category_in_db( session, example_category_earning['category'], example_user['telegram_user_id']) expected = None answer = session.query(CategoryEarning).get(1) self.assertEqual(answer, expected)
def test_add_earning_in_db(self): amount_money = 120.120 add_example_user(session) add_example_category_earning(session) expected = Earning(id=1, category_id=example_category_earning['id'], amount_money=amount_money) add_earning_in_db(session=session, telegram_user_id=example_user['telegram_user_id'], amount_money=amount_money, category_text=example_category_earning['category']) answer = session.query(Earning).get(1) self.assertEqual(answer, expected)
def test_exist_transactions(self): now = datetime.datetime(2020, 1, 22, 10, 10) add_example_user(session) add_example_category_consumption(session) add_example_category_earning(session) add_example_consumption(session, now) add_example_earning(session, now) expected = f"Информация на 22.01.2020 10:10, Среда\n\n" \ f"<b>Расходы:</b>\n" \ f"{example_category_consumption['category']} - {example_consumption['amount_money']} р.\n\n" \ f"<b>Доходы:</b>\n" \ f"{example_category_earning['category']} - {example_earning['amount_money']} р.\n\n" \ f"<b>Всего:</b>\n" \ f"Доход: {example_earning['amount_money']}\n" \ f"Расход: {example_consumption['amount_money']}\n\n" \ f"Хорошего дня!" user = session.query(User).get(1) actual = make_text_today(session, now, user) self.assertEqual(actual, expected)
def test_exist_transactions(self): add_example_user(session) add_example_category_earning(session) add_example_category_consumption(session) session.add( Earning(id=1, time_creation=datetime.datetime(2020, 1, 10, 12, 30, 00), category_id=1, user_id=1)) session.add( Consumption(id=1, time_creation=datetime.datetime( 2020, 1, 9, 12, 30, 00), category_id=1, user_id=1)) session.commit() list_transactions = make_list_transactions( session, example_user['telegram_user_id']) expected = f"Доход 0.0 руб. {example_category_earning['category']} 10.01.2020, 12:30 - /del_e1\n" \ f"Расход 0.0 руб. {example_category_consumption['category']} 09.01.2020, 12:30 - /del_c1\n" actual = make_text_list_transactions(session, list_transactions) self.assertEqual(actual, expected)
def test_delete_category(self): add_example_category_earning(session) category = session.query(CategoryEarning).get(1) category.delete_category(session) answer = session.query(CategoryEarning).get(1) self.assertEqual(answer, None)
def test_repr(self): add_example_category_earning(session) expected = f"<CategoryEarning('{example_category_earning['id']}', " \ f"'{example_category_earning['category']}', '{example_category_earning['user_id']}')>" category_earning = session.query(CategoryEarning).get(1) self.assertEqual(repr(category_earning), expected)
def test_query_category_earning(self): add_example_category_earning(session) expected = [CategoryEarning(id=1, category='Работа')] category_earning = session.query(CategoryEarning).all() self.assertEqual(category_earning, expected)
def setUp(self): Base.metadata.create_all(engine) add_example_user(session) add_example_category_earning(session)
def test_has_any_categories(self): add_example_user(session) add_example_category_earning(session) self.assertTrue( EarningCategoryManager.check_any_categories( session, example_user['telegram_user_id']))