Beispiel #1
0
    def get(self, id):
        service = TitleService()

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

        try:
            title = yield service.get(id)
            self.write({'status': 'ok', 'title': title.to_dict()})
        except ResourceNotFoundError:
            self.write({"status": "failed", "errorMessage": "Not found."})
    def get(self, id):
        service = TitleService()

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

        try:
            tags = yield service.get_tags_by_title(id)
            self.write({"status": "ok", "tags": [tag.to_dict() for tag in tags]})
        except ResourceNotFoundError:
            self.write({"status": "failed", "errorMessage": "Title not found."})
    def get(self, id):
        service = TitleService()

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

        titles = yield service.get_all_by_tag(id)
        self.write({
            "status": "ok",
            "titles": [title.to_dict() for title in titles]
        })
    def get(self):
        service = TitleService()

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

        titles = yield service.get_recentlly_added_titles(20)
        self.write({
            "status": "ok",
            "titles": [title.to_dict() for title in titles]
        })
Beispiel #5
0
    def test_remove_not_existed_tag(self):
        title = yield TitleService().create_with_entity(
            self.fixture_with_new_uuid('title'))
        remove_tag_uuid = 'efc5907c-11b6-4a36-8529-044c18e39d10'

        self.assertEquals(len(title.tags), 2)

        yield TitleService().add_tag(
            title.uuid,
            remove_tag_uuid,
            False,
        )

        title = yield TitleService().get(title.uuid)
        self.assertEquals(len(title.tags), 2)
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
Beispiel #7
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
Beispiel #8
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
Beispiel #9
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
Beispiel #10
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))
Beispiel #11
0
    def test_check_duplicates(self, mock_get):
        fake_title = mock.Mock(title_id='ABC-123')
        mock_get.return_value = gen.maybe_future(fake_title)

        dup = yield TitleService().check_duplicates(fake_title)

        mock_get.assert_called_once_with('ABC-123')
        self.assertTrue(dup)
Beispiel #12
0
    def test_title_add_tag_title_not_exists(self, mock_get):
        fake_uuid = 'c736b780-11b6-4190-8529-4d89504b76a0'
        mock_get.return_value = gen.maybe_future(None)

        with self.assertRaises(ResourceNotFoundError):
            yield TitleService().add_tag(fake_uuid, fake_uuid, True)

        mock_get.assert_called_once_with(fake_uuid)
Beispiel #13
0
    def test_get_title_by_id(self, mock_get):
        fake_title = mock.Mock()
        mock_get.return_value = gen.maybe_future(fake_title)

        fake_title_id = 'ABC-123'
        title = yield TitleService().get_by_id(fake_title_id)

        mock_get.assert_called_once_with(fake_title_id)
        self.assertEquals(title, fake_title)
Beispiel #14
0
    def test_get_tags_by_title_not_found(self, mock_get):
        mock_get.return_value = gen.maybe_future(None)

        fake_uuid = 'c736b780-11b6-4190-8529-4d89504b76a0'

        with self.assertRaises(ResourceNotFoundError):
            yield TitleService().get_tags_by_title(fake_uuid)

        mock_get.assert_called_once_with(fake_uuid)
Beispiel #15
0
    def get(self):
        service = TitleService()

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

        if not self.get_argument("id", None, True):
            titles = yield service.get_all()
            self.write({
                "status": "ok",
                "titles": [title.to_dict() for title in titles]
            })
        else:
            title_id = self.get_argument("id", None, True)
            title = yield service.get_by_id(urllib.unquote(title_id))
            if not title:
                self.write({"status": "failed", "errorMessage": "Not found."})
            else:
                self.write({'status': 'ok', 'title': title.to_dict()})
Beispiel #16
0
    def test_get_recentlly_added_titles(self, mock_get):
        fake_titles = [1, 2, 3]
        n = len(fake_titles)
        mock_get.return_value = gen.maybe_future(fake_titles)
        titles = yield TitleService().get_recentlly_added_titles(n)
        mock_get.assert_called_once_with(n)

        self.assertEquals(len(titles), n)
        self.assertEquals(titles, fake_titles)
Beispiel #17
0
    def test_get_all_by_tag(self, mock_get_all_by_tag):
        fake_uuid = 'c736b780-11b6-4190-8529-4d89504b76a0'

        fake_titles = mock.Mock()
        mock_get_all_by_tag.return_value = gen.maybe_future(fake_titles)

        titles = yield TitleService().get_all_by_tag(fake_uuid)

        mock_get_all_by_tag.assert_called_once_with(fake_uuid)
        self.assertEquals(titles, fake_titles)
Beispiel #18
0
    def test_add_existed_tag(self):
        title = yield TitleService().create_with_entity(
            self.fixture_with_new_uuid('title'))
        tag_uuids = [
            'c736b780-11b6-4190-8529-4d89504b76a0',
            'efc5907c-7316-4a36-a910-044c18e39d10'
        ]
        add_tag_uuid = tag_uuids[1]
        self.assertEquals(len(title.tags), 2)
        self.assertEquals(title.tags[0], tag_uuids[0])
        self.assertEquals(title.tags[1], tag_uuids[1])

        yield TitleService().add_tag(
            title.uuid,
            add_tag_uuid,
            True,
        )

        title = yield TitleStore().get(title.uuid)
        self.assertEquals(len(title.tags), 2)
Beispiel #19
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)
            })
Beispiel #20
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)
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
Beispiel #22
0
def gen_mock_service():
    class_name = 'bootcamp.handlers.title.TitleService'
    mock_service = TitleService()
    service_class = patch_class(class_name)
    allow_constructor(service_class).and_return(mock_service)
    return mock_service