def test_user_dislike_title(http_client, base_url): user_entity = User(user_name='fg_dislike_video', password='******', email='fgdsb@fgdsb') user = yield UserService().create_with_entity(user_entity) title_entity = Title( title_id='dislike', title='test title 1', video_path='test', file_names=['test file'], description='test des', stars=[str(uuid.uuid4())], video_size=1000000000, rate=8, ) title = yield TitleService().create_with_entity(title_entity) mock_service = gen_mock_service() expect(mock_service).like_title.with_args(user.uuid, title.uuid, False).and_return_future(None) response = yield http_client.fetch(base_url + '/api/users/' + user.uuid + '/like_titles/' + title.uuid + '?like=n') assert response.body == '{"status": "ok"}' assert response.code == httplib.OK
def get(self): user_entity = User(user_name='fg', password='******', email='fgdsb@fgdsb') service = UserService() try: user = yield service.create_with_entity(user_entity) self.write('Added {}'.format(user.uuid)) except EntityAlreadyExistsError: self.write('User name {} exist.'.format(user_entity.user_name))
def test_get_user(http_client, base_url): user_entity = User(user_name='fg', password='******', email='fgdsb@fgdsb') user = yield UserService().create_with_entity(user_entity) mock_service = gen_mock_service() expect(mock_service).get.and_return_future(user) response = yield http_client.fetch(base_url + '/api/users/' + user.uuid) result_object = json.loads(response.body) assert result_object['status'] == 'ok' assert result_object['user'] == user.to_dict() assert response.code == httplib.OK
def test_user_like_stars(http_client, base_url): user_entity = User(user_name='fg_like_stars', password='******', email='fgdsb@fgdsb') user = yield UserService().create_with_entity(user_entity) mock_service = gen_mock_service() expect(mock_service).get_all_liked_stars.and_return_future([]) response = yield http_client.fetch(base_url + '/api/users/' + user.uuid + '/like_stars') assert response.body == '{"status": "ok", "stars": []}' assert response.code == httplib.OK
def test_get_no_liked_titles(self, mock_get_all_by_uuids, mock_get): fake_uuid = 'c736b780-11b6-4190-8529-4d89504b76a0' fake_user = User(liked_titles={}) fake_titles = [] mock_get.return_value = gen.maybe_future(fake_user) mock_get_all_by_uuids.return_value = gen.maybe_future(fake_titles) titles = yield UserService().get_all_liked_titles(fake_uuid) mock_get.assert_called_once_with(fake_uuid) mock_get_all_by_uuids.assert_called_once_with([]) self.assertEquals(titles, fake_titles)
def test_get_user_by_name(http_client, base_url): user_entity = User( user_name='fgbyname', password='******', email='fgdsb@fgdsb' ) user = yield UserService().create_with_entity(user_entity) mock_service = gen_mock_service() expect(mock_service).get_by_name.with_args(user.user_name).and_return_future(user) response = yield http_client.fetch(base_url + '/api/users?user_name=' + user.user_name) assert json.loads(response.body) == {"status": "ok", "user": user.to_dict()} assert response.code == httplib.OK
def test_get_all_liked_titles(self, mock_get_all_by_uuids, mock_get): fake_uuid = 'c736b780-11b6-4190-8529-4d89504b76a0' fake_user = User( liked_titles={'210eb8b3-9b82-4762-add9-0727dc2bcc99': True}) fake_titles = mock.Mock() mock_get.return_value = gen.maybe_future(fake_user) mock_get_all_by_uuids.return_value = gen.maybe_future(fake_titles) titles = yield UserService().get_all_liked_titles(fake_uuid) mock_get.assert_called_once_with(fake_uuid) mock_get_all_by_uuids.assert_called_once_with( ['210eb8b3-9b82-4762-add9-0727dc2bcc99']) self.assertEquals(titles, fake_titles)
def test_user_dislike_star(http_client, base_url): user_entity = User(user_name='fg_dislike_star', password='******', email='fgdsb@fgdsb') user = yield UserService().create_with_entity(user_entity) star_entity = Star(name='fgdislike', hiragana='fgdsb', english_id='fgdsb') star = yield StarService().create_with_entity(star_entity) mock_service = gen_mock_service() expect(mock_service).like_star.with_args(user.uuid, star.uuid, False).and_return_future(None) response = yield http_client.fetch(base_url + '/api/users/' + user.uuid + '/like_stars/' + star.uuid + '?like=n') assert response.body == '{"status": "ok"}' assert response.code == httplib.OK
def post(self): user_name = self.get_body_argument('user_name') password = self.get_body_argument('password') email = self.get_body_argument('email') user = User(user_name=user_name, password=password, email=email) service = UserService() self.set_header('Content-Type', 'application/json') try: user = yield service.create_with_entity(user) self.write({"status": "ok", "uuid": user.uuid}) except EntityAlreadyExistsError: self.write({ "status": "failed", "errorMessage": "User name {} exist.".format(user_name) })
def test_create(self): self.save(self.user) db_user = User.get(self.user.uuid) self.assertIsNotNone(db_user)
def get_by_name(self, user_name): query = User.query().filter(User.user_name == user_name) return query.first()