def test_create_transaction(database, mock_message): character_hash = User.create_user(2, 2, "Test user", database) character_hash_2 = User.create_user(3, 3, "Test user 2", database) client = BankingClientFactory(database).create_client(mock_message) double_amount = DEFAULT_FINANCES * 2 half_amount = DEFAULT_FINANCES / 2 user2 = client.get_user_by_user_hash(character_hash_2) user1 = client.get_user_by_user_hash(character_hash) assert user2.finances == DEFAULT_FINANCES assert user1.finances == DEFAULT_FINANCES with pytest.raises(TransactionError): client.create_transaction(f"/send {character_hash_2} {double_amount}") with pytest.raises(TransactionError): client.create_transaction(f"/send {character_hash} {half_amount}") with pytest.raises(TransactionError): client.create_transaction(f"/send {character_hash_2} notanumber") with pytest.raises(TransactionError): client.create_transaction(f"/send {character_hash_2} 0") with pytest.raises(UserError): client.create_transaction(f"/send 1234567890 {half_amount}") sender_chat_id, reciever_chat_id, message = client.create_transaction( f"/send {character_hash_2} {half_amount}") user2 = client.get_user_by_user_hash(character_hash_2) user1 = client.get_user_by_user_hash(character_hash) assert user2.finances == DEFAULT_FINANCES + half_amount assert user1.finances == DEFAULT_FINANCES - half_amount assert sender_chat_id == user1.chat_id assert reciever_chat_id == user2.chat_id
def test_delete_user(database, mock_message): User.create_admin(2, 2, database) character_hash = User.create_user(3, 3, "Test user", database) client = BankingClientFactory(database).create_client(mock_message) assert client.get_user_by_user_hash(character_hash) is not None client.delete_user(f"/delete {character_hash}") with pytest.raises(UserError): client.get_user_by_user_hash(character_hash)
def test_create_hacked_transaction_other(database, mock_message): User.create_admin(1, 1, database) character_hash = User.create_user(2, 2, "Test user", database) User.update_db_value(character_hash, "hacker_level", 1, database) character_hash_2 = User.create_user(3, 3, "Test user 2", database) character_hash_4 = User.create_user(4, 4, "Test user 4", database) character_hash_5 = User.create_user(5, 5, "Test user 5", database) User.update_db_value(character_hash_4, "hacker_defence", 1, database) client = BankingClientFactory(database).create_client(mock_message) double_amount = DEFAULT_FINANCES * 2 half_amount = DEFAULT_FINANCES / 2 user2 = client.get_user_by_user_hash(character_hash_2) user1 = client.get_user_by_user_hash(character_hash) assert user2.finances == DEFAULT_FINANCES assert user1.finances == DEFAULT_FINANCES with pytest.raises(TransactionError): client.create_hacker_transaction_other( f"/h@ck_theft_other {character_hash_2} {character_hash_5} {double_amount}" ) with pytest.raises(TransactionError): client.create_hacker_transaction_other( f"/h@ck_theft_other {character_hash} {character_hash_5} {half_amount}" ) with pytest.raises(TransactionError): client.create_hacker_transaction_other( f"/h@ck_theft_other {character_hash_2} {character_hash_5} notanumber" ) with pytest.raises(TransactionError): client.create_hacker_transaction_other( f"/h@ck_theft_other {character_hash_2} {character_hash_5} 0") with pytest.raises(UserError): client.create_hacker_transaction_other( f"/h@ck_theft_other 1234567890 {character_hash_5} {half_amount}") with pytest.raises(HackerError): client.create_hacker_transaction_other( f"/h@ck_theft_other 0000000000 {character_hash_5} {half_amount}") hacker_hash, victim_chat_id, profiteer_chat_id, transaction_message, show_hack = client.create_hacker_transaction_other( f"/h@ck_theft_other {character_hash_2} {character_hash_5} {half_amount}" ) user2 = client.get_user_by_user_hash(character_hash_2) user5 = client.get_user_by_user_hash(character_hash_5) assert user2.finances == DEFAULT_FINANCES - half_amount assert user5.finances == DEFAULT_FINANCES + half_amount assert hacker_hash == client.user.character_hash assert victim_chat_id == user2.chat_id assert not show_hack hacker_hash, victim_chat_id, profiteer_chat_id, transaction_message, show_hack = client.create_hacker_transaction_other( f"/h@ck_theft_other {character_hash_4} {character_hash_5} {half_amount}" ) user4 = client.get_user_by_user_hash(character_hash_4) user5 = client.get_user_by_user_hash(character_hash_5) assert hacker_hash == client.user.character_hash assert victim_chat_id == user4.chat_id assert user4.finances == DEFAULT_FINANCES - half_amount assert user5.finances == DEFAULT_FINANCES + half_amount + half_amount assert show_hack
def test_inspect_user(database, mock_message): User.create_admin(2, 2, database) character_hash = User.create_user(3, 3, "Test user", database) client = BankingClientFactory(database).create_client(mock_message) user = client.get_user_by_user_hash("0000000000") user2 = client.get_user_by_user_hash(character_hash) assert client.inspect_user() == str(user) assert client.inspect_user(character_hash) == str(user2) with pytest.raises(UserError): client.inspect_user("1234567890")
def test_set_attribute(database, mock_message): User.create_admin(2, 2, database) character_hash = User.create_user(3, 3, "Test user", database) client = BankingClientFactory(database).create_client(mock_message) user = client.get_user_by_user_hash(character_hash) assert user.finances == DEFAULT_FINANCES with pytest.raises(UserError): client.set_attribute("/set_attribute 1234567890 finances 0") assert client.set_attribute(f"/set_attribute {character_hash} finances 0" ) == ATTRIBUTE_UPDATE_MESSAGE user = client.get_user_by_user_hash(character_hash) assert user.finances == 0
def test_admin_inspect_user(database, mock_message): User.create_admin(2, 2, database) client = BankingClientFactory(database).create_client(mock_message) character_hash_2 = User.create_user(3, 3, "Test user 2", database) user2 = client.get_user_by_user_hash(character_hash_2) with pytest.raises(UserError): client.admin_inspect_user("/admin_inspect_user 1234567890") resulting_data = client.admin_inspect_user( f'/admin_inspect_user {character_hash_2}') assert resulting_data == str(user2)
def test_prepare_message(database, mock_message): User.create_admin(1, 1, database) character_hash = User.create_user(2, 2, "Test user", database) client = BankingClientFactory(database).create_client(mock_message) admin = client.get_user_by_user_hash("0000000000") with pytest.raises(UserError): client.prepare_message("/message 1234567890 LaLaLaLa") with pytest.raises(MessageError): client.prepare_message(f"/message {client.user.character_hash} LaLaLaLa") chat_id, message = client.prepare_message("/message 0000000000 LaLaLaLa") assert message == "LaLaLaLa" assert chat_id == admin.chat_id
def test_hack_send_hacked_message(database, mock_message): User.create_admin(1, 1, database) character_hash = User.create_user(2, 2, "Test user", database) User.update_db_value(character_hash, "hacker_level", 1, database) client = BankingClientFactory(database).create_client(mock_message) character_hash_2 = User.create_user(3, 3, "Test user 2", database) character_hash_4 = User.create_user(4, 4, "Test user 4", database) User.update_db_value(character_hash_4, "hacker_defence", 1, database) user2 = client.get_user_by_user_hash(character_hash_2) user4 = client.get_user_by_user_hash(character_hash_4) with pytest.raises(UserError): client.prepare_hacker_message("/h@ck_message 1234567890 OLOLO") chat_id, sent_message, show_hack = client.prepare_hacker_message( f'/h@ck_message {character_hash_2} OLOLO') assert sent_message == "OLOLO" assert chat_id == user2.chat_id assert not show_hack with pytest.raises(HackerError): client.hack_inspect_user(f'/h@ck_message 0000000000 OLOLO') chat_id, sent_message, show_hack = client.prepare_hacker_message( f'/h@ck_message {character_hash_4} OLOLO') assert sent_message == "OLOLO" assert chat_id == user4.chat_id assert show_hack
def test_hack_inspect_user(database, mock_message): User.create_admin(1, 1, database) character_hash = User.create_user(2, 2, "Test user", database) User.update_db_value(character_hash, "hacker_level", 1, database) client = BankingClientFactory(database).create_client(mock_message) character_hash_2 = User.create_user(3, 3, "Test user 2", database) character_hash_4 = User.create_user(4, 4, "Test user 4", database) User.update_db_value(character_hash_4, "hacker_defence", 1, database) user2 = client.get_user_by_user_hash(character_hash_2) user4 = client.get_user_by_user_hash(character_hash_4) with pytest.raises(UserError): client.hack_inspect_user("/hack 1234567890") resulting_data, chat_id, show_hack = client.hack_inspect_user( f'/hack {character_hash_2}') assert resulting_data == user2.hack_result assert chat_id == user2.chat_id assert not show_hack with pytest.raises(HackerError): client.hack_inspect_user(f'/hack 0000000000') resulting_data, chat_id, show_hack = client.hack_inspect_user( f'/hack {character_hash_4}') assert resulting_data == user4.hack_result assert chat_id == user4.chat_id assert show_hack
def test_inspect_self(database, mock_message): User.create_admin(2, 2, database) client = BankingClientFactory(database).create_client(mock_message) user = client.get_user_by_user_hash("0000000000") assert client.inspect_self() == str(user)
def test_get_user_by_user_hash(database, mock_message): character_hash = User.create_user(2, 2, "Test user", database) client = BankingClientFactory(database).create_client(mock_message) with pytest.raises(UserError): client.get_user_by_user_hash("0000000000") assert client.get_user_by_user_hash(character_hash) is not None