Пример #1
0
    def test_grad_letters(self):
        """
        Check handling of letters for grad students
        """
        client = Client()
        test_auth(client, 'ggbaker')
        gs = GradStudent.objects.get(person__userid=self.gs_userid)

        # get template text and make sure substitutions are made
        lt = LetterTemplate.objects.get(label="Funding")
        url = reverse('grad.views.get_letter_text', kwargs={'grad_slug': gs.slug, 'letter_template_id': lt.id})
        response = client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'M Grad is making satisfactory progress')
        content = unicode(response.content)
        
        # create a letter with that content
        l = Letter(student=gs, date=datetime.date.today(), to_lines="The Student\nSFU", template=lt, created_by='ggbaker', content=content)
        l.save()
        url = reverse('grad.views.view_letter', kwargs={'grad_slug': gs.slug, 'letter_slug': l.slug})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('grad.views.copy_letter', kwargs={'grad_slug': gs.slug, 'letter_slug': l.slug})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
Пример #2
0
    def test_pages(self):
        "Test a bunch of page views"
        offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
        activity = Activity.objects.get(offering=offering, slug='rep')
        activity.due_date = datetime.datetime.now() + datetime.timedelta(days=1) # make sure it's submittable
        activity.save()
        client = Client()

        # instructor views
        client.login_user("ggbaker")

        component1 = URL.Component(activity=activity, title='Sample URL 1', description='Please submit some URL.',
                                   check=False, prefix='')
        component1.save()
        component2 = URL.Component(activity=activity, title='Sample URL 2', description='Please submit some URL.',
                                   check=False, prefix='')
        component2.save()

        test_views(self, client, 'submission.views.', ['show_components', 'add_component'],
                   {'course_slug': offering.slug, 'activity_slug': activity.slug})

        url = reverse('submission.views.edit_single', kwargs={'course_slug': offering.slug, 'activity_slug': activity.slug}) \
                + '?id=' + unicode(component1.id)
        basic_page_tests(self, client, url)

        url = reverse('submission.views.add_component', kwargs={'course_slug': offering.slug, 'activity_slug': activity.slug}) \
                + '?type=url'
        basic_page_tests(self, client, url)

        # student views: with none, some, and all submitted
        client.login_user("0aaa0")

        # test various permutations of success to make sure everything returns okay
        name1 = '%i-url' % (component1.id)
        name2 = '%i-url' % (component2.id)
        submissions = [
            ({}, False),
            ({name1: '', name2: ''}, False),
            ({name1: '', name2: 'do i look like a url to you?'}, False),
            ({name1: 'http://www.sfu.ca/', name2: ''}, False),
            ({name1: 'http://www.cs.sfu.ca/', name2: 'http://example.com/'}, True),
            ({name1: 'http://www.sfu.ca/', name2: 'http://example.com/'}, True),
        ]
        for submitdata, redir in submissions:
            test_views(self, client, 'submission.views.', ['show_components', 'show_components_submission_history'],
                       {'course_slug': offering.slug, 'activity_slug': activity.slug})
            url = reverse('submission.views.show_components', kwargs={'course_slug': offering.slug, 'activity_slug': activity.slug})
            response = client.post(url, submitdata)
            if redir:
                # success: we expect a redirect
                self.assertEqual(response.status_code, 302)
            else:
                # some problems: expect a page reporting that
                self.assertEqual(response.status_code, 200)
                validate_content(self, response.content, url)
Пример #3
0
    def test_add_common_problems(self):
        c = CourseOffering.objects.get(slug = self.c_slug)
        a = NumericActivity(offering = c, name = 'test_assignment_1', \
                            short_name = 'ta1', status = 'RLS', \
                            due_date = datetime.now(), max_grade = 100, position = 1)
        a.save()        
        co1 = ActivityComponent(numeric_activity = a, title = 'part1', max_mark = 50, position = 1)
        co2 = ActivityComponent(numeric_activity = a, title = 'part2', max_mark = 50, position = 2) 
        co1.save()
        co2.save()
        
        #add some common problems
        cp1 = CommonProblem(activity_component = co1, title = 'cp1', penalty="0")
        cp2 = CommonProblem(activity_component = co1, title = 'cp2', penalty="1.12")        
        cp3 = CommonProblem(activity_component = co2, title = 'cp3', penalty="-2.3")
        
        cp1.save()
        cp2.save()
        cp3.save()
        
        self.client.login_user('ggbaker')        

        response = basic_page_tests(self, self.client, reverse('offering:marking:manage_common_problems', args=(self.c_slug,a.slug)))
        
        forms = response.context['formset'].forms
 
        ins0 = forms[0].instance
        ins1 = forms[1].instance
        ins2 = forms[2].instance
        
        self.assertEqual(ins0.title, 'cp1')
        self.assertEqual(ins0.activity_component, co1)
        self.assertEqual(ins1.title, 'cp2')
        self.assertEqual(ins1.activity_component, co1)
        self.assertEqual(ins2.title, 'cp3')
        self.assertEqual(ins2.activity_component, co2)
        
        #test the marking page as well        
        url = reverse('offering:marking:marking_student', args=(self.c_slug, a.slug, '0aaa0'))
        response = basic_page_tests(self, self.client, url)
        
        mark_components = response.context['component_data']
        com1 = mark_components[0]
        com2 = mark_components[1]
        
        self.assertEqual(com1['component'], co1)
        self.assertEqual(len(com1['common_problems']), 2)
        self.assertEqual(com2['component'], co2)
        self.assertEqual(len(com2['common_problems']), 1)
Пример #4
0
    def test_invalid_nonsfu_missing_elements(self):
        old_form_submission_count = len(FormSubmission.objects.all())
        old_sheet_submission_count = len(SheetSubmission.objects.all())

        url = reverse('onlineforms.views.sheet_submission_initial', kwargs={'form_slug': "comp-simple-form"})
        response = basic_page_tests(self, self.client, url)
        # test with each field missing
        person_nofirst = {'first_name': "", 'last_name': "Turing", 'email_address': "*****@*****.**"}
        person_nolast = {'first_name': "Alan", 'last_name': "", 'email_address': "*****@*****.**"}
        person_noemail = {'first_name': "Alan", 'last_name': "Turing", 'email_address': ""}
        people = [person_nofirst, person_nolast, person_noemail]
        fill_data = {"favorite-color": "Black", "reason": "Because it's metal", "second-favorite-color": "Green"}

        for person in people:
            # submit with empty user info
            post_data = {
                'first_name': person['first_name'],
                'last_name': person['last_name'],
                'email_address': person['email_address'],
                'add-nonsfu': True,
                '0': fill_data["favorite-color"],
                '1': fill_data["reason"],
                '2': fill_data["second-favorite-color"],
                'submit': "Yes",
            }

            response = self.client.post(url, post_data, follow=True)
            self.assertEqual(response.status_code, 200)
            # make sure no success
            self.assertNotContains(response, '<li class="success">')
            # make sure there was an error
            self.assertContains(response, '<li class="error">')
            # make sure nothing got added to the database
            self.assertEqual(old_form_submission_count, len(FormSubmission.objects.all()))
            self.assertEqual(old_sheet_submission_count, len(SheetSubmission.objects.all()))
Пример #5
0
    def test_add_activity_components(self):
        
        c = CourseOffering.objects.get(slug = self.c_slug)
       
        #add a numeric activity and its components
        a = NumericActivity(offering = c, name = 'test_assignment_1', \
                            short_name = 'ta1', status = 'RLS', \
                            due_date = datetime.now(), max_grade = 100, position = 0)
        a.save()
      
        co1 = ActivityComponent(numeric_activity = a, title = 'part1', max_mark = 20, position = 1)
        co2 = ActivityComponent(numeric_activity = a, title = 'part2', max_mark = 30, position = 2)
        co3 = ActivityComponent(numeric_activity = a, title = 'part3', max_mark = 50, position = 3)
        
        co1.save()
        co2.save()
        co3.save()
        
        self.client.login_user('ggbaker')

        response = basic_page_tests(self, self.client, reverse('offering:marking:manage_activity_components', args=(self.c_slug,a.slug)))
          
        forms = response.context['formset'].forms
        self.assertEqual(forms[0].instance.title, 'part1')
        self.assertEqual(forms[1].instance.title, 'part2')
        self.assertEqual(forms[2].instance.title, 'part3') 
Пример #6
0
 def run_basic_page_tests(self, views, arguments):
     for view in views:
         try:
             url = reverse('onlineforms.views.' + view, kwargs=arguments)
             response = basic_page_tests(self, self.client, url)
             self.assertEqual(response.status_code, 200)
         except:
             print "with view==" + repr(view)
             raise
Пример #7
0
    def test_course_browser(self):
        client = Client()

        s, c = create_offering()
        
        # the main search/filter page
        url = reverse('coredata.views.browse_courses')
        response = basic_page_tests(self, client, url)

        # AJAX request for table data
        url += '?tabledata=yes&data_type=json&iDisplayLength=25'
        response = client.get(url)
        data = json.loads(response.content)
        self.assertEquals(len(data['aaData']), 25)

        # courseoffering detail page
        url = reverse('coredata.views.browse_courses_info', kwargs={'course_slug': TEST_COURSE_SLUG})
        response = basic_page_tests(self, client, url)
Пример #8
0
    def test_course_browser(self):
        client = Client()

        s, c = create_offering()
        
        # the main search/filter page
        url = reverse('browse:browse_courses')
        response = basic_page_tests(self, client, url)

        # AJAX request for table data
        url += '?tabledata=yes&data_type=json&iDisplayStart=0&iDisplayLength=10&iSortingCols=0'
        response = client.get(url)
        data = json.loads(response.content.decode('utf8'))
        self.assertEqual(len(data['aaData']), 10)

        # courseoffering detail page
        url = reverse('browse:browse_courses_info', kwargs={'course_slug': TEST_COURSE_SLUG})
        response = basic_page_tests(self, client, url)
Пример #9
0
    def test_course_credits_inst_200_ok(self):
        raise SkipTest()
        client = Client()
        client.login_user("ggbaker")

        url = reverse('planning.views.view_teaching_credits_inst')
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('planning.views.view_teaching_equivalent_inst', kwargs={'equivalent_id': 1})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('planning.views.new_teaching_equivalent_inst')
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('planning.views.edit_teaching_equivalent_inst', kwargs={'equivalent_id': 1})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
Пример #10
0
    def test_valid_simple_initial_form_submission_anonymous(self):
        person = {'first_name': "Alan", 'last_name': "Turing", 'email_address': "*****@*****.**"}
        old_form_submission_count = len(FormSubmission.objects.all())
        old_sheet_submission_count = len(SheetSubmission.objects.all())

        url = reverse('onlineforms.views.sheet_submission_initial', kwargs={'form_slug': "comp-simple-form"})
        response = basic_page_tests(self, self.client, url)
        self.assertEqual(response.status_code, 200)
        # check that the non sfu form is up
        self.assertContains(response, '<input type="hidden" name="add-nonsfu" value="True"/>')
        # check for some important fields
        # note: the keys are the slugs of the field
        fill_data = {"favorite-color": "Black", "reason": "Because it's metal", "second-favorite-color": "Green"}
        # submit the form
        post_data = {
            'first_name': person["first_name"],
            'last_name': person["last_name"],
            'email_address': person["email_address"],
            'add-nonsfu': True,
            '0': fill_data["favorite-color"],
            '1': fill_data["reason"],
            '2': fill_data["second-favorite-color"],
            'submit': "Okay go",
        }
        response = self.client.post(url, post_data, follow=True)
        self.assertEqual(response.status_code, 200)
        # check that a success messaging is being displayed
        self.assertContains(response, '<li class="success">')
        # check that one form submission and one sheet submission got created
        self.assertEqual(old_form_submission_count + 1, len(FormSubmission.objects.all()))
        self.assertEqual(old_sheet_submission_count + 1, len(SheetSubmission.objects.all()))
        # find the submission in the database
        form_submission = FormSubmission.objects.latest('id')
        self.assertTrue(form_submission)
        sheet_submission = SheetSubmission.objects.latest('id')
        self.assertTrue(sheet_submission)
        self.assertEqual(sheet_submission.form_submission, form_submission)
        # make sure the person we logged in as got form initiator credits
        self.assertFalse(form_submission.initiator.isSFUPerson())
        self.assertEqual(form_submission.initiator.name(), "%s %s" % (person["first_name"], person["last_name"]))
        self.assertEqual(form_submission.initiator.email(), person["email_address"])
        # do the same for the sheet submission
        self.assertFalse(sheet_submission.filler.isSFUPerson())
        self.assertEqual(form_submission.initiator.name(), "%s %s" % (person["first_name"], person["last_name"]))
        self.assertEqual(form_submission.initiator.email(), person["email_address"])
        # verify the data
        field_submissions = FieldSubmission.objects.filter(sheet_submission=sheet_submission).order_by('field__order')
        self.assertEqual(len(fill_data), len(field_submissions))
        for field_submission in field_submissions:
            self.assertEqual(fill_data[field_submission.field.slug], field_submission.data['info'])
        # check the sheet submission and form submission status
        self.assertEqual(sheet_submission.status, "DONE")
        # form submissions is pending until someone manually marks it done
        self.assertEqual(form_submission.status, "PEND")
Пример #11
0
    def test_workflow(self):
        """
        Test the privacy policy workflow and page exclusions
        """
        # clear privacy agreement from test data
        p = Person.objects.get(userid='dzhao')
        p.config = {}
        p.save()

        client = Client()
        client.login_user(p.userid)
        privacy_url = reverse('privacy.views.privacy')

        # non-role page should still render
        url = reverse('dashboard.views.index')
        basic_page_tests(self, client, url)

        # but role page should redirect to agreement
        url = reverse('advisornotes.views.advising')
        response = client.get(url)
        self.assertRedirects(response, privacy_url + '?next=' + url)

        # check privacy page
        basic_page_tests(self, client, privacy_url)

        # submit and expect recorded agreement
        response = client.post(privacy_url + '?next=' + url, {'agree': 'on'})
        self.assertRedirects(response, url)
        p = Person.objects.get(userid='dzhao')
        self.assertTrue(p.config['privacy_signed'])

        # now we should be able to access
        basic_page_tests(self, client, url)
Пример #12
0
    def test_course_credits_admin_200_ok(self):
        raise SkipTest()
        client = Client()
        client.login_user("teachadm")

        url = reverse('planning.views.view_insts_in_unit')
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('planning.views.view_teaching_credits_admin', kwargs={'userid': 'ggbaker'})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('planning.views.view_teaching_equivalent_admin', kwargs={'userid': 'ggbaker', 'equivalent_id': 1})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('planning.views.new_teaching_equivalent_admin', kwargs={'userid': 'ggbaker'})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('planning.views.edit_teaching_equivalent_admin', kwargs={'userid': 'ggbaker', 'equivalent_id': 1})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('planning.views.edit_course_offering_credits', kwargs={'userid': 'ggbaker', 'course_slug': TEST_COURSE_SLUG})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
Пример #13
0
    def test_group_submission_view(self):
        """
        test if group submission can be viewed by group member and non group member
        """
        now = datetime.datetime.now()
        _, course = create_offering()
        a1 = NumericActivity(name="Assignment 1", short_name="A1", status="RLS", offering=course, position=2, max_grade=15, due_date=now, group=True)
        a1.save()
        a2 = NumericActivity(name="Assignment 2", short_name="A2", status="RLS", offering=course, position=1, max_grade=15, due_date=now, group=True)
        a2.save()
        p = Person.objects.get(userid="ggbaker")
        member = Member(person=p, offering=course, role="INST", career="NONS", added_reason="UNK")
        member.save()
        c1 = URL.Component(activity=a1, title="URL Link", position=8)
        c1.save()
        c2 = Archive.Component(activity=a1, title="Archive File", position=1, max_size=100000)
        c2.save()
        c3 = Code.Component(activity=a1, title="Code File", position=3, max_size=2000, allowed=".py")
        c3.save()

        userid1 = "0aaa0"
        userid2 = "0aaa1"
        userid3 = "0aaa2"
        for u in [userid1, userid2,userid3]:
            p = Person.objects.get(userid=u)
            m = Member(person=p, offering=course, role="STUD", credits=3, career="UGRD", added_reason="UNK")
            m.save()
        m = Member.objects.get(person__userid=userid1, offering=course)
        g = Group(name="Test Group", manager=m, courseoffering=course)
        g.save()
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a1)
        gm.save()
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a2)
        gm.save()
        m = Member.objects.get(person__userid=userid2, offering=course)
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a1)
        gm.save()
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a2)
        gm.save()
        m = Member.objects.get(person__userid=userid3, offering=course)
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a2)
        gm.save()

        client = Client()
        # login as "0aaa0", member of group : test_group for assignment1 and assgnment2
        client.login_user("0aaa0")

        #submission page for assignment 1
        url = reverse('submission.views.show_components', kwargs={'course_slug': course.slug,'activity_slug':a1.slug})
        response = basic_page_tests(self, client, url)
        self.assertContains(response, "This is a group submission. You will submit on behalf of the group Test Group.")
        self.assertContains(response, "You haven't made a submission for this component.")
Пример #14
0
    def test_advanced_search_2(self):
        client = Client()
        test_auth(client, 'ggbaker')
        units = [r.unit for r in Role.objects.filter(person__userid='ggbaker', role='GRAD')]

        # basic search with the frontend
        url = reverse('grad.views.search', kwargs={})
        qs = 'student_status=PART&student_status=ACTI&columns=person.emplid&columns=person.userid&columns=program'
        response = basic_page_tests(self, client, url + '?' + qs)
        self.assertIn('grad/search_results.html', [t.name for t in response.templates])
        search_res_1 = response.context['grads']

        # test the searching API
        form = SearchForm(QueryDict(qs))
        search_res_2 = form.search_results(units)
        self.assertEqual(set(search_res_1), set(search_res_2))

        form = SearchForm(QueryDict('student_status=ACTI&columns=person.emplid'))
        all_grads = form.search_results(units)
        gs = all_grads[0]

        # test student status search (which is a simple in-database query)
        gs.status = 'ACTI'
        gs.save()
        form = SearchForm(QueryDict('student_status=ACTI&columns=person.emplid'))
        status_search = form.search_results(units)
        self.assertIn(gs, status_search)
        form = SearchForm(QueryDict('student_status=LEAV&columns=person.emplid'))
        status_search = form.search_results(units)
        self.assertNotIn(gs, status_search)

        # test semester search (which a more difficult in-database query)
        sem = gs.start_semester
        form = SearchForm(QueryDict('start_semester_start=%s&columns=person.emplid' % (sem.name)))
        semester_search = form.search_results(units)
        self.assertIn(gs, semester_search)
        form = SearchForm(QueryDict('start_semester_start=%s&columns=person.emplid' % (sem.next_semester().name)))
        semester_search = form.search_results(units)
        self.assertNotIn(gs, semester_search)

        # test GPA searching (which is a secondary filter)
        gs.person.config['gpa'] = 4.2
        gs.person.save()
        form = SearchForm(QueryDict('gpa_min=4.1&columns=person.emplid'))
        high_gpa = form.search_results(units)
        self.assertIn(gs, high_gpa)

        gs.person.config['gpa'] = 2.2
        gs.person.save()
        form = SearchForm(QueryDict('gpa_min=4.1&columns=person.emplid'))
        high_gpa = form.search_results(units)
        self.assertNotIn(gs, high_gpa)
Пример #15
0
    def test_roles(self):
        # create person an give sysadmin role
        p1 = Person(emplid=210012345, userid="test1",
                last_name="Lname", first_name="Fname", pref_first_name="Fn", middle_name="M")
        p1.save()
        
        unit = Unit.objects.get(label="UNIV")
        r = Role(person=p1, role="SYSA", unit=unit)
        r.save()
        self.assertEqual( str(r), "Lname, Fname (System Administrator, UNIV)")

        # check the front end
        client = Client()
        client.login_user("test1")

        url = reverse('coredata.views.role_list')
        response = basic_page_tests(self, client, url)
        self.assertContains(response, 'Lname, Fname</a></td><td>System Administrator</td>')

        # add a new role with the front end
        oldcount = Role.objects.filter(role='FAC').count()
        url = reverse('coredata.views.new_role')
        response = basic_page_tests(self, client, url)
        
        response = client.post(url, {'person':'33333333', 'role':'FAC', 'unit': 2})
        self.assertEquals(response.status_code, 200)
        validate_content(self, response.content, url)
        self.assertTrue("could not import DB2 module" in response.content
                        or "could not connect to reporting database" in response.content
                        or "Could not find this emplid." in response.content
                        or "Reporting database access has been disabled" in response.content
                        or "Could not communicate with reporting database" in response.content)

        response = client.post(url, {'person':p1.emplid, 'role':'FAC', 'unit':unit.id})
        self.assertEquals(response.status_code, 302)
        
        # make sure the role is now there
        self.assertEquals( Role.objects.filter(role='FAC').count(), oldcount+1)
Пример #16
0
    def test_upload(self):
        _, course = create_offering()
        a1 = NumericActivity(name="Assignment 1", short_name="A1", status="RLS", offering=course, position=2, max_grade=15, due_date=datetime.datetime.now() + datetime.timedelta(hours=1), group=False)
        a1.save()
        p = Person.objects.get(userid="ggbaker")
        member = Member(person=p, offering=course, role="INST", career="NONS", added_reason="UNK")
        member.save()
        c = Code.Component(activity=a1, title="Code File", position=3, max_size=2000, allowed=".py")
        c.save()

        userid1 = "0aaa0"
        userid2 = "0aaa1"
        userid3 = "0aaa2"
        for u in [userid1, userid2,userid3]:
            p = Person.objects.get(userid=u)
            m = Member(person=p, offering=course, role="STUD", credits=3, career="UGRD", added_reason="UNK")
            m.save()
        
        # submit as student
        client = Client()
        client.login_user("0aaa0")
        url = reverse('submission.views.show_components', kwargs={'course_slug': course.slug,'activity_slug':a1.slug})
        response = basic_page_tests(self, client, url)

        # submit a file
        tmpf = tempfile.NamedTemporaryFile(suffix=".py", delete=False)
        codecontents = 'print "Hello World!"\n'
        tmpf.write(codecontents)
        tmpf.close()

        try:
            fh = open(tmpf.name, "r")
            data = {"%i-code" % (c.id): fh}
            response = client.post(url, data)
            self.assertEquals(response.status_code, 302)
            
        finally:
            os.unlink(tmpf.name)

        # make sure it's there and correct
        subs = StudentSubmission.objects.all()
        self.assertEquals(len(subs), 1)
        sub = subs[0]
        self.assertEquals(sub.member.person.userid, '0aaa0')
            
        codes = SubmittedCode.objects.all()
        self.assertEquals(len(codes), 1)
        code = codes[0]
        code.code.open()
        self.assertEquals(code.code.read(), codecontents)
Пример #17
0
    def test_valid_simple_initial_form_submission_loggedin(self):
        logged_in_person = Person.objects.get(userid="ggbaker")
        self.client.login_user(logged_in_person.userid)

        old_form_submission_count = len(FormSubmission.objects.all())
        old_sheet_submission_count = len(SheetSubmission.objects.all())

        url = reverse('onlineforms.views.sheet_submission_initial', kwargs={'form_slug': "comp-simple-form"})
        response = basic_page_tests(self, self.client, url)
        self.assertEqual(response.status_code, 200)
        # make sure it's not displaying the add-nonsfu form
        self.assertNotContains(response, '<input type="hidden" name="add-nonsfu" value="True"/>')
        # check for some important fields
        # note: the keys are the slugs of the field
        fill_data = {"favorite-color": "Black", "reason": "Because it's metal", "second-favorite-color": "Green"}
        # submit the form
        post_data = {
            '0': fill_data["favorite-color"],
            '1': fill_data["reason"],
            '2': fill_data["second-favorite-color"],
            'submit': "Yesplease",
        }
        response = self.client.post(url, post_data, follow=True)
        self.assertEqual(response.status_code, 200)
        # check that a success messaging is being displayed
        self.assertContains(response, '<li class="success">')
        # check that one form submission and one sheet submission got created
        self.assertEqual(old_form_submission_count + 1, len(FormSubmission.objects.all()))
        self.assertEqual(old_sheet_submission_count + 1, len(SheetSubmission.objects.all()))
        # find the submission in the database
        form_submission = FormSubmission.objects.latest('id')
        self.assertTrue(form_submission)
        sheet_submission = SheetSubmission.objects.latest('id')
        self.assertTrue(sheet_submission)
        self.assertEqual(sheet_submission.form_submission, form_submission)
        # make sure the person we logged in as got form initiator credits
        self.assertTrue(form_submission.initiator.isSFUPerson())
        self.assertEqual(form_submission.initiator.sfuFormFiller, logged_in_person)
        # do the same for the sheet submission
        self.assertTrue(sheet_submission.filler.isSFUPerson())
        self.assertEqual(sheet_submission.filler.sfuFormFiller, logged_in_person)
        # verify the data
        field_submissions = FieldSubmission.objects.filter(sheet_submission=sheet_submission).order_by('field__order')
        self.assertEqual(len(fill_data), len(field_submissions))
        for field_submission in field_submissions:
            self.assertEqual(fill_data[field_submission.field.slug], field_submission.data['info'])
        # check the sheet submission and form submission status
        self.assertEqual(sheet_submission.status, "DONE")
        # form submissions is pending until someone manually marks it done
        self.assertEqual(form_submission.status, "PEND")
Пример #18
0
    def test_component_view_page(self):
        _, course = create_offering()
        a1 = NumericActivity(name="Assignment 1", short_name="A1", status="RLS", offering=course, position=2, max_grade=15, due_date="2010-04-01")
        a1.save()
        a2 = NumericActivity(name="Assignment 2", short_name="A2", status="RLS", offering=course, position=1, max_grade=15, due_date="2010-03-01")
        a2.save()

        p = Person.objects.get(userid="ggbaker")
        member = Member(person=p, offering=course, role="INST", career="NONS", added_reason="UNK")
        member.save()

        c1 = URL.Component(activity=a1, title="URL Link", position=8)
        c1.save()
        c2 = Archive.Component(activity=a1, title="Archive File", position=1, max_size=100000)
        c2.save()
        c3 = Code.Component(activity=a1, title="Code File", position=3, max_size=2000, allowed=".py")
        c3.save()
        client = Client()
        client.login_user("ggbaker")
        
        # When no component, should display error message
        url = reverse('submission.views.show_components', kwargs={'course_slug':course.slug, 'activity_slug':a2.slug})
        response = basic_page_tests(self, client, url)
        self.assertContains(response, 'No components configured.')
        # add component and test
        component = URL.Component(activity=a2, title="URL2", position=1)
        component.save()
        component = Archive.Component(activity=a2, title="Archive2", position=1, max_size=100)
        component.save()
        # should all appear
        response = basic_page_tests(self, client, url)
        self.assertContains(response, "URL2")
        self.assertContains(response, "Archive2")
        # make sure type displays
        #self.assertContains(response, '<li class="view"><label>Type:</label>Archive</li>')
        # delete component
        self.assertRaises(NotImplementedError, component.delete)
Пример #19
0
    def test_artifact_notes_success(self):
        """
        Check overall pages for the grad module and make sure they all load
        """
        client = Client()
        client.login_user("dzhao")

        for view in ['new_nonstudent', 'new_artifact', 'view_artifacts',
                     'view_courses', 'view_course_offerings', 'view_all_semesters']:
            try:
                url = reverse('advisornotes.views.' + view, kwargs={})
                response = basic_page_tests(self, client, url)
                self.assertEqual(response.status_code, 200)
            except:
                print "with view==" + repr(view)
                raise
Пример #20
0
    def test_page_load(self):
        """
        Tests that various pages load
        """
        # as instructor...
        client = Client()
        client.login_user("ggbaker")

        url = reverse('discuss.views.discussion_index', kwargs={'course_slug': self.offering.slug})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
        
        url = reverse('discuss.views.create_topic', kwargs={'course_slug': self.offering.slug})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('discuss.views.view_topic', kwargs={'course_slug': self.offering.slug, 'topic_slug': self.topic.slug})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('discuss.views.change_topic_status', kwargs={'course_slug': self.offering.slug, 'topic_slug': self.topic.slug})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # as the author of the topic/message
        client = Client()
        client.login_user(self.topic.author.person.userid)

        url = reverse('discuss.views.edit_topic', kwargs={'course_slug': self.offering.slug, 'topic_slug': self.topic.slug})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        client = Client()
        client.login_user(self.message.author.person.userid)
        
        url = reverse('discuss.views.edit_message', kwargs={'course_slug': self.offering.slug,
                      'topic_slug': self.topic.slug, 'message_slug': self.message.slug})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
        
        url = reverse('discuss.views.remove_message', kwargs={'course_slug': self.offering.slug,
                      'topic_slug': self.topic.slug, 'message_slug': self.message.slug})
        response = client.post(url)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(DiscussionMessage.objects.get(id=self.message.id).status, 'HID')
Пример #21
0
    def test_import(self):

        #  A weird looking workaround.  In devtest_importer, we specified the title of the activity component to be
        #  "part-➀", and the slug to be "part-1".  However, the slug gets changed on every save, so it gets changed to
        #  "part". Let's do this so, in this instance, it gets changed back to "part-1"
        ActivityComponent.objects.filter(slug='part').update(slug='part-1')
        self.client.login_user('ggbaker')
        url = reverse('offering:marking:import_marks', kwargs={'course_slug':self.crs.slug, 'activity_slug':self.act.slug})
        response = basic_page_tests(self, self.client, url)
        
        # post first file
        with open('marking/testfiles/marking_import1.json') as file:
            post_data = {'file':[file]}
            response = self.client.post(url, post_data)

        self.assertEqual(response.status_code, 302)
        
        # check that the parts are there
        marks = StudentActivityMark.objects.filter(activity=self.act)
        m = marks.get(numeric_grade__member__person__userid="0aaa1")
        self.assertEqual(m.numeric_grade.value, Decimal('3'))
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEqual(mc.value, Decimal('3'))
        self.assertEqual(mc.comment, "0aaa1 1")
        # No longer true since we make components optional in the import
        # mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        # self.assertEquals(mc.value, Decimal('0'))
        # self.assertEquals(mc.comment, "")

        m = marks.get(numeric_grade__member__person__userid="0aaa2")
        self.assertAlmostEqual(float(m.numeric_grade.value), 3.6)
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEqual(mc.value, Decimal('4'))
        self.assertEqual(mc.comment, "0aaa2 1a")
        # Same as above.
        # mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        # self.assertEquals(mc.value, Decimal('0'))
        # self.assertEquals(mc.comment, "")

        # post second file: should be combined with first.
        with open('marking/testfiles/marking_import2.json') as file:
            post_data = {'file':[file]}
            response = self.client.post(url, post_data)
        self.assertEqual(response.status_code, 302)
        
        marks = StudentActivityMark.objects.filter(activity=self.act)
        m = marks.filter(numeric_grade__member__person__userid="0aaa1").latest('created_at')
        self.assertAlmostEqual(float(m.numeric_grade.value), 3.2)
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEqual(mc.value, Decimal('3'))
        self.assertEqual(mc.comment, "0aaa1 1")
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        self.assertEqual(mc.value, Decimal('1'))
        self.assertEqual(mc.comment, "0aaa1 2")

        m = marks.filter(numeric_grade__member__person__userid="0aaa2").latest('created_at')
        self.assertAlmostEqual(float(m.numeric_grade.value), 6.3)
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEqual(mc.value, Decimal('5'))
        self.assertEqual(mc.comment, "0aaa2 1b")
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        self.assertEqual(mc.value, Decimal('2'))
        self.assertEqual(mc.comment, "0aaa2 2")

        # test file attachment encoded in JSON
        with open('marking/testfiles/marking_import3.json') as file:
            post_data = {'file':[file]}
            response = self.client.post(url, post_data)
        self.assertEqual(response.status_code, 302)
        
        marks = StudentActivityMark.objects.filter(activity=self.act, numeric_grade__member__person__userid="0aaa0")
        self.assertEqual(len(marks), 1)
        m = marks[0]
        self.assertEqual(m.file_mediatype, 'text/plain')
        m.file_attachment.open()
        data = m.file_attachment.read()
        self.assertEqual(data, b'Hello world!\n')
        self.assertEqual(m.attachment_filename(), 'hello.txt')
Пример #22
0
    def test_advanced_search_2(self):
        client = Client()
        client.login_user('dzhao')
        units = [
            r.unit for r in Role.objects_fresh.filter(person__userid='dzhao',
                                                      role='GRAD')
        ]

        # basic search with the frontend
        url = reverse('grad:search', kwargs={})
        qs = 'student_status=PART&student_status=ACTI&columns=person.emplid&columns=person.userid&columns=program'
        response = basic_page_tests(self, client, url + '?' + qs)
        self.assertIn('grad/search_results.html',
                      [t.name for t in response.templates])
        search_res_1 = response.context['grads']

        # test the searching API
        form = SearchForm(QueryDict(qs))
        search_res_2 = form.search_results(units)
        self.assertEqual(set(search_res_1), set(search_res_2))

        form = SearchForm(
            QueryDict('student_status=ACTI&columns=person.emplid'))
        all_grads = form.search_results(units)
        gs = all_grads[0]

        # test student status search (which is a simple in-database query)
        gs.status = 'ACTI'
        gs.save()
        form = SearchForm(
            QueryDict('student_status=ACTI&columns=person.emplid'))
        status_search = form.search_results(units)
        self.assertIn(gs, status_search)
        form = SearchForm(
            QueryDict('student_status=LEAV&columns=person.emplid'))
        status_search = form.search_results(units)
        self.assertNotIn(gs, status_search)

        # test semester search (which a more difficult in-database query)
        sem = gs.start_semester
        form = SearchForm(
            QueryDict('start_semester_start=%s&columns=person.emplid' %
                      (sem.name)))
        semester_search = form.search_results(units)
        self.assertIn(gs, semester_search)
        form = SearchForm(
            QueryDict('start_semester_start=%s&columns=person.emplid' %
                      (sem.next_semester().name)))
        semester_search = form.search_results(units)
        self.assertNotIn(gs, semester_search)

        # test GPA searching (which is a secondary filter)
        gs.person.config['gpa'] = 4.2
        gs.person.save()
        form = SearchForm(QueryDict('gpa_min=4.1&columns=person.emplid'))
        high_gpa = form.search_results(units)
        self.assertIn(gs, high_gpa)

        gs.person.config['gpa'] = 2.2
        gs.person.save()
        form = SearchForm(QueryDict('gpa_min=4.1&columns=person.emplid'))
        high_gpa = form.search_results(units)
        self.assertNotIn(gs, high_gpa)
Пример #23
0
    def test_frontend(self):
        client = Client()
        client.login_user('ggbaker')

        # set up a course
        c = CourseOffering.objects.get(slug=self.c_slug)
        a1 = NumericActivity(offering = c, name = 'test_assignment_1', \
                            short_name = 'ta1', status = 'RLS', \
                            due_date = datetime.now(), max_grade = 100, position = 0, group=True)
        a1.save()
        a2 = NumericActivity(offering = c, name = 'test_assignment_1', \
                            short_name = 'ta1', status = 'RLS', \
                            due_date = datetime.now(), max_grade = 100, position = 0, group=False)
        a2.save()

        stud1 = Member.objects.get(person=Person.objects.get(userid='0aaa0'),
                                   offering=c)
        stud2 = Member.objects.get(person=Person.objects.get(userid='0aaa1'),
                                   offering=c)
        instr = Member.objects.get(person=Person.objects.get(userid='ggbaker'),
                                   offering=c)
        group = Group.objects.create(courseoffering=c,
                                     name='hello',
                                     manager=stud1)
        member1 = GroupMember.objects.create(group=group,
                                             student=stud1,
                                             confirmed=True,
                                             activity=a1)
        member2 = GroupMember.objects.create(group=group,
                                             student=stud2,
                                             confirmed=True,
                                             activity=a1)

        # marking form (student)
        url = reverse('marking.views.marking_student',
                      kwargs={
                          'course_slug': c.slug,
                          'activity_slug': a2.slug,
                          'userid': stud1.person.userid
                      })

        response = basic_page_tests(self, client, url)

        ac = ActivityComponent(numeric_activity=a2,
                               max_mark=5,
                               title="AC Title",
                               description="AC Description",
                               position=1,
                               deleted=False)
        ac.save()
        ac = ActivityComponent(numeric_activity=a2,
                               max_mark=5,
                               title="AC Title2",
                               description="AC Description2",
                               position=2,
                               deleted=False)
        ac.save()
        cp = CommonProblem(activity_component=ac,
                           title="CP title",
                           penalty=2,
                           description="Cp description",
                           deleted=False)
        cp.save()

        response = basic_page_tests(self, client, url)

        # submit the form and check that objects were created
        PENALTY = '12.5'  # Percentage
        CMP_1_VALUE = '5.5'
        CMP_2_VALUE = '3'
        ADJ = '1.25'  # Adjustments are subtracted
        TOTAL_MARK = (
            (Decimal(CMP_1_VALUE) + Decimal(CMP_2_VALUE) - Decimal(ADJ)) *
            (1 - (Decimal(PENALTY) / 100))).quantize(Decimal('.01'),
                                                     rounding=ROUND_HALF_EVEN)

        response = client.post(
            url, {
                'cmp-1-value': float(CMP_1_VALUE),
                'cmp-1-comment': 'perfect part 1',
                'cmp-2-value': float(CMP_2_VALUE),
                'cmp-2-comment': 'ok',
                'mark_adjustment': float(ADJ),
                'mark_adjustment_reason': 'reason',
                'late_penalty': float(PENALTY),
                u'overall_comment': 'overall'
            })
        self.assertEquals(response.status_code, 302)
        sam = StudentActivityMark.objects.filter(activity=a2,
                                                 numeric_grade__member=stud1)
        self.assertEquals(len(sam), 1)
        sam = sam[0]
        self.assertEquals(sam.mark_adjustment, Decimal(ADJ))
        self.assertEquals(sam.late_penalty, Decimal(PENALTY))
        self.assertEquals(sam.overall_comment, 'overall')
        self.assertEquals(sam.mark, TOTAL_MARK)
        acms = sam.activitycomponentmark_set.all()
        self.assertEquals(len(acms), 2)
        self.assertEquals(acms[0].value, Decimal(CMP_1_VALUE))
        self.assertEquals(acms[0].comment, 'perfect part 1')
        g = NumericGrade.objects.get(activity=a2, member=stud1)
        self.assertEquals(g.value, TOTAL_MARK)

        # make sure we get old data for "mark based on"
        response = basic_page_tests(self, client,
                                    url + "?base_activity_mark=" + str(sam.id))
        #self.assertContains(response, 'name="cmp-1-value" type="text" value="{0}'.format(CMP_1_VALUE))
        #self.assertContains(response, 'name="late_penalty" type="text" value="{0}'.format(PENALTY))

        # look at the "view details" page
        url = reverse('marking.views.mark_summary_student',
                      kwargs={
                          'course_slug': c.slug,
                          'activity_slug': a2.slug,
                          'userid': stud1.person.userid
                      })
        response = basic_page_tests(self, client, url)
        self.assertContains(response, 'perfect part 1')

        # marking form (group)
        url = reverse('marking.views.marking_student',
                      kwargs={
                          'course_slug': c.slug,
                          'activity_slug': a1.slug,
                          'userid': stud1.person.userid
                      })
        response = basic_page_tests(self, client, url)

        ac = ActivityComponent(numeric_activity=a1,
                               max_mark=5,
                               title="AC Title",
                               description="AC Description",
                               position=1,
                               deleted=False)
        ac.save()
        ac = ActivityComponent(numeric_activity=a1,
                               max_mark=5,
                               title="AC Title2",
                               description="AC Description2",
                               position=2,
                               deleted=False)
        ac.save()
        cp = CommonProblem(activity_component=ac,
                           title="CP title",
                           penalty=2,
                           description="Cp description",
                           deleted=False)
        cp.save()

        response = basic_page_tests(self, client, url)

        # common problem form
        url = reverse('marking.views.manage_common_problems',
                      kwargs={
                          'course_slug': c.slug,
                          'activity_slug': a2.slug
                      })
        response = basic_page_tests(self, client, url)

        # mark all (student and group)
        url = reverse('marking.views.mark_all_students',
                      kwargs={
                          'course_slug': c.slug,
                          'activity_slug': a2.slug
                      })
        response = basic_page_tests(self, client, url)
        # mark all (student and group)
        url = reverse('marking.views.mark_all_groups',
                      kwargs={
                          'course_slug': c.slug,
                          'activity_slug': a1.slug
                      })
        response = basic_page_tests(self, client, url)
Пример #24
0
    def test_frontend(self):
        client = Client()
        client.login_user('ggbaker')
        
        # set up a course
        c = CourseOffering.objects.get(slug = self.c_slug)
        a1 = NumericActivity(offering = c, name = 'test_assignment_1', \
                            short_name = 'ta1', status = 'RLS', \
                            due_date = datetime.now(), max_grade = 100, position = 0, group=True)
        a1.save()
        a2 = NumericActivity(offering = c, name = 'test_assignment_1', \
                            short_name = 'ta1', status = 'RLS', \
                            due_date = datetime.now(), max_grade = 100, position = 0, group=False)
        a2.save()
        
        stud1 = Member.objects.get(person = Person.objects.get(userid = '0aaa0'), offering = c)
        stud2 = Member.objects.get(person = Person.objects.get(userid = '0aaa1'), offering = c)
        instr = Member.objects.get(person = Person.objects.get(userid = 'ggbaker'), offering = c)
        group = Group.objects.create(courseoffering = c, name = 'hello', manager = stud1)
        member1 = GroupMember.objects.create(group = group, student = stud1, confirmed = True, activity=a1)
        member2 = GroupMember.objects.create(group = group, student = stud2, confirmed = True, activity=a1)
        
        # marking form (student)
        url = reverse('offering:marking:marking_student', kwargs={'course_slug':c.slug, 'activity_slug':a2.slug, 'userid':stud1.person.userid})

        response = basic_page_tests(self, client, url)
        
        ac = ActivityComponent(numeric_activity=a2, max_mark=5, title="AC Title", description="AC Description", position=1, deleted=False)
        ac.save()
        ac = ActivityComponent(numeric_activity=a2, max_mark=5, title="AC Title2", description="AC Description2", position=2, deleted=False)
        ac.save()
        cp = CommonProblem(activity_component=ac, title="CP title", penalty=2, description="Cp description", deleted=False)
        cp.save()

        response = basic_page_tests(self, client, url)
        
        # submit the form and check that objects were created
        PENALTY = '12.5' # Percentage
        CMP_1_VALUE = '5.5'
        CMP_2_VALUE = '3'
        ADJ = '1.25'# Adjustments are subtracted
        TOTAL_MARK = ((Decimal(CMP_1_VALUE) + Decimal(CMP_2_VALUE) - Decimal(ADJ)) *
            (1 - (Decimal(PENALTY) / 100))).quantize(Decimal('.01'), rounding=ROUND_HALF_EVEN)

        response = client.post(url, {'cmp-1-value': float(CMP_1_VALUE), 'cmp-1-comment': 'perfect part 1',
            'cmp-2-value': float(CMP_2_VALUE), 'cmp-2-comment': 'ok', 'mark_adjustment': float(ADJ),
            'mark_adjustment_reason': 'reason', 'late_penalty': float(PENALTY),
            'overall_comment': 'overall'})
        self.assertEqual(response.status_code, 302)
        sam = StudentActivityMark.objects.filter(activity=a2, numeric_grade__member=stud1)
        self.assertEqual(len(sam), 1)
        sam = sam[0]
        self.assertEqual(sam.mark_adjustment, Decimal(ADJ))
        self.assertEqual(sam.late_penalty, Decimal(PENALTY))
        self.assertEqual(sam.overall_comment, 'overall')
        self.assertEqual(sam.mark, TOTAL_MARK)
        acms = sam.activitycomponentmark_set.all()
        self.assertEqual(len(acms), 2)
        self.assertEqual(acms[0].value, Decimal(CMP_1_VALUE))
        self.assertEqual(acms[0].comment, 'perfect part 1')
        g = NumericGrade.objects.get(activity=a2, member=stud1)
        self.assertEqual(g.value, TOTAL_MARK)
        
        # make sure we get old data for "mark based on"
        response = basic_page_tests(self, client, url + "?base_activity_mark="+str(sam.id))
        #self.assertContains(response, 'name="cmp-1-value" type="text" value="{0}'.format(CMP_1_VALUE))
        #self.assertContains(response, 'name="late_penalty" type="text" value="{0}'.format(PENALTY))

        # look at the "view details" page
        url = reverse('offering:marking:mark_summary_student', kwargs={'course_slug':c.slug, 'activity_slug':a2.slug, 'userid':stud1.person.userid})
        response = basic_page_tests(self, client, url)
        self.assertContains(response, 'perfect part 1')

        # marking form (group)
        url = reverse('offering:marking:marking_student', kwargs={'course_slug':c.slug,
            'activity_slug':a1.slug, 'userid':stud1.person.userid})
        response = basic_page_tests(self, client, url)
        
        ac = ActivityComponent(numeric_activity=a1, max_mark=5, title="AC Title",
            description="AC Description", position=1, deleted=False)
        ac.save()
        ac = ActivityComponent(numeric_activity=a1, max_mark=5, title="AC Title2",
            description="AC Description2", position=2, deleted=False)
        ac.save()
        cp = CommonProblem(activity_component=ac, title="CP title", penalty=2,
            description="Cp description", deleted=False)
        cp.save()

        response = basic_page_tests(self, client, url)

        # common problem form
        url = reverse('offering:marking:manage_common_problems', kwargs={'course_slug':c.slug, 'activity_slug':a2.slug})
        response = basic_page_tests(self, client, url)
        
        # mark all (student and group)
        url = reverse('offering:mark_all_students', kwargs={'course_slug':c.slug, 'activity_slug':a2.slug})
        response = basic_page_tests(self, client, url)
        # mark all (student and group)
        url = reverse('offering:mark_all_groups', kwargs={'course_slug':c.slug, 'activity_slug':a1.slug})
        response = basic_page_tests(self, client, url)
Пример #25
0
    def test_upload(self):
        _, course = create_offering()
        a1 = NumericActivity(name="Assignment 1",
                             short_name="A1",
                             status="RLS",
                             offering=course,
                             position=2,
                             max_grade=15,
                             due_date=datetime.datetime.now() +
                             datetime.timedelta(hours=1),
                             group=False)
        a1.save()
        p = Person.objects.get(userid="ggbaker")
        member = Member(person=p,
                        offering=course,
                        role="INST",
                        career="NONS",
                        added_reason="UNK")
        member.save()
        c = Code.Component(activity=a1,
                           title="Code File",
                           position=3,
                           max_size=2000,
                           allowed=".py")
        c.save()

        userid1 = "0aaa0"
        userid2 = "0aaa1"
        userid3 = "0aaa2"
        for u in [userid1, userid2, userid3]:
            p = Person.objects.get(userid=u)
            m = Member(person=p,
                       offering=course,
                       role="STUD",
                       credits=3,
                       career="UGRD",
                       added_reason="UNK")
            m.save()

        # submit as student
        client = Client()
        client.login_user("0aaa0")
        url = reverse('submission.views.show_components',
                      kwargs={
                          'course_slug': course.slug,
                          'activity_slug': a1.slug
                      })
        response = basic_page_tests(self, client, url)

        # submit a file
        tmpf = tempfile.NamedTemporaryFile(suffix=".py", delete=False)
        codecontents = 'print "Hello World!"\n'
        tmpf.write(codecontents)
        tmpf.close()

        try:
            fh = open(tmpf.name, "r")
            data = {"%i-code" % (c.id): fh}
            response = client.post(url, data)
            self.assertEquals(response.status_code, 302)

        finally:
            os.unlink(tmpf.name)

        # make sure it's there and correct
        subs = StudentSubmission.objects.all()
        self.assertEquals(len(subs), 1)
        sub = subs[0]
        self.assertEquals(sub.member.person.userid, '0aaa0')

        codes = SubmittedCode.objects.all()
        self.assertEquals(len(codes), 1)
        code = codes[0]
        code.code.open()
        self.assertEquals(code.code.read(), codecontents)
Пример #26
0
    def test_import(self):

        #  A weird looking workaround.  In devtest_importer, we specified the title of the activity component to be
        #  "part-➀", and the slug to be "part-1".  However, the slug gets changed on every save, so it gets changed to
        #  "part". Let's do this so, in this instance, it gets changed back to "part-1"
        ActivityComponent.objects.filter(slug='part').update(slug='part-1')
        self.client.login_user('ggbaker')
        url = reverse('offering:marking:import_marks',
                      kwargs={
                          'course_slug': self.crs.slug,
                          'activity_slug': self.act.slug
                      })
        response = basic_page_tests(self, self.client, url)

        # post first file
        with open('marking/testfiles/marking_import1.json') as file:
            post_data = {'file': [file]}
            response = self.client.post(url, post_data)

        self.assertEqual(response.status_code, 302)

        # check that the parts are there
        marks = StudentActivityMark.objects.filter(activity=self.act)
        m = marks.get(numeric_grade__member__person__userid="0aaa1")
        self.assertEqual(m.numeric_grade.value, Decimal('3'))
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEqual(mc.value, Decimal('3'))
        self.assertEqual(mc.comment, "0aaa1 1")
        # No longer true since we make components optional in the import
        # mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        # self.assertEquals(mc.value, Decimal('0'))
        # self.assertEquals(mc.comment, "")

        m = marks.get(numeric_grade__member__person__userid="0aaa2")
        self.assertAlmostEqual(float(m.numeric_grade.value), 3.6)
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEqual(mc.value, Decimal('4'))
        self.assertEqual(mc.comment, "0aaa2 1a")
        # Same as above.
        # mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        # self.assertEquals(mc.value, Decimal('0'))
        # self.assertEquals(mc.comment, "")

        # post second file: should be combined with first.
        with open('marking/testfiles/marking_import2.json') as file:
            post_data = {'file': [file]}
            response = self.client.post(url, post_data)
        self.assertEqual(response.status_code, 302)

        marks = StudentActivityMark.objects.filter(activity=self.act)
        m = marks.filter(
            numeric_grade__member__person__userid="0aaa1").latest('created_at')
        self.assertAlmostEqual(float(m.numeric_grade.value), 3.2)
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEqual(mc.value, Decimal('3'))
        self.assertEqual(mc.comment, "0aaa1 1")
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        self.assertEqual(mc.value, Decimal('1'))
        self.assertEqual(mc.comment, "0aaa1 2")

        m = marks.filter(
            numeric_grade__member__person__userid="0aaa2").latest('created_at')
        self.assertAlmostEqual(float(m.numeric_grade.value), 6.3)
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEqual(mc.value, Decimal('5'))
        self.assertEqual(mc.comment, "0aaa2 1b")
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        self.assertEqual(mc.value, Decimal('2'))
        self.assertEqual(mc.comment, "0aaa2 2")

        # test file attachment encoded in JSON
        with open('marking/testfiles/marking_import3.json') as file:
            post_data = {'file': [file]}
            response = self.client.post(url, post_data)
        self.assertEqual(response.status_code, 302)

        marks = StudentActivityMark.objects.filter(
            activity=self.act, numeric_grade__member__person__userid="0aaa0")
        self.assertEqual(len(marks), 1)
        m = marks[0]
        self.assertEqual(m.file_mediatype, 'text/plain')
        m.file_attachment.open()
        data = m.file_attachment.read()
        self.assertEqual(data, b'Hello world!\n')
        self.assertEqual(m.attachment_filename(), 'hello.txt')
Пример #27
0
    def test_application(self):
        p = Person.objects.get(emplid=210012345)
        s = Semester.objects.get(name="1077")
        unit = Unit.objects.get(label="CMPT")
        d = CourseDescription(unit=unit, description="Lab TA", labtut=True)
        d.save()
        d = CourseDescription(unit=unit, description="Office Hours", labtut=False)
        d.save()

        #Create posting that closes in a long time so no applications are late
        posting = TAPosting(semester=s, unit=unit,opens=date(2007,9,4), closes=date(2099,9,4))
        posting.config['accounts'] = [a.id for a in Account.objects.all()]
        posting.config['start'] = date(2100,10,10)
        posting.config['end'] = date(2101,10,10)
        posting.config['deadline'] = date(2099,9,20)
        posting.save() 

        #Create application for posting as well as campus and course preferences
        app = TAApplication(posting=posting, person=p, category="UTA", base_units=2, sin="123123123", course_load="No Other Courses")
        app.save()

        cp1 = CampusPreference(app=app, campus="BRNBY", pref="PRF")
        cp2 = CampusPreference(app=app, campus="SURRY", pref="NOT")
        cp1.save()
        cp2.save()

        c1 = Course.objects.get(subject="CMPT", number="120")
        
        course1 = CoursePreference(app=app, course=c1, taken="YES", exper="FAM", rank=1)
        course1.save()

        #Login a ta admin
        client = Client()
        userid = Role.objects.filter(role="TAAD")[0].person.userid
        client.login_user(userid)     

        #Check that assign_tas page has two courses in it, one with someone who has applied
        url = reverse('ta.views.assign_tas', kwargs={'post_slug': posting.slug,})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, '<a href="/ta/%s/%s"' % (posting.slug, self.co1.slug) )
        self.assertContains(response, '<a href="/ta/%s/%s"' % (posting.slug, self.co2.slug) )
        self.assertContains(response, '<td class="num">1</td>')

        #Check the view application page to make sure it displays properly
        url = reverse('ta.views.view_application', kwargs={'post_slug': posting.slug, 'userid':app.person.userid,})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, '<a href="mailto:%[email protected]"' % (app.person.userid) )
        self.assertContains(response, '<td>%s</td>' % (c1) )
       
        #Check the assign_bu page to make sure applicant appears
        url = reverse('ta.views.assign_bus', kwargs={'post_slug': posting.slug, 'course_slug':self.co1.slug,})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, '<a href="/ta/%s/application/%s"' % (posting.slug, app.person.userid) )
       
        #Assign bu's to the applicant and make sure they show up on assign_ta page 
        post_data = {
            'form-TOTAL_FORMS':2,
            'form-INITIAL_FORMS':1,
            'form-MAX_NUM_FORMS':'',
            'form-0-rank':1,
            'form-0-bu':2.0,
        }
        response = client.post(url, post_data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, '<td class="num">2.00</td>')
Пример #28
0
    def test_pages(self):
        client = Client()
        client.login_user("dzhao")
        adv = Person.objects.get(userid='dzhao')

        # create some notes to work with
        unit = Unit.objects.get(slug='cmpt')
        ns = NonStudent(first_name="Non", last_name="Student", high_school="North South Burnaby-Surrey",
                        start_year=2000)
        ns.save()
        p1 = Person.objects.get(userid='0aaa6')
        n1 = AdvisorNote(student=p1, text="He seems like a nice student.", unit=unit, advisor=adv)
        n1.save()
        p2 = Person.objects.get(userid='0aaa8')
        p2.userid = None
        p2.save()
        n2 = AdvisorNote(student=p2, text="This guy doesn't have an active computing account.", unit=unit, advisor=adv)
        n2.save()
        n3 = AdvisorNote(nonstudent=ns, text="What a horrible person.", unit=unit, advisor=adv)
        n3.save()

        # index page
        url = reverse('advisornotes.views.advising', kwargs={})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # new nonstudent form
        url = reverse('advisornotes.views.new_nonstudent', kwargs={})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # student with userid
        url = reverse('advisornotes.views.advising', kwargs={})
        response = client.post(url, {'search': p1.emplid})
        self.assertEqual(response.status_code, 302)
        redir_url = response['location']
        student_url = reverse('advisornotes.views.student_notes', kwargs={'userid': p1.userid})
        self.assertIn(student_url, redir_url)
        response = basic_page_tests(self, client, student_url, check_valid=False)
        self.assertEqual(response.status_code, 200)
        new_url = reverse('advisornotes.views.new_note', kwargs={'userid': p1.userid})
        response = basic_page_tests(self, client, new_url)
        self.assertEqual(response.status_code, 200)

        # student with no userid
        response = client.post(url, {'search': p2.emplid})
        self.assertEqual(response.status_code, 302)
        redir_url = response['location']
        student_url = reverse('advisornotes.views.student_notes', kwargs={'userid': p2.emplid})
        self.assertIn(student_url, redir_url)
        response = basic_page_tests(self, client, student_url, check_valid=False)
        self.assertEqual(response.status_code, 200)
        new_url = reverse('advisornotes.views.new_note', kwargs={'userid': p2.emplid})
        response = basic_page_tests(self, client, new_url)
        self.assertEqual(response.status_code, 200)

        # non student
        response = client.post(url, {'search': ns.slug})
        self.assertEqual(response.status_code, 302)
        redir_url = response['location']
        student_url = reverse('advisornotes.views.student_notes', kwargs={'userid': ns.slug})
        self.assertIn(student_url, redir_url)
        response = basic_page_tests(self, client, student_url, check_valid=False)
        self.assertEqual(response.status_code, 200)
        new_url = reverse('advisornotes.views.new_note', kwargs={'userid': ns.slug})
        response = basic_page_tests(self, client, new_url)
        self.assertEqual(response.status_code, 200)

        # note content search
        url = reverse('advisornotes.views.note_search', kwargs={}) + "?text-search=nice"
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['notes']), 1)
        url = reverse('advisornotes.views.note_search', kwargs={}) + "?text-search="
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['notes']), 3)
Пример #29
0
    def test_application(self):
        p = Person.objects.get(emplid=210012345)
        s = Semester.objects.get(name="1077")
        unit = Unit.objects.get(label="CMPT")
        d = CourseDescription(unit=unit, description="Lab TA", labtut=True)
        d.save()
        d = CourseDescription(unit=unit, description="Office Hours", labtut=False)
        d.save()

        #Create posting that closes in a long time so no applications are late
        posting = TAPosting(semester=s, unit=unit,opens=date(2007,9,4), closes=date(2099,9,4))
        posting.config['accounts'] = [a.id for a in Account.objects.all()]
        posting.config['start'] = date(2100,10,10)
        posting.config['end'] = date(2101,10,10)
        posting.config['deadline'] = date(2099,9,20)
        posting.save() 

        #Create application for posting as well as campus and course preferences
        app = TAApplication(posting=posting, person=p, category="UTA", base_units=2, sin="123123123", course_load="No Other Courses")
        app.save()

        cp1 = CampusPreference(app=app, campus="BRNBY", pref="PRF")
        cp2 = CampusPreference(app=app, campus="SURRY", pref="NOT")
        cp1.save()
        cp2.save()

        c1 = Course.objects.get(subject="CMPT", number="120")
        
        course1 = CoursePreference(app=app, course=c1, taken="YES", exper="FAM", rank=1)
        course1.save()

        #Login a ta admin
        client = Client()
        userid = Role.objects.filter(role="TAAD")[0].person.userid
        client.login_user(userid)     

        #Check that assign_tas page has two courses in it, one with someone who has applied
        url = reverse('ta.views.assign_tas', kwargs={'post_slug': posting.slug,})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, '<a href="/ta/%s/%s"' % (posting.slug, self.co1.slug) )
        self.assertContains(response, '<a href="/ta/%s/%s"' % (posting.slug, self.co2.slug) )
        self.assertContains(response, '<td class="num">1</td>')

        #Check the view application page to make sure it displays properly
        url = reverse('ta.views.view_application', kwargs={'post_slug': posting.slug, 'userid':app.person.userid,})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, '<a href="mailto:%[email protected]"' % (app.person.userid) )
        self.assertContains(response, '<td>%s</td>' % (c1) )
       
        #Check the assign_bu page to make sure applicant appears
        url = reverse('ta.views.assign_bus', kwargs={'post_slug': posting.slug, 'course_slug':self.co1.slug,})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, '<a href="/ta/%s/application/%s"' % (posting.slug, app.person.userid) )
       
        #Assign bu's to the applicant and make sure they show up on assign_ta page 
        post_data = {
            'form-TOTAL_FORMS':2,
            'form-INITIAL_FORMS':1,
            'form-MAX_NUM_FORMS':'',
            'form-0-rank':1,
            'form-0-bu':2.0,
        }
        response = client.post(url, post_data, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, '<td class="num">2.00</td>')
Пример #30
0
    def test_import(self):
        self.client.login_user('ggbaker')
        url = reverse('marking.views.import_marks', kwargs={'course_slug':self.crs.slug, 'activity_slug':self.act.slug})
        response = basic_page_tests(self, self.client, url)
        
        # post first file
        with open('marking/testfiles/marking_import1.json') as file:
            post_data = {'file':[file]}
            response = self.client.post(url, post_data)
        
        self.assertEquals(response.status_code, 302)
        
        # check that the parts are there
        marks = StudentActivityMark.objects.filter(activity=self.act)
        m = marks.get(numeric_grade__member__person__userid="0aaa9")
        self.assertEquals(m.numeric_grade.value, Decimal('3'))
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEquals(mc.value, Decimal('3'))
        self.assertEquals(mc.comment, "0aaa9 1")
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        self.assertEquals(mc.value, Decimal('0'))
        self.assertEquals(mc.comment, "")

        m = marks.get(numeric_grade__member__person__userid="0aaa8")
        self.assertAlmostEquals(float(m.numeric_grade.value), 3.6)
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEquals(mc.value, Decimal('4'))
        self.assertEquals(mc.comment, "0aaa8 1a")
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        self.assertEquals(mc.value, Decimal('0'))
        self.assertEquals(mc.comment, "")
        
        
        # post second file: should be combined with first.
        with open('marking/testfiles/marking_import2.json') as file:
            post_data = {'file':[file]}
            response = self.client.post(url, post_data)
        self.assertEquals(response.status_code, 302)
        
        marks = StudentActivityMark.objects.filter(activity=self.act)
        m = marks.filter(numeric_grade__member__person__userid="0aaa9").latest('created_at')
        self.assertAlmostEquals(float(m.numeric_grade.value), 3.2)
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEquals(mc.value, Decimal('3'))
        self.assertEquals(mc.comment, "0aaa9 1")
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        self.assertEquals(mc.value, Decimal('1'))
        self.assertEquals(mc.comment, "0aaa9 2")

        m = marks.filter(numeric_grade__member__person__userid="0aaa8").latest('created_at')
        self.assertAlmostEquals(float(m.numeric_grade.value), 6.3)
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEquals(mc.value, Decimal('5'))
        self.assertEquals(mc.comment, "0aaa8 1b")
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        self.assertEquals(mc.value, Decimal('2'))
        self.assertEquals(mc.comment, "0aaa8 2")

        # test file attachment encoded in JSON
        with open('marking/testfiles/marking_import3.json') as file:
            post_data = {'file':[file]}
            response = self.client.post(url, post_data)
        self.assertEquals(response.status_code, 302)
        
        marks = StudentActivityMark.objects.filter(activity=self.act, numeric_grade__member__person__userid="0aaa7")
        self.assertEqual(len(marks), 1)
        m = marks[0]
        self.assertEqual(m.file_mediatype, 'text/plain')
        m.file_attachment.open()
        data = m.file_attachment.read()
        self.assertEqual(data, 'Hello world!\n')
        self.assertEqual(m.attachment_filename(), 'hello.txt')
Пример #31
0
    def test_component_view_page(self):
        _, course = create_offering()
        a1 = NumericActivity(name="Assignment 1",
                             short_name="A1",
                             status="RLS",
                             offering=course,
                             position=2,
                             max_grade=15,
                             due_date="2010-04-01")
        a1.save()
        a2 = NumericActivity(name="Assignment 2",
                             short_name="A2",
                             status="RLS",
                             offering=course,
                             position=1,
                             max_grade=15,
                             due_date="2010-03-01")
        a2.save()

        p = Person.objects.get(userid="ggbaker")
        member = Member(person=p,
                        offering=course,
                        role="INST",
                        career="NONS",
                        added_reason="UNK")
        member.save()

        c1 = URL.Component(activity=a1, title="URL Link", position=8)
        c1.save()
        c2 = Archive.Component(activity=a1,
                               title="Archive File",
                               position=1,
                               max_size=100000)
        c2.save()
        c3 = Code.Component(activity=a1,
                            title="Code File",
                            position=3,
                            max_size=2000,
                            allowed=".py")
        c3.save()
        client = Client()
        client.login_user("ggbaker")

        # When no component, should display error message
        url = reverse('submission.views.show_components',
                      kwargs={
                          'course_slug': course.slug,
                          'activity_slug': a2.slug
                      })
        response = basic_page_tests(self, client, url)
        self.assertContains(response, 'No components configured.')
        # add component and test
        component = URL.Component(activity=a2, title="URL2", position=1)
        component.save()
        component = Archive.Component(activity=a2,
                                      title="Archive2",
                                      position=1,
                                      max_size=100)
        component.save()
        # should all appear
        response = basic_page_tests(self, client, url)
        self.assertContains(response, "URL2")
        self.assertContains(response, "Archive2")
        # make sure type displays
        #self.assertContains(response, '<li class="view"><label>Type:</label>Archive</li>')
        # delete component
        self.assertRaises(NotImplementedError, component.delete)
Пример #32
0
    def test_group_submission_view(self):
        """
        test if group submission can be viewed by group member and non group member
        """
        now = datetime.datetime.now()
        _, course = create_offering()
        a1 = NumericActivity(name="Assignment 1",
                             short_name="A1",
                             status="RLS",
                             offering=course,
                             position=2,
                             max_grade=15,
                             due_date=now,
                             group=True)
        a1.save()
        a2 = NumericActivity(name="Assignment 2",
                             short_name="A2",
                             status="RLS",
                             offering=course,
                             position=1,
                             max_grade=15,
                             due_date=now,
                             group=True)
        a2.save()
        p = Person.objects.get(userid="ggbaker")
        member = Member(person=p,
                        offering=course,
                        role="INST",
                        career="NONS",
                        added_reason="UNK")
        member.save()
        c1 = URL.Component(activity=a1, title="URL Link", position=8)
        c1.save()
        c2 = Archive.Component(activity=a1,
                               title="Archive File",
                               position=1,
                               max_size=100000)
        c2.save()
        c3 = Code.Component(activity=a1,
                            title="Code File",
                            position=3,
                            max_size=2000,
                            allowed=".py")
        c3.save()

        userid1 = "0aaa0"
        userid2 = "0aaa1"
        userid3 = "0aaa2"
        for u in [userid1, userid2, userid3]:
            p = Person.objects.get(userid=u)
            m = Member(person=p,
                       offering=course,
                       role="STUD",
                       credits=3,
                       career="UGRD",
                       added_reason="UNK")
            m.save()
        m = Member.objects.get(person__userid=userid1, offering=course)
        g = Group(name="Test Group", manager=m, courseoffering=course)
        g.save()
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a1)
        gm.save()
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a2)
        gm.save()
        m = Member.objects.get(person__userid=userid2, offering=course)
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a1)
        gm.save()
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a2)
        gm.save()
        m = Member.objects.get(person__userid=userid3, offering=course)
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a2)
        gm.save()

        client = Client()
        # login as "0aaa0", member of group : test_group for assignment1 and assgnment2
        client.login_user("0aaa0")

        #submission page for assignment 1
        url = reverse('submission.views.show_components',
                      kwargs={
                          'course_slug': course.slug,
                          'activity_slug': a1.slug
                      })
        response = basic_page_tests(self, client, url)
        self.assertContains(
            response,
            "This is a group submission. You will submit on behalf of the group Test Group."
        )
        self.assertContains(
            response, "You haven't made a submission for this component.")
Пример #33
0
    def test_valid_simple_initial_form_submission_anonymous(self):
        person = {
            'first_name': "Alan",
            'last_name': "Turing",
            'email_address': "*****@*****.**"
        }
        old_form_submission_count = len(FormSubmission.objects.all())
        old_sheet_submission_count = len(SheetSubmission.objects.all())

        url = reverse('onlineforms:sheet_submission_initial',
                      kwargs={'form_slug': "comp-simple-form"})
        response = basic_page_tests(self, self.client, url)
        self.assertEqual(response.status_code, 200)
        # check that the non sfu form is up
        self.assertContains(
            response, '<input type="hidden" name="add-nonsfu" value="True"/>')
        # check for some important fields
        # note: the keys are the slugs of the field
        fill_data = {
            "favorite-color": "Black",
            "reason": "Because it's metal",
            "second-favorite-color": "Green"
        }
        # submit the form
        post_data = {
            'first_name': person["first_name"],
            'last_name': person["last_name"],
            'email_address': person["email_address"],
            'add-nonsfu': True,
            '0': fill_data["favorite-color"],
            '1': fill_data["reason"],
            '2': fill_data["second-favorite-color"],
            'submit': "Okay go",
        }
        response = self.client.post(url, post_data, follow=True)
        self.assertEqual(response.status_code, 200)
        # check that a success messaging is being displayed
        self.assertContains(response, '<li class="success">')
        # check that one form submission and one sheet submission got created
        self.assertEqual(old_form_submission_count + 1,
                         len(FormSubmission.objects.all()))
        self.assertEqual(old_sheet_submission_count + 1,
                         len(SheetSubmission.objects.all()))
        # find the submission in the database
        form_submission = FormSubmission.objects.latest('id')
        self.assertTrue(form_submission)
        sheet_submission = SheetSubmission.objects.latest('id')
        self.assertTrue(sheet_submission)
        self.assertEqual(sheet_submission.form_submission, form_submission)
        # make sure the person we logged in as got form initiator credits
        self.assertFalse(form_submission.initiator.isSFUPerson())
        self.assertEqual(form_submission.initiator.name(),
                         "%s %s" % (person["first_name"], person["last_name"]))
        self.assertEqual(form_submission.initiator.email(),
                         person["email_address"])
        # do the same for the sheet submission
        self.assertFalse(sheet_submission.filler.isSFUPerson())
        self.assertEqual(form_submission.initiator.name(),
                         "%s %s" % (person["first_name"], person["last_name"]))
        self.assertEqual(form_submission.initiator.email(),
                         person["email_address"])
        # verify the data
        field_submissions = FieldSubmission.objects.filter(
            sheet_submission=sheet_submission).order_by('field__order')
        self.assertEqual(len(fill_data), len(field_submissions))
        for field_submission in field_submissions:
            self.assertEqual(fill_data[field_submission.field.slug],
                             field_submission.data['info'])
        # check the sheet submission and form submission status
        self.assertEqual(sheet_submission.status, "DONE")
        # form submissions is pending until someone manually marks it done
        self.assertEqual(form_submission.status, "PEND")
Пример #34
0
    def test_grad_student_pages(self):
        """
        Check the pages for a grad student and make sure they all load
        """

        client = Client()
        client.login_user('dzhao')
        gs = self.__make_test_grad()
        lt = LetterTemplate(
            unit=gs.program.unit,
            label='Template',
            content="This is the\n\nletter for {{first_name}}.")
        lt.save()

        url = reverse('grad:get_letter_text',
                      kwargs={
                          'grad_slug': gs.slug,
                          'letter_template_id': lt.id
                      })
        content = client.get(url).content
        Letter(student=gs,
               template=lt,
               date=datetime.date.today(),
               content=content).save()

        url = reverse('grad:view', kwargs={'grad_slug': gs.slug})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # sections of the main gradstudent view that can be loaded
        for section in all_sections:
            url = reverse('grad:view', kwargs={'grad_slug': gs.slug})
            # check fragment fetch for AJAX
            try:
                response = client.get(url, {'section': section})
                self.assertEqual(response.status_code, 200)
            except:
                print "with section==" + repr(section)
                raise

            # check section in page
            try:
                response = basic_page_tests(
                    self, client, url + '?_escaped_fragment_=' + section)
                self.assertEqual(response.status_code, 200)
            except:
                print "with section==" + repr(section)
                raise

        # check all sections together
        url = url + '?_escaped_fragment_=' + ','.join(all_sections)
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # check management pages
        for view in [
                'financials', 'manage_general', 'manage_requirements',
                'manage_scholarships', 'manage_otherfunding',
                'manage_promises', 'manage_letters', 'manage_status',
                'manage_supervisors', 'manage_program',
                'manage_start_end_semesters', 'manage_financialcomments',
                'manage_defence', 'manage_progress', 'manage_documents'
        ]:
            try:
                url = reverse('grad:' + view, kwargs={'grad_slug': gs.slug})
                response = basic_page_tests(self, client, url)
                self.assertEqual(response.status_code, 200)
            except:
                print "with view==" + repr(view)
                raise

        for style in STYLES:
            url = reverse('grad:financials',
                          kwargs={
                              'grad_slug': gs.slug,
                              'style': style
                          })
            response = basic_page_tests(self, client, url)
            self.assertEqual(response.status_code, 200)

        url = reverse('grad:new_letter',
                      kwargs={
                          'grad_slug': gs.slug,
                          'letter_template_slug': lt.slug
                      })
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
Пример #35
0
    def test_import(self):
        self.client.login_user('ggbaker')
        url = reverse('marking.views.import_marks',
                      kwargs={
                          'course_slug': self.crs.slug,
                          'activity_slug': self.act.slug
                      })
        response = basic_page_tests(self, self.client, url)

        # post first file
        with open('marking/testfiles/marking_import1.json') as file:
            post_data = {'file': [file]}
            response = self.client.post(url, post_data)

        self.assertEquals(response.status_code, 302)

        # check that the parts are there
        marks = StudentActivityMark.objects.filter(activity=self.act)
        m = marks.get(numeric_grade__member__person__userid="0aaa9")
        self.assertEquals(m.numeric_grade.value, Decimal('3'))
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEquals(mc.value, Decimal('3'))
        self.assertEquals(mc.comment, "0aaa9 1")
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        self.assertEquals(mc.value, Decimal('0'))
        self.assertEquals(mc.comment, "")

        m = marks.get(numeric_grade__member__person__userid="0aaa8")
        self.assertAlmostEquals(float(m.numeric_grade.value), 3.6)
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEquals(mc.value, Decimal('4'))
        self.assertEquals(mc.comment, "0aaa8 1a")
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        self.assertEquals(mc.value, Decimal('0'))
        self.assertEquals(mc.comment, "")

        # post second file: should be combined with first.
        with open('marking/testfiles/marking_import2.json') as file:
            post_data = {'file': [file]}
            response = self.client.post(url, post_data)
        self.assertEquals(response.status_code, 302)

        marks = StudentActivityMark.objects.filter(activity=self.act)
        m = marks.filter(
            numeric_grade__member__person__userid="0aaa9").latest('created_at')
        self.assertAlmostEquals(float(m.numeric_grade.value), 3.2)
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEquals(mc.value, Decimal('3'))
        self.assertEquals(mc.comment, "0aaa9 1")
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        self.assertEquals(mc.value, Decimal('1'))
        self.assertEquals(mc.comment, "0aaa9 2")

        m = marks.filter(
            numeric_grade__member__person__userid="0aaa8").latest('created_at')
        self.assertAlmostEquals(float(m.numeric_grade.value), 6.3)
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-1")
        self.assertEquals(mc.value, Decimal('5'))
        self.assertEquals(mc.comment, "0aaa8 1b")
        mc = m.activitycomponentmark_set.get(activity_component__slug="part-2")
        self.assertEquals(mc.value, Decimal('2'))
        self.assertEquals(mc.comment, "0aaa8 2")

        # test file attachment encoded in JSON
        with open('marking/testfiles/marking_import3.json') as file:
            post_data = {'file': [file]}
            response = self.client.post(url, post_data)
        self.assertEquals(response.status_code, 302)

        marks = StudentActivityMark.objects.filter(
            activity=self.act, numeric_grade__member__person__userid="0aaa7")
        self.assertEqual(len(marks), 1)
        m = marks[0]
        self.assertEqual(m.file_mediatype, 'text/plain')
        m.file_attachment.open()
        data = m.file_attachment.read()
        self.assertEqual(data, 'Hello world!\n')
        self.assertEqual(m.attachment_filename(), 'hello.txt')
Пример #36
0
    def test_page_load(self):
        """
        Tests that various pages load
        """
        # as instructor...
        client = Client()
        client.login_user("ggbaker")

        url = reverse('offering:discussion:discussion_index',
                      kwargs={'course_slug': self.offering.slug})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('offering:discussion:create_topic',
                      kwargs={'course_slug': self.offering.slug})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('offering:discussion:view_topic',
                      kwargs={
                          'course_slug': self.offering.slug,
                          'topic_slug': self.topic.slug
                      })
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('offering:discussion:change_topic_status',
                      kwargs={
                          'course_slug': self.offering.slug,
                          'topic_slug': self.topic.slug
                      })
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # as the author of the topic/message
        client = Client()
        client.login_user(self.topic.author.person.userid)

        url = reverse('offering:discussion:edit_topic',
                      kwargs={
                          'course_slug': self.offering.slug,
                          'topic_slug': self.topic.slug
                      })
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        client = Client()
        client.login_user(self.message.author.person.userid)

        url = reverse('offering:discussion:edit_message',
                      kwargs={
                          'course_slug': self.offering.slug,
                          'topic_slug': self.topic.slug,
                          'message_slug': self.message.slug
                      })
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        url = reverse('offering:discussion:remove_message',
                      kwargs={
                          'course_slug': self.offering.slug,
                          'topic_slug': self.topic.slug,
                          'message_slug': self.message.slug
                      })
        response = client.post(url)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(
            DiscussionMessage.objects.get(id=self.message.id).status, 'HID')
Пример #37
0
    def test_add_common_problems(self):
        c = CourseOffering.objects.get(slug=self.c_slug)
        a = NumericActivity(offering = c, name = 'test_assignment_1', \
                            short_name = 'ta1', status = 'RLS', \
                            due_date = datetime.now(), max_grade = 100, position = 1)
        a.save()
        co1 = ActivityComponent(numeric_activity=a,
                                title='part1',
                                max_mark=50,
                                position=1)
        co2 = ActivityComponent(numeric_activity=a,
                                title='part2',
                                max_mark=50,
                                position=2)
        co1.save()
        co2.save()

        #add some common problems
        cp1 = CommonProblem(activity_component=co1, title='cp1', penalty="0")
        cp2 = CommonProblem(activity_component=co1,
                            title='cp2',
                            penalty="1.12")
        cp3 = CommonProblem(activity_component=co2,
                            title='cp3',
                            penalty="-2.3")

        cp1.save()
        cp2.save()
        cp3.save()

        self.client.login_user('ggbaker')

        response = basic_page_tests(
            self, self.client,
            reverse(manage_common_problems, args=(self.c_slug, a.slug)))

        forms = response.context['formset'].forms

        ins0 = forms[0].instance
        ins1 = forms[1].instance
        ins2 = forms[2].instance

        self.assertEquals(ins0.title, 'cp1')
        self.assertEquals(ins0.activity_component, co1)
        self.assertEquals(ins1.title, 'cp2')
        self.assertEquals(ins1.activity_component, co1)
        self.assertEquals(ins2.title, 'cp3')
        self.assertEquals(ins2.activity_component, co2)

        #test the marking page as well
        url = reverse(marking_student, args=(self.c_slug, a.slug, '0aaa0'))
        response = basic_page_tests(self, self.client, url)

        mark_components = response.context['component_data']
        com1 = mark_components[0]
        com2 = mark_components[1]

        self.assertEquals(com1['component'], co1)
        self.assertEquals(len(com1['common_problems']), 2)
        self.assertEquals(com2['component'], co2)
        self.assertEquals(len(com2['common_problems']), 1)
Пример #38
0
    def test_planning_admin_returns_200_ok(self):
        """
        Tests basic page permissions
        """
        raise SkipTest()
        client = Client()
        client.login_user("dixon")
        url = reverse('planning.views.admin_index')
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # Test create plan view
        url = reverse('planning.views.create_plan')
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # Test copy plan view
        url = reverse('planning.views.copy_plan')
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        return


        # Test update plan view
        url = reverse('planning.views.update_plan', kwargs={
            'semester': 1127,
            'plan_slug': 'test-plan'
        })
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # Test edit plan view
        url = reverse('planning.views.edit_plan', kwargs={
                'semester': 1127,
                'plan_slug': 'test-plan'
        })
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # Test assign instructor view
        url = reverse('planning.views.view_instructors', kwargs={
            'semester': 1127,
            'plan_slug': 'test-plan',
            'planned_offering_slug': 'CMPT-102-D100'
        })
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # Test edit planned offering view
        url = reverse('planning.views.edit_planned_offering', kwargs={
            'semester': 1127,
            'plan_slug': 'test-plan',
            'planned_offering_slug': 'CMPT-102-D100'
        })
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # Test manage courses view
        url = reverse('planning.views.manage_courses')
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # Test create courses view
        url = reverse('planning.views.create_course')
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # Test edit course view
        url = reverse('planning.views.edit_course', kwargs={'course_slug': 'CMPT-102'})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # Test semester teaching intentions view
        url = reverse('planning.views.view_intentions')
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # Test semester teaching intentions semester view
        url = reverse('planning.views.view_semester_intentions', kwargs={'semester': '1127'})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # Test create semester teaching intentions view
        url = reverse('planning.views.planner_create_intention')
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # Test semester teaching capabilities view
        url = reverse('planning.views.view_capabilities')
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)

        # Test create semester teaching capabilities view
        url = reverse('planning.views.planner_edit_capabilities', kwargs={'userid': 'ggbaker'})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
Пример #39
0
    def test_pages(self):
        "Test a bunch of page views"
        offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
        activity = Activity.objects.get(offering=offering, slug='rep')
        activity.due_date = datetime.datetime.now() + datetime.timedelta(
            days=1)  # make sure it's submittable
        activity.save()
        client = Client()

        # instructor views
        client.login_user("ggbaker")

        component1 = URL.Component(activity=activity,
                                   title='Sample URL 1',
                                   description='Please submit some URL.',
                                   check=False,
                                   prefix='')
        component1.save()
        component2 = URL.Component(activity=activity,
                                   title='Sample URL 2',
                                   description='Please submit some URL.',
                                   check=False,
                                   prefix='')
        component2.save()

        test_views(self, client, 'submission.views.',
                   ['show_components', 'add_component'], {
                       'course_slug': offering.slug,
                       'activity_slug': activity.slug
                   })

        url = reverse('submission.views.edit_single', kwargs={'course_slug': offering.slug, 'activity_slug': activity.slug}) \
                + '?id=' + unicode(component1.id)
        basic_page_tests(self, client, url)

        url = reverse('submission.views.add_component', kwargs={'course_slug': offering.slug, 'activity_slug': activity.slug}) \
                + '?type=url'
        basic_page_tests(self, client, url)

        # student views: with none, some, and all submitted
        client.login_user("0aaa0")

        # test various permutations of success to make sure everything returns okay
        name1 = '%i-url' % (component1.id)
        name2 = '%i-url' % (component2.id)
        submissions = [
            ({}, False),
            ({
                name1: '',
                name2: ''
            }, False),
            ({
                name1: '',
                name2: 'do i look like a url to you?'
            }, False),
            ({
                name1: 'http://www.sfu.ca/',
                name2: ''
            }, False),
            ({
                name1: 'http://www.cs.sfu.ca/',
                name2: 'http://example.com/'
            }, True),
            ({
                name1: 'http://www.sfu.ca/',
                name2: 'http://example.com/'
            }, True),
        ]
        for submitdata, redir in submissions:
            test_views(
                self, client, 'submission.views.',
                ['show_components', 'show_components_submission_history'], {
                    'course_slug': offering.slug,
                    'activity_slug': activity.slug
                })
            url = reverse('submission.views.show_components',
                          kwargs={
                              'course_slug': offering.slug,
                              'activity_slug': activity.slug
                          })
            response = client.post(url, submitdata)
            if redir:
                # success: we expect a redirect
                self.assertEqual(response.status_code, 302)
            else:
                # some problems: expect a page reporting that
                self.assertEqual(response.status_code, 200)
                validate_content(self, response.content, url)
Пример #40
0
    def test_grad_student_pages(self):
        """
        Check the pages for a grad student and make sure they all load
        """

        client = Client()
        test_auth(client, 'ggbaker')
        gs = self.__make_test_grad()
        lt = LetterTemplate(unit=gs.program.unit, label='Template', content="This is the\n\nletter for {{first_name}}.")
        lt.save()

        url = reverse('grad.views.get_letter_text', kwargs={'grad_slug': gs.slug, 'letter_template_id': lt.id})
        content = client.get(url).content
        Letter(student=gs, template=lt, date=datetime.date.today(), content=content).save()
        
        url = reverse('grad.views.view', kwargs={'grad_slug': gs.slug})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
        
        # sections of the main gradstudent view that can be loaded
        for section in all_sections:
            url = reverse('grad.views.view', kwargs={'grad_slug': gs.slug})
            # check fragment fetch for AJAX
            try:
                response = client.get(url, {'section': section})
                self.assertEqual(response.status_code, 200)
            except:
                print "with section==" + repr(section)
                raise

            # check section in page
            try:
                response = basic_page_tests(self, client, url + '?_escaped_fragment_=' + section)
                self.assertEqual(response.status_code, 200)
            except:
                print "with section==" + repr(section)
                raise
        
        # check all sections together
        url = url + '?_escaped_fragment_=' + ','.join(all_sections)
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
            
        # check management pages
        for view in ['financials', 
                     'manage_general',
                     'manage_requirements',
                     'manage_scholarships',
                     'manage_otherfunding',
                     'manage_promises',
                     'manage_letters',
                     'manage_status',
                     'manage_supervisors',
                     'manage_program',
                     'manage_start_end_semesters',
                     'manage_financialcomments',
                     'manage_defence',
                     'manage_progress',
                     'manage_documents']:
            try:
                url = reverse('grad.views.'+view, kwargs={'grad_slug': gs.slug})
                response = basic_page_tests(self, client, url)
                self.assertEqual(response.status_code, 200)
            except:
                print "with view==" + repr(view)
                raise

        for style in STYLES:
            url = reverse('grad.views.financials', kwargs={'grad_slug': gs.slug, 'style': style})
            response = basic_page_tests(self, client, url)
            self.assertEqual(response.status_code, 200)

        url = reverse('grad.views.new_letter', kwargs={'grad_slug': gs.slug, 'letter_template_slug': lt.slug})
        response = basic_page_tests(self, client, url)
        self.assertEqual(response.status_code, 200)
Пример #41
0
    def test_valid_simple_initial_form_submission_loggedin(self):
        logged_in_person = Person.objects.get(userid="ggbaker")
        self.client.login_user(logged_in_person.userid)

        old_form_submission_count = len(FormSubmission.objects.all())
        old_sheet_submission_count = len(SheetSubmission.objects.all())

        url = reverse('onlineforms:sheet_submission_initial',
                      kwargs={'form_slug': "comp-simple-form"})
        response = basic_page_tests(self, self.client, url)
        self.assertEqual(response.status_code, 200)
        # make sure it's not displaying the add-nonsfu form
        self.assertNotContains(
            response, '<input type="hidden" name="add-nonsfu" value="True"/>')
        # check for some important fields
        # note: the keys are the slugs of the field
        fill_data = {
            "favorite-color": "Black",
            "reason": "Because it's metal",
            "second-favorite-color": "Green"
        }
        # submit the form
        post_data = {
            '0': fill_data["favorite-color"],
            '1': fill_data["reason"],
            '2': fill_data["second-favorite-color"],
            'submit': "Yesplease",
        }
        response = self.client.post(url, post_data, follow=True)
        self.assertEqual(response.status_code, 200)
        # check that a success messaging is being displayed
        self.assertContains(response, '<li class="success">')
        # check that one form submission and one sheet submission got created
        self.assertEqual(old_form_submission_count + 1,
                         len(FormSubmission.objects.all()))
        self.assertEqual(old_sheet_submission_count + 1,
                         len(SheetSubmission.objects.all()))
        # find the submission in the database
        form_submission = FormSubmission.objects.latest('id')
        self.assertTrue(form_submission)
        sheet_submission = SheetSubmission.objects.latest('id')
        self.assertTrue(sheet_submission)
        self.assertEqual(sheet_submission.form_submission, form_submission)
        # make sure the person we logged in as got form initiator credits
        self.assertTrue(form_submission.initiator.isSFUPerson())
        self.assertEqual(form_submission.initiator.sfuFormFiller,
                         logged_in_person)
        # do the same for the sheet submission
        self.assertTrue(sheet_submission.filler.isSFUPerson())
        self.assertEqual(sheet_submission.filler.sfuFormFiller,
                         logged_in_person)
        # verify the data
        field_submissions = FieldSubmission.objects.filter(
            sheet_submission=sheet_submission).order_by('field__order')
        self.assertEqual(len(fill_data), len(field_submissions))
        for field_submission in field_submissions:
            self.assertEqual(fill_data[field_submission.field.slug],
                             field_submission.data['info'])
        # check the sheet submission and form submission status
        self.assertEqual(sheet_submission.status, "DONE")
        # form submissions is pending until someone manually marks it done
        self.assertEqual(form_submission.status, "PEND")