예제 #1
0
def before_scenario(context, scenario):
    base_before_scenario(context, scenario)

    if "with_progress" in context.tags:
        user = FacilityUser.objects.get(username=context.user, facility=getattr(context, "facility", None))
        exercises = get_random_content(kinds=["Exercise"], limit=2)
        for exercise in exercises:
            log = ExerciseLog(
                exercise_id=exercise.get("id"),
                user=user,
                streak_progress=50,
                attempts=15,
                latest_activity_timestamp=datetime.datetime.now()
                )
            log.save()
        context.exercises = exercises

        videos = get_random_content(kinds=["Video"], limit=2)

        for video in videos:
            log = VideoLog(
                youtube_id=video.get("id"),
                video_id=video.get("id"),
                user=user,
                total_seconds_watched=100,
                points=600,
                latest_activity_timestamp=datetime.datetime.now()
                )
            log.save()
        context.videos = videos
예제 #2
0
def create_some_learner_data():
    """
    Just create a lil' bit-o-data of each type, to populate the table.
    """
    user = CreateStudentMixin.create_student()
    attempt_states = (  # (name, streak_progress, attempt_count)
        ("not started", 0, 0),
        ("completed", 100, 15),
        ("attempted", 50, 10),
        ("struggling", 30, 25),
    )
    exercises = get_random_content(kinds=["Exercise"], limit=len(attempt_states))  # Important they are *distinct*
    for state in attempt_states:
        exercise = exercises.pop()
        log, created = ExerciseLog.objects.get_or_create(exercise_id=exercise.get("id"), user=user)
        if "not started" != state[0]:
            log.streak_progress, log.attempts = state[1:]
            for i in range(0, log.attempts):
                AttemptLog.objects.get_or_create(
                    exercise_id=exercise.get("id"),
                    user=user,
                    seed=i,
                    timestamp=datetime.datetime.now()
                )
            log.latest_activity_timestamp = datetime.datetime.now()
            log.save()
예제 #3
0
 def test_update_item(self):
     item = get_random_content()[0]
     available = item.get("available")
     inverse_available = not available
     update_item({"available": inverse_available}, item.get("path"))
     item2 = get_content_item(content_id=item.get("id"))
     self.assertEqual(item2.get("available"), inverse_available)
예제 #4
0
def setup_content_paths(context, db):
    """
    Creaters available content items and adds their urls to the context object.

    :param context: A behave context, to which the attributes "available_content_path" and "unavailable_content_path"
        will be added.
    :return: None
    """

    # These paths are "magic" -- the success or failure of actually visiting the content items in the browser
    # depends on these specific values.
    context.unavailable_content_path = "khan/foo/bar/unavail"
    context.available_content_path = get_random_content(kinds=["Exercise"], available=True)[0]['path']

    # This function uses 'iterator_content_items' function to return a list of path, update dict pairs
    # It then updates the items with these paths with their update dicts, and then propagates
    # availability changes up the topic tree - this means that we can alter the availability of one item
    # and make all its parent topics available so that it is navigable to in integration tests.
    def iterator_content_items(ids=None, channel="khan", language="en"):
        return [(context.available_content_path, {"available": True})]

    annotate_content_models(db=db, iterator_content_items=iterator_content_items)

    with Using(db, [Item], with_transaction=False):
        context._unavailable_item = Item.create(
            title="Unavailable item",
            description="baz",
            available=False,
            kind="Video",
            id="3",
            slug="unavail",
            path=context.unavailable_content_path
        )
예제 #5
0
def impl(context):
    exercises = get_random_content(kinds=["Exercise"], limit=10)
    for user in FacilityUser.objects.all():
        for exercise in exercises:
            log, created = ExerciseLog.objects.get_or_create(
                exercise_id=exercise.get("id"),
                user=user,
                streak_progress=100,
                attempts=15,
                latest_activity_timestamp=datetime.datetime.now()
                )
예제 #6
0
 def create_random_content_file(self):
     """
     Helper function for testing content files.
     """
     content = get_random_content(kinds=["Video"], limit=1)[0]
     youtube_id = content["id"]
     path = content["path"]
     fake_content_file = os.path.join(settings.CONTENT_ROOT, "%s.mp4" % youtube_id)
     with open(fake_content_file, "w") as fh:
         fh.write("")
     update_item(update={"files_complete": 1, "available": True, "size_on_disk": 12}, path=content["path"])
     self.assertTrue(os.path.exists(fake_content_file), "Make sure the content file was created, youtube_id='%s'." % youtube_id)
     return (fake_content_file, content["id"], youtube_id, path)
예제 #7
0
 def create_random_content_file(self):
     """
     Helper function for testing content files.
     """
     content = get_random_content(kinds=["Video"], limit=1)[0]
     youtube_id = content["id"]
     path = content["path"]
     fake_content_file = os.path.join(settings.CONTENT_ROOT,
                                      "%s.mp4" % youtube_id)
     with open(fake_content_file, "w") as fh:
         fh.write("")
     update_item(update={
         "files_complete": 1,
         "available": True,
         "size_on_disk": 12
     },
                 path=content["path"])
     self.assertTrue(
         os.path.exists(fake_content_file),
         "Make sure the content file was created, youtube_id='%s'." %
         youtube_id)
     return (fake_content_file, content["id"], youtube_id, path)
예제 #8
0
 def browse_to_random_video(self):
     video = get_random_content(limit=1)[0]
     video_url = video['path']
     self.browse_to(self.reverse("learn") + video_url)
예제 #9
0
 def browse_to_random_video(self):
     video = get_random_content(limit=1)[0]
     video_url = video['path']
     self.browse_to(self.reverse("learn") + video_url)