Refactored test_user_creds.py to pytest from unittests

This commit is contained in:
VakarisZ 2021-04-30 15:14:44 +03:00 committed by Mike Salvatore
parent 502bc3b296
commit f28cd5305c
1 changed files with 18 additions and 28 deletions

View File

@ -1,37 +1,27 @@
from unittest import TestCase
from monkey_island.cc.environment.user_creds import UserCreds
class TestUserCreds(TestCase):
def test_to_dict(self):
user_creds = UserCreds()
self.assertDictEqual(user_creds.to_dict(), {})
def test_to_dict_empty_creds():
user_creds = UserCreds()
assert user_creds.to_dict() == {}
user_creds = UserCreds(username="Test")
self.assertDictEqual(user_creds.to_dict(), {"user": "Test"})
user_creds = UserCreds(password_hash="abc1231234")
self.assertDictEqual(user_creds.to_dict(), {"password_hash": "abc1231234"})
def test_to_dict_full_creds():
user_creds = UserCreds(username="Test", password_hash="abc1231234")
assert user_creds.to_dict() == {"user": "Test", "password_hash": "abc1231234"}
user_creds = UserCreds(username="Test", password_hash="abc1231234")
self.assertDictEqual(user_creds.to_dict(), {"user": "Test", "password_hash": "abc1231234"})
def test_to_auth_user(self):
user_creds = UserCreds(username="Test", password_hash="abc1231234")
auth_user = user_creds.to_auth_user()
self.assertEqual(auth_user.id, 1)
self.assertEqual(auth_user.username, "Test")
self.assertEqual(auth_user.secret, "abc1231234")
def test_to_auth_user_full_credentials():
user_creds = UserCreds(username="Test", password_hash="abc1231234")
auth_user = user_creds.to_auth_user()
assert auth_user.id == 1
assert auth_user.username == "Test"
assert auth_user.secret == "abc1231234"
user_creds = UserCreds(username="Test")
auth_user = user_creds.to_auth_user()
self.assertEqual(auth_user.id, 1)
self.assertEqual(auth_user.username, "Test")
self.assertEqual(auth_user.secret, "")
user_creds = UserCreds(password_hash="abc1231234")
auth_user = user_creds.to_auth_user()
self.assertEqual(auth_user.id, 1)
self.assertEqual(auth_user.username, "")
self.assertEqual(auth_user.secret, "abc1231234")
def test_to_auth_user_username_only():
user_creds = UserCreds(username="Test")
auth_user = user_creds.to_auth_user()
assert auth_user.id == 1
assert auth_user.username == "Test"
assert auth_user.secret == ""