def test_make_text_list_categories(self): add_example_user(session) add_example_category_consumption(session) expected = f"1. {example_category_consumption['category']}\n" self.assertEqual(ConsumptionCategoryManager.make_text_list_categories(session, example_user['telegram_user_id']), expected)
def test_get_all_categories_by_text(self): add_example_user(session) add_example_category_consumption(session) expected = [example_category_consumption['category']] answer = ConsumptionCategoryManager.get_all_categories_by_text(session, example_user['telegram_user_id']) self.assertEqual(answer, expected)
def test_update_category(self): new_category = 'Шаурма' add_example_category_consumption(session) category = session.query(CategoryConsumption).get(1) category.update_category(session, new_category) category = session.query(CategoryConsumption).get(1) self.assertEqual(category.category, new_category)
def test_get_all_categories(self): add_example_user(session) add_example_category_consumption(session) expected = [CategoryConsumption(id=1, user_id=example_user['id'], category=example_category_consumption['category'])] answer = session.query(CategoryConsumption).all() self.assertEqual(answer, expected)
def test_edit_category_in_db(self): add_example_user(session) add_example_category_consumption(session) new_category = 'расход какой то' ConsumptionCategoryManager.edit_category_in_db(session, example_user['telegram_user_id'], example_category_consumption['category'], new_category) answer = session.query(CategoryConsumption).get(1) self.assertEqual(answer.category, new_category)
def test_delete_category_in_db(self): add_example_user(session) add_example_category_consumption(session) ConsumptionCategoryManager.delete_category_in_db(session, example_category_consumption['category'], example_user['telegram_user_id']) expected = None answer = session.query(CategoryConsumption).get(1) self.assertEqual(answer, expected)
def test_exist_category(self): add_example_limit(session) add_example_category_consumption(session) add_example_consumption(session) limit = session.query(Limit).get(1) expected = f"{TypeLimit.text_type(example_limit['type_limit']).title()} " \ f"{example_category_consumption['category']} - {example_limit['amount_money']} р." actual = text_limit(session, limit) self.assertEqual(expected, actual)
def test_make_text_delete_transaction(self): add_example_category_consumption(session) add_example_consumption(session) consumption = session.query(Consumption).get(1) expected = f"Вы уверены, что хотите удалить расход в размере <b>{example_consumption['amount_money']} " \ f"рублей</b> категории <b>{example_category_consumption['category']}</b>, созданный в " \ f"<b>{consumption.get_str_time_creation()}</b>?" self.assertEqual(self.deleter.make_text_delete_transaction(session), expected)
def test_add_consumption_in_db(self): amount_money = 120.120 add_example_user(session) add_example_category_consumption(session) expected = Consumption(id=1, category_id=example_category_consumption['id'], amount_money=amount_money) add_consumption_in_db(session=session, telegram_user_id=example_user['telegram_user_id'], amount_money=amount_money, category_text=example_category_consumption['category']) answer = session.query(Consumption).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_has_any_categories(self): add_example_user(session) add_example_category_consumption(session) self.assertTrue(ConsumptionCategoryManager.check_any_categories(session, example_user['telegram_user_id']))
def test_delete_category(self): add_example_category_consumption(session) category = session.query(CategoryConsumption).get(1) category.delete_category(session) answer = session.query(CategoryConsumption).get(1) self.assertEqual(answer, None)
def test_repr(self): add_example_category_consumption(session) expected = f"<CategoryConsumption('{example_category_consumption['id']}', " \ f"'{example_category_consumption['category']}', '{example_category_consumption['user_id']}')>" category_consumption = session.query(CategoryConsumption).get(example_category_consumption['id']) self.assertEqual(repr(category_consumption), expected)
def test_query_category_consumption(self): add_example_category_consumption(session) expected = [CategoryConsumption(id=1, category='Транспорт')] category_consumption = session.query(CategoryConsumption).all() self.assertEqual(category_consumption, expected)
def setUp(self): Base.metadata.create_all(engine) add_example_user(session) add_example_category_consumption(session)