def test_user_model_comparison(): init_dict = { "user_id": 1, "username": "******", "password": "******", "email": "*****@*****.**", "createdAt": str(datetime.datetime(2018, 9, 21, 13, 5, 23, 781750)), "updatedAt": str(datetime.datetime(2018, 9, 21, 13, 5, 23, 781750)) } user1 = User.from_dict(init_dict) user2 = User.from_dict(init_dict) assert user1 == user2
def test_serialize_domain_user(): user = User( user_id = 1, username = "******", password = "******", email = "*****@*****.**", createdAt = str(datetime.datetime(2018, 9, 21, 13, 5, 23, 781750)), updatedAt = str(datetime.datetime(2018, 9, 21, 13, 5, 23, 781750)) ) expected_json = f""" {{ "user_id": "1", "username": "******", "password": "******", "email": "*****@*****.**", "createdAt": "{str(datetime.datetime(2018, 9, 21, 13, 5, 23, 781750))}", "updatedAt": "{str(datetime.datetime(2018, 9, 21, 13, 5, 23, 781750))}" }} """ json_user = json.dumps(user, cls=UserJsonEncoder) assert json.loads(json_user) == json.loads(expected_json)
def domain_users(): user1 = User( user_id = 1, username = "******", password = "******", email = "*****@*****.**", createdAt = str(datetime.datetime(2018, 9, 21, 13, 5, 23, 781750)), updatedAt = str(datetime.datetime(2018, 9, 21, 13, 5, 23, 781750)) ) user2 = User( user_id = 2, username = "******", password = "******", email = "*****@*****.**", createdAt = str(datetime.datetime(2015, 6, 21, 13, 5, 23, 781750)), updatedAt = str(datetime.datetime(2015, 6, 23, 13, 5, 23, 781750)) ) user3 = User( user_id = 3, username = "******", password = "******", email = "*****@*****.**", createdAt = str(datetime.datetime(2016, 3, 8, 13, 5, 23, 781750)), updatedAt = str(datetime.datetime(2016, 4, 10, 13, 5, 23, 781750)) ) user4 = User( user_id = 4, username = "******", password = "******", email = "*****@*****.**", createdAt = str(datetime.datetime(2017, 8, 23, 13, 5, 23, 781750)), updatedAt = str(datetime.datetime(2017, 10, 25, 13, 5, 23, 781750)) ) return [user1, user2, user3, user4]
def list(self, filters=None): result = [User.from_dict(i) for i in self.data] if filters is None: return result print(filters) if "user_id__eq" in filters: result = [ r for r in result if r.user_id == int(filters["user_id__eq"]) ] return result
def test_user_model_init(): user = User(user_id=1, username="******", password="******", email="*****@*****.**", createdAt=str(datetime.datetime(2018, 9, 21, 13, 5, 23, 781750)), updatedAt=str(datetime.datetime(2018, 9, 21, 13, 5, 23, 781750))) assert user.user_id == 1 assert user.username == "user" assert user.password == "123" assert user.email == "*****@*****.**" assert user.createdAt == str( datetime.datetime(2018, 9, 21, 13, 5, 23, 781750)) assert user.updatedAt == str( datetime.datetime(2018, 9, 21, 13, 5, 23, 781750))
def test_user_model_from_dict(): init_dict = { "user_id": 1, "username": "******", "password": "******", "email": "*****@*****.**", "createdAt": str(datetime.datetime(2018, 9, 21, 13, 5, 23, 781750)), "updatedAt": str(datetime.datetime(2018, 9, 21, 13, 5, 23, 781750)) } user = User.from_dict(init_dict) assert user.user_id == 1 assert user.username == "user" assert user.password == "123" assert user.email == "*****@*****.**" assert user.createdAt == str( datetime.datetime(2018, 9, 21, 13, 5, 23, 781750)) assert user.updatedAt == str( datetime.datetime(2018, 9, 21, 13, 5, 23, 781750))
def test_repository_list_without_parameters(user_dicts): repo = MemRepo(user_dicts) users = [User.from_dict(i) for i in user_dicts] assert repo.list() == users
from unittest import mock from project.domain.user import User from project.responses import ResponseSuccess user_dict = { "user_id": "1", "username": "******", "password": "******", "email": "*****@*****.**", "createdAt": str(datetime.datetime(2018, 9, 21, 13, 5, 23, 781750)), "updatedAt": str(datetime.datetime(2018, 9, 21, 13, 5, 23, 781750)) } users = [User.from_dict(user_dict)] @mock.patch("application.rest.user.user_list_use_case") def test_get(mock_use_case, client): mock_use_case.return_value = ResponseSuccess(users) http_response = client.get("/users") assert json.loads(http_response.data.decode("UTF-8")) == [user_dict] mock_use_case.assert_called() args, kwargs = mock_use_case.call_args assert args[1].filters == {} assert http_response.status_code == 200