def channel():
    with cc.ContentNode.objects.delay_mptt_updates():
        root = mixer.blend(cc.ContentNode, title="root", parent=None, kind=topic())
        level1 = mixer.blend(cc.ContentNode, parent=root, kind=topic())
        level2 = mixer.blend(cc.ContentNode, parent=level1, kind=topic())
        leaf = mixer.blend(cc.ContentNode, parent=level2, kind=video())
        leaf2 = mixer.blend(cc.ContentNode, parent=level2, kind=exercise(), title='EXERCISE 1', extra_fields={
            'mastery_model': 'do_all',
            'randomize': True
        })
        mixer.blend(cc.ContentNode, parent=level2, kind=slideshow(), title="SLIDESHOW 1", extra_fields={})

        video_file = fileobj_video()
        video_file.contentnode = leaf
        video_file.save()

        item = assessment_item()
        item.contentnode = leaf2
        item.save()

        item2 = assessment_item()
        item2.contentnode = leaf2
        item2.save()

        item3 = assessment_item()
        item3.contentnode = leaf2
        item3.save()

        item4 = assessment_item()
        item4.contentnode = leaf2
        item4.save()

    channel = mixer.blend(cc.Channel, main_tree=root, name='testchannel', thumbnail=str(thumbnail()))

    return channel
示例#2
0
def fileformat_mp4():
    """
    Create an mp4 FileFormat entry.
    """
    return mixer.blend(cc.FileFormat,
                       extension='mp4',
                       mimetype='application/video')
示例#3
0
    def test_editors_can_access_invitations(self):
        """
        This checks that editors for a channel can still access invitations for the same channel
        even if they weren't the ones who sent them
        """
        guestuser = User.objects.create(email="*****@*****.**")
        testuser = User.objects.create(email="*****@*****.**")
        testviewonlyuser = User.objects.create(
            email="*****@*****.**")
        invitation = mixer.blend(Invitation,
                                 channel=self.channel,
                                 sender=self.user,
                                 invited=guestuser)
        self.channel.editors.add(testuser)
        self.channel.viewers.add(testviewonlyuser)

        # Editors should have access
        self.client.force_authenticate(testuser)
        response = self.get('/api/invitation/{}'.format(invitation.pk))
        self.assertEqual(response.status_code, 200)

        # Viewers shoudl have access
        self.client.force_authenticate(testviewonlyuser)
        response = self.get('/api/invitation/{}'.format(invitation.pk))
        self.assertEqual(response.status_code, 200)
 def setUp(self):
     super(ChannelSetTestCase, self).setUp()
     self.channelset = mixer.blend(ChannelSet, editors=[self.user])
     self.channels = mixer.cycle(10).blend(
         Channel,
         secret_tokens=[self.channelset.secret_token],
         editors=[self.user])
示例#5
0
def fileformat_perseus():
    """
    Create a perseus FileFormat entry.
    """
    return mixer.blend(cc.FileFormat,
                       extension='perseus',
                       mimetype='application/exercise')
def assessment_item2():
    answers = "[{\"correct\": true, \"answer\": \"Eggs\", \"help_text\": \"\"}, " \
              "{\"correct\": true, \"answer\": \"Tofu\", \"help_text\": \"\"}, " \
              "{\"correct\": true, \"answer\": \"Meat\", \"help_text\": \"\"}, " \
              "{\"correct\": true, \"answer\": \"Beans\", \"help_text\": \"\"}, " \
              "{\"correct\": false, \"answer\": \"Rice\", \"help_text\": \"\"}]"
    return mixer.blend(cc.AssessmentItem, question='Which of the following are proteins?',
                       type='multiple_selection', answers=answers)
示例#7
0
def create_studio_file(filebytes,
                       preset='document',
                       ext='pdf',
                       original_filename=None):
    """
    Create a file with contents of `filebytes` and the associated cc.File object for it.
    :param filebytes: The data to be stored in the file (as bytes)
    :param preset: String identifying the format preset (defaults to ``document``)
    :param ext: File extension, omitting the initial period
    :param original_filename: Original filename (needed for exercise_images)
    Returns a dict containing the following:
    - name (str): the filename within the content storage system (= md5 hash of the contents + .ext )
    - data (bytes): file content (echo of `filebytes`)
    - file (file): a basic BytesIO file-like object that you can read/write
    - db_file (cc.File): a Studio File object saved in DB
    """
    try:
        filebytes = filebytes.encode('utf-8')
    except:  # noqa
        pass

    fileobj = BytesIO(filebytes)
    # Every time the BytesIO object is read from or appended to, we need to reset the seek position,
    # otherwise, it will start reading from the end of the file.
    fileobj.seek(0)
    hash = hashlib.md5(filebytes)
    checksum = hash.hexdigest()
    filename = "{}.{}".format(checksum, ext)
    storage_file_path = cc.generate_object_storage_name(checksum, filename)

    # 1. Write out the file bytes on to object storage
    fileobj.seek(0)
    default_storage.save(storage_file_path, fileobj)
    fileobj.seek(0)
    assert default_storage.exists(storage_file_path)

    # 2. Get the minimum required Studio meta fields for a File object
    preset = cc.FormatPreset.objects.get(id=preset)
    file_format = cc.FileFormat.objects.get(extension=ext)
    if original_filename is None:
        original_filename = 'somefile.' + ext

    # 3. Create a File object
    db_file_obj = mixer.blend(cc.File,
                              checksum=checksum,
                              file_format=file_format,
                              preset=preset,
                              original_filename=original_filename,
                              file_on_disk=storage_file_path)

    return {
        'name': os.path.basename(storage_file_path),
        'data': filebytes,
        'file': fileobj,
        'db_file': db_file_obj
    }
 def test_get_user_channel_sets(self):
     """ Make sure get_user_channel_sets returns the correct sets """
     other_channelset = mixer.blend(ChannelSet)
     response = self.get(reverse_lazy("get_user_channel_sets"))
     self.assertEqual(response.status_code, 200)
     channelsets = json.loads(response.content)
     self.assertTrue(any(c['id'] == self.channelset.pk
                         for c in channelsets))
     self.assertFalse(
         any(c['id'] == other_channelset.pk for c in channelsets))
示例#9
0
def license_wtfpl():
    """
    Create a license object called WTF License.
    """
    return cc.License.objects.first() or mixer.blend(
        cc.License, license_name="WTF License")
示例#10
0
def preset_video():
    """
    Create a video format preset.
    """
    return mixer.blend(cc.FormatPreset, id='high_res_video', kind=video())
示例#11
0
def video():
    """
    Create a video content kind entry.
    """
    return mixer.blend(cc.ContentKind, kind='video')
def assessment_item3():
    answers = "[]"
    return mixer.blend(cc.AssessmentItem, question='Why a rice cooker?', type='free_response', answers=answers)
def assessment_item4():
    answers = "[{\"correct\": true, \"answer\": 20, \"help_text\": \"\"}]"
    return mixer.blend(cc.AssessmentItem, question='How many minutes does it take to cook rice?',
                       type='input_question', answers=answers)
示例#14
0
def topic():
    """
    Create a topic content kind.
    """
    return mixer.blend(cc.ContentKind, kind='topic')
def assessment_item():
    answers = "[{\"correct\": false, \"answer\": \"White Rice\", \"help_text\": \"\"}, " \
              "{\"correct\": true, \"answer\": \"Brown Rice\", \"help_text\": \"\"}, " \
              "{\"correct\": false, \"answer\": \"Rice Krispies\", \"help_text\": \"\"}]"
    return mixer.blend(cc.AssessmentItem, question='Which rice is the healthiest?',
                       type='single_selection', answers=answers)
示例#16
0
from contentcuration.tests.utils import mixer

mixer.register(User, information="{}", content_defaults="{}", policies="{}")

if __name__ == "__main__":
    warnings.warn("THIS WILL CLEAR YOUR DATABASE AND FILL IT WITH TEST DATA!")
    logging.info("Clearing the DB")
    call_command("flush", "--noinput")

    # set up our DB from scratch and create our user
    logging.info("Setting up the database")
    call_command("setup")

    # create NUM_CHANNELS channels using mixer

    logging.info("Creating {} channels".format(NUM_CHANNELS))

    for _ in range(NUM_CHANNELS):
        editor = mixer.blend(User)
        c = mixer.blend(Channel)
        c.editors.add(editor)
        viewers = mixer.cycle(2).blend(User)
        for v in viewers:
            v.view_only_channels.add(c)
            v.save()
        c.save()

    # start the server in prod mode
    subprocess.call(["yarn", "run", "devserver"])
示例#17
0
def exercise():
    """
    Create a exercise content kind.
    """
    return mixer.blend(cc.ContentKind, kind='exercise')
示例#18
0
def slideshow():
    """
    Returns a slideshow content kind object.
    """
    return mixer.blend(cc.ContentKind, kind='slideshow')