Exemplo n.º 1
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
 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))
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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
Exemplo n.º 6
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 StringIO file-like object that you can read/write
    - db_file (cc.File): a Studio File object saved in DB
    """
    fileobj = StringIO(filebytes)
    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
    default_storage.save(storage_file_path, fileobj)
    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
    }
Exemplo n.º 7
0
def assessment_item3():
    answers = "[]"
    return mixer.blend(cc.AssessmentItem,
                       question='Why a rice cooker?',
                       type='free_response',
                       answers=answers)
Exemplo n.º 8
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")
Exemplo n.º 9
0
def fileformat_mp4():
    """
    Create an mp4 FileFormat entry.
    """
    return mixer.blend(cc.FileFormat, extension='mp4', mimetype='application/video')
Exemplo n.º 10
0
def fileformat_perseus():
    """
    Create a perseus FileFormat entry.
    """
    return mixer.blend(cc.FileFormat, extension='perseus', mimetype='application/exercise')
Exemplo n.º 11
0
 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])
Exemplo n.º 12
0
def exercise():
    """
    Create a exercise content kind.
    """
    return mixer.blend(cc.ContentKind, kind='exercise')
Exemplo n.º 13
0
def topic():
    """
    Create a topic content kind.
    """
    return mixer.blend(cc.ContentKind, kind='topic')
Exemplo n.º 14
0
def preset_video():
    """
    Create a video format preset.
    """
    return mixer.blend(cc.FormatPreset, id='high_res_video', kind=video())
Exemplo n.º 15
0
def video():
    """
    Create a video content kind entry.
    """
    return mixer.blend(cc.ContentKind, kind='video')
Exemplo n.º 16
0
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)
Exemplo n.º 17
0
def slideshow():
    """
    Returns a slideshow content kind object.
    """
    return mixer.blend(cc.ContentKind, kind='slideshow')
Exemplo n.º 18
0
from contentcuration.tests.testutils 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"])