Ejemplo n.º 1
0
    def test_video_ogv_download_only(self):
        """Test BooleanField"""
        # Note: This is dependent on video_reqs.json data.

        data = dict(self.default)

        data['video_ogv_download_only'] = True
        assert len(verify_video_data(data)) == 0

        data['video_ogv_download_only'] = False
        assert len(verify_video_data(data)) == 0

        data['video_ogv_download_only'] = 'True'
        assert len(verify_video_data(data)) == 1
Ejemplo n.º 2
0
    def test_video_ogv_download_only(self):
        """Test BooleanField"""
        # Note: This is dependent on video_reqs.json data.

        data = dict(self.default)

        data['video_ogv_download_only'] = True
        eq_(len(verify_video_data(data)), 0)

        data['video_ogv_download_only'] = False
        eq_(len(verify_video_data(data)), 0)

        data['video_ogv_download_only'] = 'True'
        eq_(len(verify_video_data(data)), 1)
Ejemplo n.º 3
0
    def test_speakers(self):
        """Tests speakers which is a TextArrayField"""
        # Note: This is dependent on video_reqs.json data.

        data = dict(self.default)

        data['speakers'] = []
        assert len(verify_video_data(data)) == 0

        data['speakers'] = ['']
        assert len(verify_video_data(data)) == 1

        data['speakers'] = ['Jimmy Discotheque']
        assert len(verify_video_data(data)) == 0
Ejemplo n.º 4
0
    def test_speakers(self):
        """Tests speakers which is a TextArrayField"""
        # Note: This is dependent on video_reqs.json data.

        data = dict(self.default)

        data['speakers'] = []
        eq_(len(verify_video_data(data)), 0)

        data['speakers'] = ['']
        eq_(len(verify_video_data(data)), 1)

        data['speakers'] = ['Jimmy Discotheque']
        eq_(len(verify_video_data(data)), 0)
Ejemplo n.º 5
0
    def test_default_minimum(self):
        """Verify that default verifies"""
        # Note: This is dependent on video_reqs.json data.

        data = dict(self.default)

        eq_(len(verify_video_data(data)), 0)
Ejemplo n.º 6
0
    def test_default_minimum(self):
        """Verify that default verifies"""
        # Note: This is dependent on video_reqs.json data.

        data = dict(self.default)

        assert len(verify_video_data(data)) == 0
Ejemplo n.º 7
0
    def test_state(self):
        """Test verifying state (IntegerField with choices)"""
        # Note: This is dependent on video_reqs.json data.

        data = dict(self.default)

        data['state'] = 0
        eq_(len(verify_video_data(data)), 1)

        data['state'] = 1
        eq_(len(verify_video_data(data)), 0)

        data['state'] = 2
        eq_(len(verify_video_data(data)), 0)

        data['state'] = 3
        eq_(len(verify_video_data(data)), 1)
Ejemplo n.º 8
0
    def test_state(self):
        """Test verifying state (IntegerField with choices)"""
        # Note: This is dependent on video_reqs.json data.

        data = dict(self.default)

        data['state'] = 0
        assert len(verify_video_data(data)) == 1

        data['state'] = 1
        assert len(verify_video_data(data)) == 0

        data['state'] = 2
        assert len(verify_video_data(data)) == 0

        data['state'] = 3
        assert len(verify_video_data(data)) == 1
Ejemplo n.º 9
0
    def test_state(self):
        """Test verifying state (IntegerField with choices)"""
        # Note: This is dependent on video_reqs.json data.

        data = dict(self.default)

        data['state'] = 0
        assert len(verify_video_data(data)) == 1

        data['state'] = 1
        assert len(verify_video_data(data)) == 0

        data['state'] = 2
        assert len(verify_video_data(data)) == 0

        data['state'] = 3
        assert len(verify_video_data(data)) == 1
Ejemplo n.º 10
0
    def test_minimum_requirements(self):
        """Tests verifying required fields"""
        # Note: This is dependent on video_reqs.json data.

        data = dict(self.default)
        del data['title']
        eq_(len(verify_video_data(data)), 1)

        data = dict(self.default)
        del data['category']
        eq_(len(verify_video_data(data)), 1)

        data = dict(self.default)
        del data['language']
        eq_(len(verify_video_data(data)), 1)

        # Three errors if we pass in an empty dict
        eq_(len(verify_video_data({})), 3)
Ejemplo n.º 11
0
    def test_minimum_requirements(self):
        """Tests verifying required fields"""
        # Note: This is dependent on video_reqs.json data.

        data = dict(self.default)
        del data['title']
        assert len(verify_video_data(data)) == 1

        data = dict(self.default)
        del data['category']
        assert len(verify_video_data(data)) == 1

        data = dict(self.default)
        del data['language']
        assert len(verify_video_data(data)) == 1

        # Three errors if we pass in an empty dict
        assert len(verify_video_data({})) == 3
Ejemplo n.º 12
0
    def test_category(self):
        """Test category variations"""
        # category is none, no data['category']
        data = dict(self.default)
        del data['category']
        assert len(verify_video_data(data, None)) == 1

        # category is something, no data['category']
        assert len(verify_video_data(data, 'Test Category')) == 0

        # category is none, data['category'] = something
        data = dict(self.default)
        assert len(verify_video_data(data, None)) == 0

        # category is something, data['category'] = same something
        assert len(verify_video_data(data, data['category'])) == 0

        # category is something, data['category'] = different something
        assert len(verify_video_data(data, data['category'] + 'abc')) == 1
Ejemplo n.º 13
0
    def test_category(self):
        """Test category variations"""
        # category is none, no data['category']
        data = dict(self.default)
        del data['category']
        eq_(len(verify_video_data(data, None)), 1)

        # category is something, no data['category']
        eq_(len(verify_video_data(data, 'Test Category')), 0)

        # category is none, data['category'] = something
        data = dict(self.default)
        eq_(len(verify_video_data(data, None)), 0)

        # category is something, data['category'] = same something
        eq_(len(verify_video_data(data, data['category'])), 0)

        # category is something, data['category'] = different something
        eq_(len(verify_video_data(data, data['category'] + 'abc')), 1)
Ejemplo n.º 14
0
    def test_minimum_requirements(self):
        """Tests verifying required fields"""
        # Note: This is dependent on video_reqs.json data.

        data = dict(self.default)
        del data['title']
        eq_(len(verify_video_data(data)), 1)

        data = dict(self.default)
        del data['category']
        eq_(len(verify_video_data(data)), 1)

        data = dict(self.default)
        del data['language']
        eq_(len(verify_video_data(data)), 1)

        data = dict(self.default)
        del data['added']
        eq_(len(verify_video_data(data)), 1)

        # Four errors if we pass in an empty dict
        eq_(len(verify_video_data({})), 4)
Ejemplo n.º 15
0
def update_video(api_url, username, auth_key, video_id, video_data):
    """Updates an existing video on the site

    This updates an existing video on the site using HTTP PUT. It
    returns the final video data.


    .. Warning::

       This stomps on the data that's currently there. If you have the
       video_id wrong, then this will overwrite the current data.

       Be very careful about updating existing video data. Best to get
       it, make sure the id is correct (check the title? the slug?),
       and then update it.


    :arg api_url: URL for the api
    :arg username: username
    :arg auth_key: auth key for that username for that API URL
    :arg video_id: The id for the video
    :arg video_data: Python dict holding all the data for this video

    :returns: the updated video data

    :raises steve.restapi.Http4xxException: if the video doesn't
        exist on the server
    :raises steve.restapi.Http5xxException: if there's a server
        error
    :raises steve.richardapi.MissingRequiredData: if the video_data
        is missing keys that are required---check the ``errors``
        property of the exception for a list of errors


    Example::

        import datetime

        from steve.util import update_video, MissingRequiredData

        try:
            video = update_video(
                'http://pyvideo.org/api/v1/',
                'carl',
                'ou812authkey',
                1101,
                {
                    'id': 1101,
                    'category': 'Test Category',
                    'state': 1,
                    'title': 'Test video title',
                    'speakers': ['Jimmy Discotheque'],
                    'language': 'English',
                    'added': datetime.datetime.now().isoformat()
                })

            # Prints the video data.
            print video

        except MissingRequiredData as exc:
            # Prints the errors
            print exc.errors


    .. Note::

       Check the richard project in the video app at ``models.py`` for
       up-to-date list of fields and their types.

       https://github.com/willkg/richard/blob/master/richard/videos/models.py

    """
    # If you do a create_video, then update that data and do an
    # update_video, the data has 'resource_uri' in it. We want to nix
    # that if it's there.
    video_data.pop('resource_uri', None)

    errors = verify_video_data(video_data)

    if errors:
        raise MissingRequiredData(
            'video data has errors', errors=errors)

    api = restapi.API(api_url)

    # Try to get the video on the site. This will kick up a 404
    # if it doesn't exist.
    api.video(video_id).get(username=username, api_key=auth_key)

    # Everything is probably fine, so try to update the data.
    return restapi.get_content(
        api.video(video_id).put(data=video_data,
                                username=username,
                                api_key=auth_key))
Ejemplo n.º 16
0
def create_video(api_url, auth_token, video_data):
    """Creates a video on the site

    This creates a video on the site using HTTP POST. It returns
    the video data it posted which also contains the id.

    .. Note::

       This doesn't yet check to see if the video already exists.

    :arg api_url: URL for the api
    :arg auth_token: auth token
    :arg video_data: Python dict holding the values to create
        this video

    :returns: the video data

    :raises steve.restapi.Http5xxException: if there's a server
        error
    :raises steve.richardapi.MissingRequiredData: if the video_data
        is missing keys that are required

    Example::

        import datetime

        from steve.util import STATE_LIVE, create_video, MissingRequiredData

        try:
            video = create_video(
                'http://pyvideo.org/api/v1/',
                auth_token='ou812authkey',
                video_data={
                    'category': 'Test Category',
                    'state': STATE_LIVE,
                    'title': 'Test video title',
                    'speakers': ['Jimmy Discotheque'],
                    'language': 'English',
                    'added': datetime.datetime.now().isoformat()
                })

            # Prints the video data.
            print video

        except MissingRequiredData as exc:
            # Prints the errors
            print exc


    .. Note::

       Check the richard project in the video app at ``models.py`` for
       up-to-date list of fields and their types.

       https://github.com/pyvideo/richard/blob/master/richard/videos/models.py

    """
    errors = verify_video_data(video_data)

    if errors:
        raise MissingRequiredData('video data has errors: {0}'.format(
            repr(errors)))

    # TODO: Check to see if the video exists already. Probably
    # want to use (category, title) as a key.

    api = restapi.API(api_url)
    return restapi.get_content(
        api.video.post(data=video_data, auth_token=auth_token))
Ejemplo n.º 17
0
def update_video(api_url, auth_token, video_id, video_data):
    """Updates an existing video on the site

    This updates an existing video on the site using HTTP PUT. It
    returns the final video data.

    .. Warning::

       This stomps on the data that's currently there. If you have the
       video_id wrong, then this will overwrite the current data.

       Be very careful about updating existing video data. Best to get
       it, make sure the id is correct (check the title? the slug?),
       and then update it.


    :arg api_url: URL for the api
    :arg auth_token: auth token
    :arg video_id: The id for the video
    :arg video_data: Python dict holding all the data for this video

    :returns: the updated video data

    :raises steve.restapi.Http4xxException: if the video doesn't
        exist on the server
    :raises steve.restapi.Http5xxException: if there's a server
        error
    :raises steve.richardapi.MissingRequiredData: if the video_data
        is missing keys that are required


    Example::

        import datetime

        from steve.util import STATE_LIVE, update_video, MissingRequiredData

        try:
            video = update_video(
                'http://pyvideo.org/api/v1/',
                auth_token='ou812authkey',
                video_id=1101,
                video_data={
                    'id': 1101,
                    'category': 'Test Category',
                    'state': STATE_LIVE,
                    'title': 'Test video title',
                    'speakers': ['Jimmy Discotheque'],
                    'language': 'English',
                    'added': datetime.datetime.now().isoformat()
                })

            # Prints the video data.
            print video

        except MissingRequiredData as exc:
            # Prints the errors
            print exc


    .. Note::

       Check the richard project in the video app at ``models.py`` for
       up-to-date list of fields and their types.

       https://github.com/pyvideo/richard/blob/master/richard/videos/models.py

    """
    # If you do a create_video, then update that data and do an
    # update_video, the data has a few fields in it that shouldn't be
    # there. We nix those here.
    video_data.pop('resource_uri', None)
    video_data.pop('added', None)

    errors = verify_video_data(video_data)

    if errors:
        raise MissingRequiredData('video data has errors: {0}'.format(
            repr(errors)))

    api = restapi.API(api_url)

    # Try to get the video on the site. This will kick up a 404
    # if it doesn't exist.
    api.video(video_id).get(auth_token=auth_token)

    # Everything is probably fine, so try to update the data.
    return restapi.get_content(
        api.video(video_id).put(data=video_data, auth_token=auth_token))
Ejemplo n.º 18
0
def create_video(api_url, username, auth_key, video_data):
    """Creates a video on the site

    This creates a video on the site using HTTP POST. It returns
    the video data it posted which also contains the id.

    .. Note::

       This doesn't yet check to see if the video already exists.

    :arg api_url: URL for the api
    :arg username: username
    :arg auth_key: auth key for that username for that API URL
    :arg video_data: Python dict holding the values to create
        this video

    :returns: the video data

    :raises steve.restapi.Http5xxException: if there's a server
        error
    :raises steve.richardapi.MissingRequiredData: if the video_data
        is missing keys that are required---check the ``errors``
        property of the exception for a list of errors

    Example::

        import datetime

        from steve.util import create_video, MissingRequiredData

        try:
            video = create_video(
                'http://pyvideo.org/api/v1/',
                'carl',
                'ou812authkey',
                {
                    'category': 'Test Category',
                    'state': 1,
                    'title': 'Test video title',
                    'speakers': ['Jimmy Discotheque'],
                    'language': 'English',
                    'added': datetime.datetime.now().isoformat()
                })

            # Prints the video data.
            print video

        except MissingRequiredData as exc:
            # Prints the errors
            print exc.errors


    .. Note::

       Check the richard project in the video app at ``models.py`` for
       up-to-date list of fields and their types.

       https://github.com/willkg/richard/blob/master/richard/videos/models.py

    """
    errors = verify_video_data(video_data)

    if errors:
        raise MissingRequiredData(
            'video data has errors', errors=errors)

    # TODO: Check to see if the video exists already. Probably
    # want to use (category, title) as a key.

    api = restapi.API(api_url)
    return restapi.get_content(
        api.video.post(data=video_data,
                       username=username,
                       api_key=auth_key))