from plone.namedfile.testing import PLONE_NAMEDFILE_INTEGRATION_TESTING
from plone.namedfile.tests.test_blobfile import registerUtilities
from ploneintranet.testing import dummy_file
from ploneintranet.workspace.behaviors.file import FileField

import unittest


def _makeOne():
    class Dummy:
        pass

    dummy = Dummy()
    return FileField(dummy)


class TestFileFieldBehavior(unittest.TestCase):

    layer = PLONE_NAMEDFILE_INTEGRATION_TESTING

    def setUp(self):
        registerUtilities()

    def test_file_field_is_audiotype(self):
        ob = _makeOne()
        ob.context.file = dummy_file("test.mp3")
        self.assertTrue(ob.is_audiotype)
        self.assertFalse(ob.is_videotype)

    def test_file_field_is_videotype(self):
        ob = _makeOne()
        ob.context.file = dummy_file("test.mp4")
        self.assertFalse(ob.is_audiotype)
        self.assertTrue(ob.is_videotype)
