Esempio n. 1
0
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
Esempio n. 2
0
def test_get_tag(http_client, base_url):
    title_entity = Title(
            title_id='titleId',
            title='title',
            video_path='video_path',
            file_names=['file_names'],
            description='description',
            maker='maker',
            video_size=1000000,
            stars=[],
            rate=4.2,
            length=121,
            published_date='2011-01-29',
        )
    title = yield TitleService().create_with_entity(title_entity)

    mock_service = gen_mock_service()
    expect(mock_service).get.and_return_future(title)

    response = yield http_client.fetch(base_url + '/api/titles/' + title.uuid)

    result_object = json.loads(response.body)
    assert result_object['status'] == 'ok'
    assert result_object['title'] == title.to_dict()
    assert response.code == httplib.OK
Esempio n. 3
0
def test_get_title_by_id(http_client, base_url):
    title_entity = Title(
        title_id='titleId02',
        title='title',
        video_path='video_path',
        file_names=['file_names'],
        description='description',
        maker='maker',
        video_size=1000000,
        stars=[],
        rate=4.2,
        length=121,
        published_date='2011-01-29',
    )
    title = yield TitleService().create_with_entity(title_entity)

    mock_service = gen_mock_service()
    expect(mock_service).get_by_id.with_args(
        title.title_id).and_return_future(title)

    response = yield http_client.fetch(base_url + '/api/titles?id=' +
                                       title.title_id)

    assert json.loads(response.body) == {
        "status": "ok",
        "title": title.to_dict()
    }
    assert response.code == httplib.OK
Esempio n. 4
0
def test_title_remove_tag(http_client, base_url):
    title_entity = Title(
        title_id='RemoveTag',
        title='title',
        video_path='video_path',
        file_names=['file_names'],
        description='description',
        maker='maker',
        video_size=1000000,
        stars=[],
        rate=4.2,
        length=121,
        published_date='2011-01-29',
    )
    title = yield TitleService().create_with_entity(title_entity)

    tag_entity = Tag(name='PUZ', )
    tag = yield TagService().create_with_entity(tag_entity)

    mock_service = gen_mock_service()
    expect(mock_service).add_tag.with_args(title.uuid, tag.uuid,
                                           False).and_return_future(None)

    response = yield http_client.fetch(base_url + '/api/titles/' + title.uuid +
                                       '/add_tag/' + tag.uuid + '?add=n')
    assert response.body == '{"status": "ok"}'
    assert response.code == httplib.OK
Esempio n. 5
0
 def get(self):
     title_entity = Title(
         title_id='ABC-123',
         title='test title 1',
         video_path='test',
         file_names=['test file'],
         description='test des',
         stars=[str(uuid.uuid4())],
         video_size=1000000000,
         rate=8,
     )
     service = TitleService()
     try:
         title = yield service.create_with_entity(title_entity)
         self.write('Added {}'.format(title.uuid))
     except EntityAlreadyExistsError:
         self.write('{} already exists'.format(title_entity.title_id))
Esempio n. 6
0
    def test_get_all_by_title(self, mock_get_all_by_uuids, mock_get):
        fake_uuid = 'c736b780-11b6-4190-8529-4d89504b76a0'
        fake_title = Title(tags=[
            'c736b780-11b6-4190-8529-4d89504b76a0',
            'efc5907c-7316-4a36-a910-044c18e39d10',
        ], )

        fake_tag_docs = mock.Mock()
        mock_get.return_value = gen.maybe_future(fake_title)
        mock_get_all_by_uuids.return_value = gen.maybe_future(fake_tag_docs)

        tag_docs = yield TitleService().get_tags_by_title(fake_uuid)

        mock_get.assert_called_once_with(fake_uuid)
        mock_get_all_by_uuids.assert_called_once_with([
            'c736b780-11b6-4190-8529-4d89504b76a0',
            'efc5907c-7316-4a36-a910-044c18e39d10',
        ])

        self.assertEquals(tag_docs, fake_tag_docs)
Esempio n. 7
0
    def post(self):
        title_id = self.get_body_argument('title_id')
        title = self.get_body_argument('title')
        video_path = self.get_body_argument('video_path')
        file_names = self.get_body_argument('file_names')
        description = self.get_body_argument('description')
        maker = self.get_body_argument('maker')
        video_size = self.get_body_argument('video_size')
        rate = self.get_body_argument('rate')
        length = self.get_body_argument('length')
        published_date = self.get_body_argument('published_date')

        title_entity = Title(
            title_id=title_id,
            title=title,
            video_path=video_path,
            file_names=file_names,
            description=description,
            maker=maker,
            video_size=video_size,
            rate=rate,
            length=length,
            published_date=published_date,
        )
        service = TitleService()

        self.set_header('Content-Type', 'application/json')

        try:
            title = yield service.create_with_entity(title_entity)
            self.write({"status": "ok", "uuid": title.uuid})
        except EntityAlreadyExistsError:
            self.write({
                "status":
                "failed",
                "errorMessage":
                "Title title_id {} exist.".format(title_id)
            })
def test_title_tags(http_client, base_url):
    title_entity = Title(
        title_id='titleTags',
        title='title',
        video_path='video_path',
        file_names=['file_names'],
        description='description',
        maker='maker',
        video_size=1000000,
        stars=[],
        rate=4.2,
        length=121,
        published_date='2011-01-29',
    )
    title = yield TitleService().create_with_entity(title_entity)

    mock_service = gen_mock_service()
    expect(mock_service).get_tags_by_title.and_return_future([])

    response = yield http_client.fetch(base_url + '/api/titles/' + title.uuid +
                                       '/tags')
    assert response.body == '{"status": "ok", "tags": []}'
    assert response.code == httplib.OK
Esempio n. 9
0
 def get_all_by_tag(self, tag_uuid):
     query = Title.query().filter(Title.tags.any(tag_uuid))
     return query.all()
Esempio n. 10
0
 def get_by_id(self, title_id):
     query = Title.query().filter(Title.title_id == title_id)
     return query.first()
Esempio n. 11
0
 def test_create(self):
     self.save(self.title)
     db_title = Title.get(self.title.uuid)
     self.assertIsNotNone(db_title)