Example #1
0
def test_clean_only_image(image):
    """
    Cleaning a media resource that only has an image should do nothing.
    """
    resource = models.MediaResource(image=image)

    resource.clean()
def test_resolve_youtube_id_with_id():
    """
    If the media resource has a YouTube video ID, it should be returned.
    """
    resource = models.MediaResource(youtube_id="dQw4w9WgXcQ")
    result = schema.MediaResourceType.resolve_youtube_id(resource, None)

    assert result == resource.youtube_id
def test_resolve_youtube_id_no_id():
    """
    If the media resource does not have a YouTube video ID, the field
    should resolve to ``None``.
    """
    resource = models.MediaResource()

    assert schema.MediaResourceType.resolve_youtube_id(resource, None) is None
def test_resolve_image_no_image():
    """
    If a media resource has no image, the field should resolve to
    ``None``.
    """
    resource = models.MediaResource()

    assert schema.MediaResourceType.resolve_image(resource, None) is None
Example #5
0
def test_type_youtube():
    """
    If a media resource has a YouTube video ID, its type property should
    indicate it's a YouTube video.
    """
    resource = models.MediaResource(youtube_id="dQw4w9WgXcQ")

    assert resource.type == models.MediaResource.TYPE_YOUTUBE
Example #6
0
def test_type_image(image):
    """
    If a media resource has an image, its type property should indicate
    it's an image.
    """
    resource = models.MediaResource(image=image)

    assert resource.type == models.MediaResource.TYPE_IMAGE
Example #7
0
def test_clean_only_youtube_id():
    """
    Cleaning a media resource that only has a YouTube video ID should do
    nothing.
    """
    resource = models.MediaResource(youtube_id="dQw4w9WgXcQ")

    resource.clean()
Example #8
0
def test_clean_no_image_or_youtube_id():
    """
    If a media resource does not encapsulate any media, cleaning it
    should throw an error.
    """
    resource = models.MediaResource()

    with pytest.raises(ValidationError):
        resource.clean()
Example #9
0
def test_clean_both_image_and_youtube_id(image):
    """
    If a media resource has both an image and YouTube video ID specified
    then cleaning it should throw an error.
    """
    resource = models.MediaResource(image=image, youtube_id="dQw4w9WgXcQ")

    with pytest.raises(ValidationError):
        resource.clean()
def test_resolve_image_with_image(image, rf):
    """
    If a media resource has an image, the field should resolve to the
    URL of the media resource's image.
    """
    resource = models.MediaResource(image=image)
    request = rf.get("/")
    info = DummyInfo(request)

    expected = request.build_absolute_uri(resource.image.url)

    assert schema.MediaResourceType.resolve_image(resource, info) == expected