def test_register_validation_name_exist(self): with self.assertRaises(ValidationError): repo = MemoryProfileRepo() usecase = RegisterUseCase(repo) profile = Profile('name', Password('mypassword', Sha256Hasher)) usecase.register(profile) # should be success usecase.register(profile) # name should be cannot pass validation
def test_delete_success(self): repo = MemoryProfileRepo() profile = Profile('myname', Password('mypassword', Sha256Hasher)) register_case = RegisterUseCase(repo) delete_case = DeleteUseCase(repo) self.assertTrue(register_case.register(profile)) self.assertTrue(delete_case.remove(profile.name)) check = repo.get_detail(profile.name) self.assertIsNone(check)
def test_get_list_success(self): repo = MemoryProfileRepo() profile1 = Profile('myname', Password('mypassword', Sha256Hasher)) profile2 = Profile('myname2', Password('mypassword', Sha256Hasher)) register_case = RegisterUseCase(repo) register_case.register(profile1) register_case.register(profile2) profiles_case = ProfilesUseCase(repo) profiles = profiles_case.profiles({'names': ['myname', 'myname2']}) self.assertEqual(2, len(profiles)) profile1_from_db = profiles[0] self.assertEqual('myname', profile1_from_db.name)
class RegisterAdapter(object): """Act as proxy from application to core usecase""" def __init__(self, repo: ProfileRepository): self.usecase = RegisterUseCase(repo) def register(self, name: str, password: str) -> Profile: """Register new profile based on given name and password Raises: core.shared.exceptions.ValidationError: if profile not passed validation process core.shared.exceptions.StorageError: if there is an error related with datastorage """ password = Password(raw=password, hasher=Sha256Hasher) profile = Profile(name=name, password=password) return self.usecase.register(profile)
def __init__(self, repo: ProfileRepository): self.usecase = RegisterUseCase(repo)
def test_register_validation_no_password(self): with self.assertRaises(ValidationError): repo = MemoryProfileRepo() usecase = RegisterUseCase(repo) profile = Profile('name', Password('', Sha256Hasher)) usecase.register(profile)
def test_register_success(self): repo = MemoryProfileRepo() usecase = RegisterUseCase(repo) profile = Profile('myname', Password('mypassword', Sha256Hasher)) self.assertTrue(usecase.register(profile))