def test_remove_ticket_true(self): rep = UserRepository() user_id = rep.create('name', 'password') rep.assign_ticket(user_id, 'abc') boolean = rep.remove_ticket(user_id, 'abc') self.assertTrue(boolean) rep.delete(user_id)
def test_create(self): rep = UserRepository() id1 = rep.create('name', 'password') id2 = rep.create('name', 'password') self.assertNotEqual(id1, id2) rep.delete(id1) rep.delete(id2)
def test_get_right(self): rep = UserRepository() user_id = rep.create('name', 'password') user1 = rep.get(user_id) user2 = User(user_id=fields.ObjectId(user_id), ticket_ids=[], name='name', password='******') self.assertEqual(user1, user2) rep.delete(user_id)
def post(self): repo = UserRepository() app.logger.info('Получен запрос на создание пользователя') try: payload = jsonpickle.decode(flask.request.data) except: payload = {'name': 'test', 'password': '******'} user_id = repo.create(payload["name"], payload["password"]) user = repo.get(user_id) response = app.make_response("") response.status_code = 201 response.data = user.to_json() response.content_type = "application/json" app.logger.info('Запрос на создание нового пользователя успешно обработан, идентификатор: %s' % user_id) return response
class UserService(object): def __init__(self, user_id=None): self._user_id = user_id self._user_repository = UserRepository() def register_user(self, user_data): ''' Register an user in the webpage user_data: <Dict: {}> return: <User: Model> ''' return self._user_repository.create(user_data) def find_by_id(self, user_id): ''' Find an user by his id ''' return self._user_repository.get(user_id) def get_posts_user(self, user_id): ''' Return all the posts of an user user_id: <int> Return: [<Post: Model>,<Post: Model>,<Post: Model>] ''' return self._user_repository.get_posts_user(user_id) def find_all_related_users_by_username(self, username): ''' Find all the users queried by username username: Str Return: List[ <User: Model> , <User: Model> ] ''' # Esto incluso podria ser un servicio o una clase Helper Search() # que tenga metodos por diferentes criterios de busqueda pass # Seguir a un usuario deberia ir aca por ejemeplo def add_follow(from_user, to_user): ''' Add a follow from a user to another from_user: <User: Model> to_user: <User: Model> ''' pass
def test_exists_true(self): rep = UserRepository() user_id = rep.create('name', 'password') boolean = rep.exists(user_id) self.assertTrue(boolean) rep.delete(user_id)
def test_delete_existed(self): rep = UserRepository() id1 = rep.create('name', 'password') rep.delete(id1) self.assertFalse(rep.exists(id1))
def test_assign_ticket_true(self): rep = UserRepository() user_id = rep.create('l_name', 'p_name') boolean = rep.assign_prod(user_id, 'abc') self.assertTrue(boolean) rep.delete(user_id)