Beispiel #1
0
    def test_get_quiz_feedback_with_only_subjects_and_no_linked_resource(self):
        # fill database
        course = Course(pk=159,
                        name="Test_course1",
                        courseId=1,
                        version_time=datetime.datetime(2020, 1, 28))
        course.save()

        Quiz.objects.create(course_id=159,
                            name="Test_quiz1",
                            external_id=18,
                            subjects_id=1,
                            version_time=datetime.datetime(2020, 1, 28))
        resource = Resource(
            course_id=159,
            name="Book 1",
            target="http://localhost:4000/mod/book/view.php?id=12",
            type="book",
            external=False,
            external_id=12,
            version_time=datetime.datetime(2020, 1, 28))
        resource.save()

        subject = Subject(course=course, name="Test_subject1")
        subject.save()

        self.assertEqual(feedback_manager.get_quiz_feedback_link(18),
                         "the course resource")
Beispiel #2
0
    def test_get_quiz_feedback_with_only_subjects_and_linked_resource(self):
        # fill database
        course = Course(pk=159,
                        name="Test_course1",
                        courseId=1,
                        version_time=datetime.datetime(2020, 1, 28))
        course.save()

        quiz = Quiz.objects.create(course_id=159,
                                   name="Test_quiz1",
                                   external_id=18,
                                   subjects_id=1,
                                   version_time=datetime.datetime(2020, 1, 28))
        quiz.save()

        resource = Resource(
            course_id=159,
            name="Book 1",
            target="http://localhost:4000/mod/book/view.php?id=12",
            type="book",
            external=False,
            external_id=12,
            version_time=datetime.datetime(2020, 1, 28))
        resource.save()

        subject = Subject(course=course, name="Test_subject1")
        subject.save()

        # add the link between subjects and resources
        subject.resources.add(resource)
        message = '\r\n- <a href="http://localhost:4000/mod/book/view.php?id=12">Book 1</a>'
        self.assertEqual(feedback_manager.get_quiz_feedback_link(18), message)
    def test_fuzzy_matching_subject(self):
        subject_math3 = Subject()
        subject_math3.name = "math-algebra"
        subject_math3.save()

        subject_set = get_fuzzy_subject_matching(subject_math3)
        self.assertEqual(len(subject_set), 3)
    def test_json_subjects(self):
        """
        Test the /api/subjects/ endpoint
        """
        temp_subject = Subject(name='Pottery')
        temp_subject.save()

        response = self.client.get('/api/subjects/')
        self.assertEqual(response.status_code, 200)
        self.assertTrue('Pottery' in response.content)
    def setUp(self):
        # Create three fake users and two fake courses
        self.subject_math = Subject()
        self.subject_math.name = 'math'
        self.subject_math.save()

        self.subject_english = Subject()
        self.subject_english.name = 'english'
        self.subject_english.save()

        self.subject_math2 = Subject()
        self.subject_math2.name = 'math-calculus'
        self.subject_math2.save()

        self.course_math = Course()
        self.course_math.name = 'intro to math'
        self.course_math.description = 'this is a introduction to math'
        self.course_math.save()
        self.course_math.subjects.add(self.subject_math)
        self.course_math.save()

        self.course_english = Course()
        self.course_english.name = 'Literature 100'
        self.course_english.description = 'Learn how to read!'
        self.course_english.save()
        self.course_english.subjects.add(self.subject_english)
        self.course_english.save()

        self.user1 = User.objects.create(username='******')
        self.user_profile_1 = UserProfile.objects.create(user=self.user1)
        self.user_profile_1.save()
        self.user_profile_1.interests.add(self.subject_math2)
        self.user_profile_1.disliked.add(self.course_math)
        self.user_profile_1.disliked.add(self.course_english)
        self.user_profile_1.completed.add(self.course_math)
        self.user_profile_1.completed.add(self.course_english)
        self.user_profile_1.save()

        self.user_2 = User.objects.create(username='******')
        self.user_profile_2 = UserProfile.objects.create(user=self.user_2)
        self.user_profile_2.save()
        self.user_profile_2.interests.add(self.subject_math2)
        self.user_profile_2.disliked.add(self.course_english)
        self.user_profile_2.disliked.add(self.course_math)
        self.user_profile_2.save()

        self.user_3 = User.objects.create(username='******')
        self.user_profile_3 = UserProfile.objects.create(user=self.user_3)
        self.user_profile_3.save()
        self.user_profile_3.interests.add(self.subject_english)
        self.user_profile_3.disliked.add(self.course_math)
        self.user_profile_3.completed.add(self.course_math)
        self.user_profile_3.completed.add(self.course_english)
        self.user_profile_3.save()
    def test_json_like_subject(self):
        """
        Test the /api/like_subject/ endpoint for a logged in user
        """
        login_successful = self.client.login(username='******', password='******')
        self.assertTrue(login_successful)

        temp_subject = Subject(name='Pottery')
        temp_subject.save()
        response = self.client.post('/api/like_subject/', data={'liked_subject': temp_subject.id})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('{"success": true}', response.content)
        response = self.client.post('/api/like_subject/', data={'liked_subject': 1234567890})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('{"success": false}', response.content)
    def test_create_subject(self):
        """
        Creates a Subject model object and tests if it can be manipulated properly
        """
        subject = Subject()
        subject.name = 'CS'
        subject.save()

        all_subjects = Subject.objects.all()

        self.assertEquals(len(all_subjects), 1)
        only_subject = all_subjects[0]
        self.assertEquals(only_subject, subject)

        self.assertEquals(only_subject.name, 'CS')
    def setUp(self):
        """
        Set up a test user and user profile
        """
        self.client = Client()
        self.user = User.objects.create_user(username='******', email='*****@*****.**', password='******',
                                             first_name='', last_name='')
        self.user_profile = UserProfile.objects.create(user=self.user)

        # to avoid conflict with a test written before this setup
        # append '2' to provider and subject names
        self.test_provider = Provider(name='Test provider 2')
        self.test_provider.save()
        self.test_subject = Subject(name='Test subject 2')
        self.test_subject.save()

        self.test_course_1 = Course(name='Pottery 1', description="Test description 1", provider=self.test_provider,
                                    instructor="Test instructor 1", url='http://www.example.com/1')
        self.test_course_1.save()
        self.test_course_1.subjects.add(self.test_subject)
        self.test_course_1.save()

        self.test_course_2 = Course(name='Pottery 2', description="Test description 2", provider=self.test_provider,
                                    instructor="Test instructor 2", url='http://www.example.com/2')
        self.test_course_2.save()
        self.test_course_2.subjects.add(self.test_subject)
        self.test_course_2.save()

        self.test_course_3 = Course(name='Pottery 3', description="Test description 3", provider=self.test_provider,
                                    instructor="Test instructor 3", url='http://www.example.com/3')
        self.test_course_3.save()
        self.test_course_3.subjects.add(self.test_subject)
        self.test_course_3.save()
Beispiel #9
0
def create_subject():

    subjectSpecs = SubjectSpecification.objects.all()
    subjectSpec_list = [subjectSpec for subjectSpec in subjectSpecs]

    students = Student.objects.all()
    student_list = [student for student in students]

    subject = Subject(
        subject_spec=random.choice(subjectSpec_list),
        lective_year=datetime.datetime.now().date,
        semester=random.choice(["1", "2"]),
        duration=random.randrange(12, 16),
    )

    subject.save()
    subject.students.add(random.choice(student_list))
Beispiel #10
0
    def test_saving_and_retrieving_subjects(self):
        sub1 = Subject(title='First Subject', slug='first_subject')
        sub1.save()
        self.assertIsNotNone(sub1)
        saved_sub1 = Subject.objects.first()
        self.assertEqual(sub1, saved_sub1)

        sub2 = Subject(title='Second Subject', slug='second_subject')
        sub2.save()

        saved_subs = Subject.objects.all()
        self.assertEqual(saved_subs.count(), 2)

        self.assertEqual(sub1.title, 'First Subject')
        self.assertEqual(sub2.slug, 'second_subject')
Beispiel #11
0
    def test_retriving_subjects_ordered_by_title(self):

        sub2 = Subject(title='B A C', slug='b_a_c')
        sub2.save()

        sub1 = Subject(title='A B C', slug='a_b_c')
        sub1.save()

        saved_subs = Subject.objects.all()

        first_sub = saved_subs[0]
        second_sub = saved_subs[1]

        self.assertEqual(first_sub, sub1)
        self.assertEqual(second_sub, sub2)
    def test_course_info(self):
        """
        Test the /api/course_info/ endpoint for a logged in user
        """
        login_successful = self.client.login(username='******', password='******')
        self.assertTrue(login_successful)

        temp_provider = Provider(name='Test provider')
        temp_provider.save()
        temp_subject = Subject(name='Test subject')
        temp_subject.save()
        temp_course = Course(name='Pottery', description="Test description", provider=temp_provider,
                             instructor="Test instructor")
        temp_course.save()
        temp_course.subjects.add(temp_subject)
        temp_course.save()

        helpout_url = 'https://helpouts.google.com/search?q='

        for word in temp_course.name.split(' '):
            helpout_url += word + '%20OR%20'
        helpout_url = helpout_url[:-8]  # remove trailing %20OR%20

        course_info = {'description': 'Test description', 'provider': 'Test provider',
                       'instructor': 'Test instructor', 'name': 'Pottery', 'url': '',
                       'subjects': ['Test subject'], 'helpouturl': helpout_url,
                       'similar_courses_names': [], 'similar_courses_links': []}
        expected_content = {'success': True, 'info': course_info}

        response = self.client.post('/api/course_info/', data={'course_id': temp_course.id})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(json.dumps(expected_content), response.content)

        response = self.client.post('/api/complete_course/', data={'course_id': 1234567890})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('{"success": false}', response.content)
    def test_json_liked_subjects(self):
        """
        Test the /api/liked_subjects/ endpoint for a logged in user
        """
        temp_subject = Subject(name='Computer Science')
        temp_subject.save()

        temp_subject_two = Subject(name='Computer Engineering')
        temp_subject_two.save()

        self.user_profile.interests.add(temp_subject)
        self.user_profile.interests.add(temp_subject_two)
        self.user_profile.save()

        login_successful = self.client.login(username='******', password='******')
        self.assertTrue(login_successful)
        response = self.client.get('/api/liked_subjects/')
        self.assertEqual(response.status_code, 200)
        self.assertEqual('["Computer Science", "Computer Engineering"]', response.content)
Beispiel #14
0
    def test_auto_save_for_subject_slug(self):

        sub = Subject(title='this is a subject')
        sub.save()
        self.assertEqual(sub.slug, 'this-is-a-subject')
Beispiel #15
0
import django
import requests
import os
import json
import re
from courses.models import Subject, Course, CourseSection

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "eduya.settings")
django.setup()

# save all subjects
with open('subjects.txt') as f:
    subjects_json = json.load(f)
    for subject in subjects_json:
        s = Subject()
        s.name = subjects_json[subject]['SubjectName']
        s.abbreviation = subjects_json[subject]['SubjectAbbreviation']
        s.save()

# save all courses and courses
with open('classes.txt') as f:
    classes_json = json.load(f)
    for c in classes_json:
        course = classes_json[c]['Course']
        new_course = Course()
        new_course.subject = Subject.objects.filter(
            abbreviation=course['Subject']['SubjectAbbreviation'])[0]
        new_course.title = course['Title']
        new_course.number = course['CourseNumber']
        new_course.save()
class RecommenderTestsNormalCase(TestCase):
    def setUp(self):
        # Create three fake users and two fake courses
        self.subject_math = Subject()
        self.subject_math.name = 'math'
        self.subject_math.save()

        self.subject_english = Subject()
        self.subject_english.name = 'english'
        self.subject_english.save()

        self.subject_math2 = Subject()
        self.subject_math2.name = 'math-calculus'
        self.subject_math2.save()

        self.course_math = Course()
        self.course_math.name = 'intro to math'
        self.course_math.description = 'this is a introduction to math'
        self.course_math.save()
        self.course_math.subjects.add(self.subject_math)
        self.course_math.save()

        self.course_english = Course()
        self.course_english.name = 'Literature 100'
        self.course_english.description = 'Learn how to read!'
        self.course_english.save()
        self.course_english.subjects.add(self.subject_english)
        self.course_english.save()

        self.user1 = User.objects.create(username='******')
        self.user_profile_1 = UserProfile.objects.create(user=self.user1)
        self.user_profile_1.save()
        self.user_profile_1.interests.add(self.subject_math2)
        self.user_profile_1.disliked.add(self.course_math)
        self.user_profile_1.disliked.add(self.course_english)
        self.user_profile_1.completed.add(self.course_math)
        self.user_profile_1.completed.add(self.course_english)
        self.user_profile_1.save()

        self.user_2 = User.objects.create(username='******')
        self.user_profile_2 = UserProfile.objects.create(user=self.user_2)
        self.user_profile_2.save()
        self.user_profile_2.interests.add(self.subject_math2)
        self.user_profile_2.disliked.add(self.course_english)
        self.user_profile_2.disliked.add(self.course_math)
        self.user_profile_2.save()

        self.user_3 = User.objects.create(username='******')
        self.user_profile_3 = UserProfile.objects.create(user=self.user_3)
        self.user_profile_3.save()
        self.user_profile_3.interests.add(self.subject_english)
        self.user_profile_3.disliked.add(self.course_math)
        self.user_profile_3.completed.add(self.course_math)
        self.user_profile_3.completed.add(self.course_english)
        self.user_profile_3.save()

    def test_fuzzy_matching_subject(self):
        subject_math3 = Subject()
        subject_math3.name = "math-algebra"
        subject_math3.save()

        subject_set = get_fuzzy_subject_matching(subject_math3)
        self.assertEqual(len(subject_set), 3)

    def test_get_recs_from_subjects(self):
        test_subs = set()
        test_subs.add(Subject.objects.get(name="math-calculus"))
        subject_set = get_recs_from_subjects(test_subs)
        self.assertEqual(len(subject_set), 1)
        self.assertEqual(subject_set.pop().name, "intro to math")

    def test_get_enrolled_subjects(self):
        self.assertEqual(len(get_enrolled_subjects(self.user1)), 2)

    def test_get_similar_user_interests(self):
        similar_user, numb = get_similar_user_interests(self.user1)
        self.assertEqual(similar_user, self.user_profile_2)
        self.assertEqual(numb, 1)

    def test_get_similar_user_dislikes(self):
        similar_user, numb = get_similar_user_dislikes(self.user1)
        self.assertEqual(similar_user, self.user_profile_2)
        self.assertEqual(numb, 2)

    def test_get_similar_user_completed(self):
        similar_user, numb = get_similar_user_completed(self.user1)
        print similar_user.user.username
        self.assertEqual(similar_user, self.user_profile_3)
        self.assertEqual(numb, 2)
class TestAPI(TestCase):
    def setUp(self):
        """
        Set up a test user and user profile
        """
        self.client = Client()
        self.user = User.objects.create_user(username='******', email='*****@*****.**', password='******',
                                             first_name='', last_name='')
        self.user_profile = UserProfile.objects.create(user=self.user)

        # to avoid conflict with a test written before this setup
        # append '2' to provider and subject names
        self.test_provider = Provider(name='Test provider 2')
        self.test_provider.save()
        self.test_subject = Subject(name='Test subject 2')
        self.test_subject.save()

        self.test_course_1 = Course(name='Pottery 1', description="Test description 1", provider=self.test_provider,
                                    instructor="Test instructor 1", url='http://www.example.com/1')
        self.test_course_1.save()
        self.test_course_1.subjects.add(self.test_subject)
        self.test_course_1.save()

        self.test_course_2 = Course(name='Pottery 2', description="Test description 2", provider=self.test_provider,
                                    instructor="Test instructor 2", url='http://www.example.com/2')
        self.test_course_2.save()
        self.test_course_2.subjects.add(self.test_subject)
        self.test_course_2.save()

        self.test_course_3 = Course(name='Pottery 3', description="Test description 3", provider=self.test_provider,
                                    instructor="Test instructor 3", url='http://www.example.com/3')
        self.test_course_3.save()
        self.test_course_3.subjects.add(self.test_subject)
        self.test_course_3.save()

    def test_json_subjects(self):
        """
        Test the /api/subjects/ endpoint
        """
        temp_subject = Subject(name='Pottery')
        temp_subject.save()

        response = self.client.get('/api/subjects/')
        self.assertEqual(response.status_code, 200)
        self.assertTrue('Pottery' in response.content)

    def test_json_courses(self):
        """
        Test the /api/courses/ endpoint
        """
        temp_course = Course(name='Advanced Pottery III')
        temp_course.save()

        response = self.client.get('/api/courses/')
        self.assertEqual(response.status_code, 200)
        self.assertTrue('Advanced Pottery III' in response.content)

    def test_json_enrolled_courses(self):
        """
        Test the /api/enrolled_courses/ endpoint for a logged in user
        """
        temp_course = Course(name='Advanced Pottery III', description='Learn pottery like you never imagined possible.',
                             instructor='Bob Smith')
        temp_course.save()

        self.user_profile.enrolled.add(temp_course)
        self.user_profile.save()

        login_successful = self.client.login(username='******', password='******')
        self.assertTrue(login_successful)

        response = self.client.get('/api/enrolled_courses/')
        self.assertEqual(response.status_code, 200)
        self.assertEqual('["Advanced Pottery III"]', response.content)

    def test_json_liked_subjects(self):
        """
        Test the /api/liked_subjects/ endpoint for a logged in user
        """
        temp_subject = Subject(name='Computer Science')
        temp_subject.save()

        temp_subject_two = Subject(name='Computer Engineering')
        temp_subject_two.save()

        self.user_profile.interests.add(temp_subject)
        self.user_profile.interests.add(temp_subject_two)
        self.user_profile.save()

        login_successful = self.client.login(username='******', password='******')
        self.assertTrue(login_successful)
        response = self.client.get('/api/liked_subjects/')
        self.assertEqual(response.status_code, 200)
        self.assertEqual('["Computer Science", "Computer Engineering"]', response.content)

    def test_json_like_subject(self):
        """
        Test the /api/like_subject/ endpoint for a logged in user
        """
        login_successful = self.client.login(username='******', password='******')
        self.assertTrue(login_successful)

        temp_subject = Subject(name='Pottery')
        temp_subject.save()
        response = self.client.post('/api/like_subject/', data={'liked_subject': temp_subject.id})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('{"success": true}', response.content)
        response = self.client.post('/api/like_subject/', data={'liked_subject': 1234567890})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('{"success": false}', response.content)

    def test_json_dislike_course(self):
        """
        Test the /api/dislike_course/ endpoint for a logged in user
        """
        login_successful = self.client.login(username='******', password='******')
        self.assertTrue(login_successful)

        temp_course = Course(name='Pottery')
        temp_course.save()
        response = self.client.post('/api/dislike_course/', data={'disliked_course': temp_course.id})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('{"success": true}', response.content)
        response = self.client.post('/api/dislike_course/', data={'disliked_course': 1234567890})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('{"success": false}', response.content)

    def test_json_complete_course(self):
        """
        Test the /api/complete_course/ endpoint for a logged in user
        """
        login_successful = self.client.login(username='******', password='******')
        self.assertTrue(login_successful)

        temp_course = Course(name='Pottery')
        temp_course.save()
        response = self.client.post('/api/complete_course/', data={'completed_course': temp_course.id})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('{"success": true}', response.content)
        response = self.client.post('/api/complete_course/', data={'completed_course': 1234567890})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('{"success": false}', response.content)

    def create_fake_userprofile(self):
        """
        Helper function to create a fake user profile for tests
        """
        email = "*****@*****.**"
        password = "******"
        user = User.objects.create_user(username_md5(email), email, password, first_name="", last_name="")
        user.save()
        user_profile = UserProfile(user=user)

        course_name = "Test course"
        description = "Test description"
        c, created = Course.objects.get_or_create(name=course_name, description=description, instructor='instructor')

        user_profile.save()
        user_profile.enrolled.add(c)
        user_profile.save()
        return user_profile

    def test_add_remove_course(self):
        """
        Test the /api/remove_course/ endpoint for a logged in user
        """
        user_profile = self.create_fake_userprofile()
        self.client.login(username='******', password='******')

        test_course = Course.objects.get(name="Test course")

        request = HttpRequest()
        request.POST['course_to_add'] = test_course.id
        request.user = user_profile.user
        request.method = 'POST'

        add_course(request)

        all_courses = list(user_profile.enrolled.all())
        self.assertEquals(len(all_courses), 1)

        the_course = all_courses[0]
        self.assertEquals(the_course.name, test_course.name)
        self.assertEquals(the_course.description, test_course.description)

        request.POST['course_to_drop'] = the_course.id
        drop_course(request)

        all_courses = list(user_profile.enrolled.all())
        self.assertEqual(len(all_courses), 0)

    def test_course_info(self):
        """
        Test the /api/course_info/ endpoint for a logged in user
        """
        login_successful = self.client.login(username='******', password='******')
        self.assertTrue(login_successful)

        temp_provider = Provider(name='Test provider')
        temp_provider.save()
        temp_subject = Subject(name='Test subject')
        temp_subject.save()
        temp_course = Course(name='Pottery', description="Test description", provider=temp_provider,
                             instructor="Test instructor")
        temp_course.save()
        temp_course.subjects.add(temp_subject)
        temp_course.save()

        helpout_url = 'https://helpouts.google.com/search?q='

        for word in temp_course.name.split(' '):
            helpout_url += word + '%20OR%20'
        helpout_url = helpout_url[:-8]  # remove trailing %20OR%20

        course_info = {'description': 'Test description', 'provider': 'Test provider',
                       'instructor': 'Test instructor', 'name': 'Pottery', 'url': '',
                       'subjects': ['Test subject'], 'helpouturl': helpout_url,
                       'similar_courses_names': [], 'similar_courses_links': []}
        expected_content = {'success': True, 'info': course_info}

        response = self.client.post('/api/course_info/', data={'course_id': temp_course.id})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(json.dumps(expected_content), response.content)

        response = self.client.post('/api/complete_course/', data={'course_id': 1234567890})
        self.assertEqual(response.status_code, 200)
        self.assertEqual('{"success": false}', response.content)

    def test_similar_courses(self):
        """
        Test the /api/similar_courses/ endpoint for a logged in user
        """
        similar_courses = get_similar_courses(self.test_course_1)
        self.assertEqual(len(similar_courses), 2)
        self.assertIn(self.test_course_2, similar_courses)
        self.assertIn(self.test_course_3, similar_courses)
Beispiel #18
0
          datetime=datetime.datetime.now(),
          price=10.00,
          notes="My phone number is 1-888-812-1245")
p3 = Post(student=s2,
          subject="CS",
          course="CS354",
          location="Hicks Library",
          datetime=datetime.datetime.now(),
          price=8.50,
          notes="1 hr session")
p1.save()
p2.save()
p3.save()

# Create 3 Test Subjects
ts1 = Subject(name='CHM')
ts2 = Subject(name='EAPS')
ts3 = Subject(name='CS')
ts1.save()
ts2.save()
ts3.save()

# Create Test Courses
c1 = Course(subject=ts3,
            title='Introduction To The Analysis Of Algorithms',
            course_id='CS38100')
c2 = Course(subject=ts3,
            title='Data Structures and Algorithms',
            course_id='CS25100')
c3 = Course(subject=ts3, title='Computer Architecture', course_id='CS25000')
c4 = Course(subject=ts1, title='Intro Inorganic Chem', course_id='CHM24100')