def test_get_one_my_mock(self): # arrange usecase = UserUsecases(UserDBRepoMock()) test_id = 1 expected_user = UserMother.one().build() # act (result_users, error) = usecase.get_user(test_id) # assert assert result_users.username == expected_user.username
def test_create_user(self): # arrange userdata = userToDict(UserMother.one().build()) usecase = UserUsecases(UserDBRepo()) # act (user, error) = usecase.create_user(userdata) # assert assert error is None assert userdata['username'] == user.username assert userdata['email'] == user.email
def test_get_one_success_london(self, mocker): # arrange usecase = UserUsecases(UserDBRepo()) test_id = 1 expected_user = UserMother.one().build() mocker.patch('modules.DBRepo.UserDBRepo.UserDBRepo.get', return_value=(expected_user, None)) # act (result_users, error) = usecase.get_user(test_id) # assert assert result_users.username == expected_user.username
def test_create_user_no_password(self): # arrange userdata = { 'username': '******', 'email': '*****@*****.**', } usecase = UserUsecases(UserDBRepo()) with pytest.raises(KeyError) as r: # act (user, error) = usecase.create_user(userdata) # assert assert r
def test_create_user_mock(self, mocker): # arrange userdata = userToDict(UserMother.one().build()) usecase = UserUsecases(UserDBRepo()) mocker.patch('modules.DBRepo.UserDBRepo.UserDBRepo.create', return_value=(UserMother.one().build(), None)) # act (user, error) = usecase.create_user(userdata) # assert assert error is None assert userdata['username'] == user.username assert userdata['email'] == user.email
def test_create_user_duple_email(self): # arrange builder = UserMother.one() userdata_1 = userToDict(builder.build()) builder.name = "user122212" userdata_2 = userToDict(builder.build()) usecase = UserUsecases(UserDBRepo()) # act (user_1, error_1) = usecase.create_user(userdata_1) (user_2, error_2) = usecase.create_user(userdata_2) # assert assert error_2 == "invalid_email"
def test_create_user_duple_username(self): # arrange builder = UserMother.one() userdata_1 = userToDict(builder.build()) builder.email = "*****@*****.**" userdata_2 = userToDict(builder.build()) usecase = UserUsecases(UserDBRepo()) # act (user_1, error_1) = usecase.create_user(userdata_1) (user_2, error_2) = usecase.create_user(userdata_2) # assert assert error_2 == "invalid_username"
def get_user_usecase() -> UserUsecases: return UserUsecases(UserDBRepo())