def execute(self, request, presenter):
        """

        :param request:
        :param presenter:
        :return:
        """
        username = request['username']
        password = request['password']
        response = {'user_created': False, 'username': username, 'errors': {}}

        is_valid, errors = validation.validate(
            {'username': username},
            self._validation_schema
        )

        if errors:
            response['errors'] = errors
        elif context.user_repo.exists(username):
            LOGGER.info("create_user: user '{}' already exists".format(username))
            response['errors'] = {'username': ['That username is taken']}
        else:
            user = User(username)
            user.password_hash = create_password_hash(password)
            context.user_repo.save(user)
            response['user_created'] = True

        presenter.present(response)
Exemple #2
0
    def get(self, user_id):
        docs = [doc for doc in self._data if doc['id'] == user_id]
        if docs:
            user = User(docs[0]['id'])
            user.password_hash = docs[0]['password_hash']
            return user

        return NullUser()
Exemple #3
0
    def setUp(self):
        super().setUp()
        self.uc = CreateUserUseCase()
        self.presenter_spy = PresenterSpy()
        self.user = User('user')
        self.user.password_hash = create_password_hash('password')
        context.user_repo.save(self.user)

        self.request = {'username': '******', 'password': '******'}
Exemple #4
0
    def setUp(self):
        super().setUp()
        self.presenter_spy = PresenterSpy()
        self.user = User('user')
        context.user_repo.save(self.user)

        self.usecase = create_bookmark.CreateBookmarkUseCase()
        self.usecase.user_id = self.user.id
        self.usecase.name = 'test name'
        self.usecase.url = 'http://test.com'
Exemple #5
0
    def setUp(self):
        super().setUp()
        self.user = User('user')
        self.user.password_hash = create_password_hash('password')
        context.user_repo.save(self.user)

        self.uc = AuthenticateUserUseCase()
        self.uc.user_id = self.user.id
        self.uc.password = '******'

        self.presenter_spy = PresenterSpy()
    def setUp(self):
        super().setUp()
        self.presenter_spy = PresenterSpy()
        context.user_repo._data = []
        context.bookmark_repo._data = []

        self.user = User('user')
        context.user_repo.save(self.user)

        self.bookmark = Bookmark('id1', self.user.id, 'name',
                                 'http://test.com')
        context.bookmark_repo.save(self.bookmark)
    def test_user_cannot_edit_another_users_bookmark(self):
        other_user = User('other_user')
        context.user_repo.save(other_user)

        uc = edit_bookmark.EditBookmarkUseCase()
        uc.user_id = other_user.id
        uc.bookmark_id = self.bookmark.id
        uc.name = 'name changed'
        uc.url = 'http://test.com'
        uc.execute(self.presenter_spy)

        self.assertTrue(self.presenter_spy.present_called)
        self.assertEqual(self.presenter_spy.response_model.errors['error'],
                         'Forbidden')
Exemple #8
0
 def test_constructor(self):
     user = User('user')
     self.assertEqual(user.id, 'user')
 def to_entity(self, doc):
     user = User(doc['_id'])
     user.password_hash = doc['password_hash']
     return user