Пример #1
0
    def test_pages(self):
        # Presumably, our booking that starts more than 5 years ago is the one generated in the fixtures.  If there are
        # others that old, it should at least be the first.
        unit = Unit.objects.get(slug='cmpt')
        booking = BookingRecord.objects.filter(start_time__lte=self.long_start, location__unit=unit).first()
        location = booking.location
        roomtype = location.room_type
        client = Client()

        userid = Role.objects_fresh.filter(role='SPAC', unit=unit)[0].person.userid
        client.login_user(userid)
        test_views(self, client, 'space:', ['index', 'list_roomtypes', 'add_roomtype', 'manage_safety_items',
                                            'add_safety_item'], {})
        test_views(self, client, 'space:', ['view_location', 'edit_location', 'add_booking'],
                   {'location_slug': location.slug})
        test_views(self, client, 'space:', ['view_roomtype', 'edit_roomtype'], {'roomtype_slug': roomtype.slug})
        test_views(self, client, 'space:', ['view_booking', 'edit_booking', 'add_booking_attachment'],
                   {'booking_slug': booking.slug})

        # Now, we should be able to delete stuff properly.
        url = reverse('space:delete_booking', kwargs={'booking_id': booking.id})
        response = client.post(url, follow=True)
        self.assertEqual(response.status_code, 200)

        url = reverse('space:delete_location', kwargs={'location_id': location.id})
        response = client.post(url, follow=True)
        self.assertEqual(response.status_code, 200)

        url = reverse('space:delete_roomtype', kwargs={'roomtype_id': roomtype.id})
        response = client.post(url, follow=True)
        self.assertEqual(response.status_code, 200)
Пример #2
0
 def test_api(self):
     crs = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
     memb = Member.objects.get(offering=crs, person__userid="ggbaker")
     person = Person.objects.get(userid='ggbaker')
     p = Page(offering=crs, label="PageExists")
     p.save()
     v = PageVersion(page=p, title="Page Exists", wikitext="Original Contents", editor=memb, comment="original page")
     v.save()
     
     from dashboard.models import new_feed_token
     token = new_feed_token()
     
     updata = u"""{
         "userid": "ggbaker",
         "token": "%s",
         "pages": [
             {
                 "label": "Index",
                 "title": "The Coursé Page",
                 "can_read": "ALL",
                 "can_write": "INST",
                 "wikitext-base64": "VGhpcyBwYWdlIGlzIHNwZWNpYWwgaW4gKipzb21lKiogd2F5LiBcKHh+XjIrMSA9IFxmcmFjezF9ezJ9XCkuCgpHb29kYnllIHdvcmxkIQ==",
                 "comment": "page creation comment",
                 "use_math": true
             },
             {
                 "label": "PageExists",
                 "new_label": "PageChanged",
                 "title": "Another Page",
                 "can_read": "STUD",
                 "wikitext": "This is some **new** page\\n\\ncontent."
             }
         ]
     }""" % (token)
     
     # make a request with no auth token in place
     c = Client()
     url = reverse('pages.views.api_import', kwargs={'course_slug': crs.slug})
     response = c.post(url, data=updata.encode('utf8'), content_type="application/json")
     self.assertEquals(response.status_code, 403)
     
     # create token and try again
     person.config['pages-token'] = token
     person.save()
     response = c.post(url, data=updata.encode('utf8'), content_type="application/json")
     self.assertEquals(response.status_code, 200)
     
     # make sure the data arrived
     self.assertEquals(Page.objects.filter(offering=crs, label="PageExists").count(), 0)
     p = Page.objects.get(offering=crs, label="PageChanged")
     v = p.current_version()
     self.assertEqual(v.title, "Another Page")
     self.assertEqual(v.get_wikitext(), "This is some **new** page\n\ncontent.")
     
     p = Page.objects.get(offering=crs, label="Index")
     v = p.current_version()
     self.assertEqual(v.title, u"The Cours\u00e9 Page")
     self.assertEqual(v.get_wikitext(), 'This page is special in **some** way. \\(x~^2+1 = \\frac{1}{2}\\).\n\nGoodbye world!')
     self.assert_('math' in v.config)
     self.assertEqual(v.config['math'], True)
Пример #3
0
    def test_annual_teaching(self):
        """
        Test the annual teaching value entry field
        """
        person = Person.objects.get(userid='ggbaker')
        unit = Unit.objects.get(slug='cmpt')
        editor = Person.objects.get(userid='dzhao')
        etype = 'NORM_TEACH'
        event = CareerEvent.objects.filter(unit=unit, person=person, event_type=etype)[0]
        event.config['load'] = 2 # 2 courses/semester in database should be 6/year to the user
        event.get_handler().save(editor)

        c = Client()
        c.login_user(editor.userid)

        # make sure the form renders with value="6"
        url = reverse('faculty:change_event', kwargs={'userid': person.userid, 'event_slug': event.slug})
        resp = c.get(url)
        inputs = [l for l in resp.content.split(b'\n') if b'name="load"' in l]
        inputs_correct_value = [l for l in inputs if b'value="6"' in l]
        self.assertEqual(len(inputs_correct_value), 1)

        # POST a change and make sure the right value ends up in the DB
        data = {
            'start_date_0': '2000-09-01',
            'end_date_0': '',
            'unit': str(unit.id),
            'load': '5',
            'comments': '',
        }
        c.post(url, data)
        new_ce = CareerEvent.objects.filter(unit=unit, person=person, event_type=etype)[0]
        self.assertEqual(new_ce.config['load'], '5/3')
Пример #4
0
    def test_inaccessible_pages(self):
        # Presumably, our booking that starts more than 5 years ago is the one generated in the fixtures.  If there are
        # others that old, it should at least be the first.
        unit = Unit.objects.get(slug='cmpt')
        booking = BookingRecord.objects.filter(start_time__lte=self.long_start, location__unit=unit).first()
        location = booking.location
        roomtype = location.room_type
        client = Client()
        # First, without logging in:
        url = reverse('space:index')
        response = client.get(url)
        self.assertEqual(response.status_code, 302)

        # Now log in but without the correct role
        client.login_user('pba7')
        response = client.get(url)
        self.assertEqual(response.status_code, 403)

        # We darn well better not be able to delete anything without the proper role:
        url = reverse('space:delete_booking', kwargs={'booking_id': booking.id})
        response = client.post(url, follow=True)
        self.assertEqual(response.status_code, 403)

        url = reverse('space:delete_location', kwargs={'location_id': location.id})
        response = client.post(url, follow=True)
        self.assertEqual(response.status_code, 403)

        url = reverse('space:delete_roomtype', kwargs={'roomtype_id': roomtype.id})
        response = client.post(url, follow=True)
        self.assertEqual(response.status_code, 403)
Пример #5
0
 def test_api(self):
     crs = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
     memb = Member.objects.get(offering=crs, person__userid="ggbaker")
     person = Person.objects.get(userid='ggbaker')
     p = Page(offering=crs, label="PageExists")
     p.save()
     v = PageVersion(page=p, title="Page Exists", wikitext="Original Contents", editor=memb, comment="original page")
     v.save()
     
     from dashboard.models import new_feed_token
     token = new_feed_token()
     
     updata = u"""{
         "userid": "ggbaker",
         "token": "%s",
         "pages": [
             {
                 "label": "Index",
                 "title": "The Coursé Page",
                 "can_read": "ALL",
                 "can_write": "INST",
                 "wikitext-base64": "VGhpcyBwYWdlIGlzIHNwZWNpYWwgaW4gKipzb21lKiogd2F5LiBcKHh+XjIrMSA9IFxmcmFjezF9ezJ9XCkuCgpHb29kYnllIHdvcmxkIQ==",
                 "comment": "page creation comment",
                 "use_math": true
             },
             {
                 "label": "PageExists",
                 "new_label": "PageChanged",
                 "title": "Another Page",
                 "can_read": "STUD",
                 "wikitext": "This is some **new** page\\n\\ncontent."
             }
         ]
     }""" % (token)
     
     # make a request with no auth token in place
     c = Client()
     url = reverse('pages.views.api_import', kwargs={'course_slug': crs.slug})
     response = c.post(url, data=updata.encode('utf8'), content_type="application/json")
     self.assertEquals(response.status_code, 403)
     
     # create token and try again
     person.config['pages-token'] = token
     person.save()
     response = c.post(url, data=updata.encode('utf8'), content_type="application/json")
     self.assertEquals(response.status_code, 200)
     
     # make sure the data arrived
     self.assertEquals(Page.objects.filter(offering=crs, label="PageExists").count(), 0)
     p = Page.objects.get(offering=crs, label="PageChanged")
     v = p.current_version()
     self.assertEqual(v.title, "Another Page")
     self.assertEqual(v.get_wikitext(), "This is some **new** page\n\ncontent.")
     
     p = Page.objects.get(offering=crs, label="Index")
     v = p.current_version()
     self.assertEqual(v.title, u"The Cours\u00e9 Page")
     self.assertEqual(v.get_wikitext(), 'This page is special in **some** way. \\(x~^2+1 = \\frac{1}{2}\\).\n\nGoodbye world!')
     self.assert_('math' in v.config)
     self.assertEqual(v.config['math'], True)
Пример #6
0
class TestImportViews(TestCase):
    fixtures = ['basedata', 'coredata', 'grades']

    def setUp(self):
        self.c_slug = TEST_COURSE_SLUG
        self.client = Client()
        self.c = CourseOffering.objects.get(slug=self.c_slug)
        self.a1 = NumericActivity(offering=self.c,
                                  name='test_assignment_1',
                                  short_name='ta1',
                                  status='RLS',
                                  due_date=datetime.now(),
                                  max_grade=100,
                                  position=0)
        self.a1.save()

    def check_student_db_grade(self, grade, s, g):
        self.assertEqual(grade.member, s)
        self.assertEqual(grade.value, Decimal(g))
        self.assertEqual(grade.flag, 'GRAD')

    def test_import_view(self):
        self.client.login_user('ggbaker')

        # Import the file, check that resulting HTML has correct entries in fields for two affected students
        url = reverse('offering:mark_all_students',
                      kwargs={
                          'course_slug': self.c_slug,
                          'activity_slug': self.a1.slug
                      })
        with open('marking/testfiles/newformat_noprob_userid.csv') as file:
            post_data = {'import-file-file': [file]}
            response = self.client.post(url + "?import=true",
                                        post_data,
                                        follow=True)
        self.assertEqual(response.status_code, 200)
        stud1 = Member.objects.get(person=Person.objects.get(userid='0aaa0'),
                                   offering=self.c)
        stud2 = Member.objects.get(person=Person.objects.get(userid='0aaa1'),
                                   offering=self.c)
        STUD1_GRADE = '88'
        STUD2_GRADE = '15'
        self.assertContains(response,
                            b'value="%b"' % (STUD1_GRADE.encode('utf8'), ))
        self.assertContains(response,
                            b'value="%b"' % (STUD2_GRADE.encode('utf8'), ))

        # Submit the grades, check that they were added to DB
        post_data = {'0aaa0-value': STUD1_GRADE, '0aaa1-value': STUD2_GRADE}
        response = self.client.post(url, post_data, follow=True)
        self.assertEqual(response.status_code, 200)
        num_grades = NumericGrade.objects.filter(
            activity=self.a1).order_by('member__person__userid')
        self.assertEqual(len(num_grades), 2)
        self.check_student_db_grade(num_grades[0], stud1, STUD1_GRADE)
        self.check_student_db_grade(num_grades[1], stud2, STUD2_GRADE)
Пример #7
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, expiry=TEST_ROLE_EXPIRY)
        r.save()
        self.assertEqual(str(r), "Lname, Fname (System Administrator, UNIV)")

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

        url = reverse('sysadmin:role_list')
        response = basic_page_tests(self, client, url)
        self.assertContains(
            response, 'Lname, Fname</a></td>\n  <td>System Administrator</td>')

        # add a new role with the front end
        oldcount = Role.objects.filter(role='FAC').count()
        url = reverse('sysadmin:new_role')
        response = basic_page_tests(self, client, url)

        response = client.post(url, {
            'person': '33333333',
            'role': 'FAC',
            'unit': 2
        })
        self.assertEqual(response.status_code, 200)
        validate_content(self, response.content, url)
        self.assertTrue(
            b"could not import DB2 module" in response.content
            or b"could not connect to reporting database" in response.content
            or b"Could not find this emplid." in response.content or
            b"Reporting database access has been disabled" in response.content
            or b"Could not communicate with reporting database"
            in response.content)

        response = client.post(
            url, {
                'person': p1.emplid,
                'role': 'FAC',
                'unit': unit.id,
                'expiry': str(TEST_ROLE_EXPIRY)
            })
        self.assertEqual(response.status_code, 302)

        # make sure the role is now there
        self.assertEqual(Role.objects.filter(role='FAC').count(), oldcount + 1)
Пример #8
0
 def DISABLED_test_rest_notes_problem_already_exists(self):
     raise SkipTest()
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_problem_already_exists.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     before_count = len(Problem.objects.filter(person__emplid=200000172))
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     after_count = len(Problem.objects.filter(person__emplid=200000172))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(before_count, after_count, "Shouldn't duplicate problem")
Пример #9
0
class TestImportViewsLet(TestCase):
    fixtures = ['test_data']

    def setUp(self):
        self.c_slug = TEST_COURSE_SLUG
        self.client = Client()
        self.c = CourseOffering.objects.get(slug=self.c_slug)
        self.a1 = LetterActivity(offering=self.c,
                                 name='test_assignment_1_let',
                                 short_name='tal1',
                                 status='RLS',
                                 due_date=datetime.now(),
                                 position=0)
        self.a1.save()

    def check_student_db_grade(self, grade, s, g):
        self.assertEquals(grade.member, s)
        self.assertEquals(grade.letter_grade, g)
        self.assertEquals(grade.flag, 'GRAD')

    def test_import_view_let(self):
        self.client.login_user('ggbaker')

        # Import the file, check that resulting HTML has correct entries in fields for two affected students
        url = reverse('marking.views.mark_all_students',
                      kwargs={
                          'course_slug': self.c_slug,
                          'activity_slug': self.a1.slug
                      })
        with open('marking/testfiles/newformat_noprob_userid_let.csv') as file:
            post_data = {'import-file-file': [file]}
            response = self.client.post(url + "?import=true",
                                        post_data,
                                        follow=True)
        self.assertEquals(response.status_code, 200)
        stud1 = Member.objects.get(person=Person.objects.get(userid='0aaa0'),
                                   offering=self.c)
        stud2 = Member.objects.get(person=Person.objects.get(userid='0aaa1'),
                                   offering=self.c)
        STUD1_GRADE = 'A'
        STUD2_GRADE = 'C-'
        self.assertTrue(re.search(STUD1_GRADE, response.content))
        self.assertTrue(re.search(STUD2_GRADE, response.content))

        # Submit the grades, check that they were added to DB
        post_data = {'0aaa0-value': STUD1_GRADE, '0aaa1-value': STUD2_GRADE}
        response = self.client.post(url, post_data, follow=True)
        self.assertEquals(response.status_code, 200)
        let_grades = LetterGrade.objects.filter(
            activity=self.a1).order_by('member__person__userid')
        self.assertEquals(len(let_grades), 2)
        self.check_student_db_grade(let_grades[0], stud1, STUD1_GRADE)
        self.check_student_db_grade(let_grades[1], stud2, STUD2_GRADE)
Пример #10
0
 def test_new_nonstudent_post_failure(self):
     client = Client()
     client.login_user("dzhao")
     response = client.post(reverse('advising:new_nonstudent'), {'first_name': 'test123'})
     self.assertEqual(response.status_code, 200, "Should be brought back to form")
     q = NonStudent.objects.filter(first_name='test123')
     self.assertEqual(len(q), 0, "Nonstudent should not have been created")
Пример #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('config:privacy')

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

        # but role page should redirect to agreement
        url = reverse('advising: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_new_nonstudent_post_failure(self):
     client = Client()
     client.login_user("dzhao")
     response = client.post(reverse('advisornotes.views.new_nonstudent'), {'first_name': 'test123'})
     self.assertEqual(response.status_code, 200, "Should be brought back to form")
     q = NonStudent.objects.filter(first_name='test123')
     self.assertEqual(len(q), 0, "Nonstudent should not have been created")
Пример #13
0
    def DISABLED_test_rest_notes_problems_successful(self):
        raise SkipTest()
        client = Client()
        f = open('advisornotes/testfiles/rest_notes_problems_successful.json')
        data = f.read()
        f.close()

        # check that a duplicate isn't saved
        p = Problem(person=Person.objects.get(emplid=200000172),
                    code='Deceased',
                    status='RESO',
                    resolved_at=datetime.datetime.now(),
                    resolution_lasts=10,
                    resolved_until=datetime.datetime.now() +
                    datetime.timedelta(days=10),
                    unit=Unit.objects.get(slug='cmpt'))
        p.save()

        before_count = len(Problem.objects.filter(person__emplid=200000172))
        response = client.post(reverse('advisornotes.views.rest_notes'), data,
                               'application/json')
        after_count = len(Problem.objects.filter(person__emplid=200000172))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(before_count + 1, after_count,
                         "Only one problem should have been created")
Пример #14
0
    def test_pages(self):
        client = Client()
        today = datetime.date.today()
        long_start = today + datetime.timedelta(days=5 * 365)
        # Our test even is probably the only one that starts at least 5 years from whatever day it is when we run this
        event = OutreachEvent.objects.current([
            Unit.objects.get(slug='cmpt')
        ]).filter(start_date__gt=long_start).first()
        registration = OutreachEventRegistration.objects.filter(
            event=event).first()
        # Anyone should be able to register
        test_views(self, client, 'outreach:', ['register', 'register_success'],
                   {'event_slug': event.slug})

        # Log in as someone with the correct role.
        userid = Role.objects_fresh.filter(
            role='OUTR', unit=Unit.objects.get(slug='cmpt'))[0].person.userid
        client.login_user(userid)
        test_views(self, client, 'outreach:',
                   ['outreach_index', 'view_all_registrations'], {})
        test_views(self, client, 'outreach:',
                   ['edit_event', 'view_event', 'view_event_registrations'],
                   {'event_slug': event.slug})
        test_views(self, client, 'outreach:',
                   ['view_registration', 'edit_registration'],
                   {'registration_id': registration.id})

        url = reverse('outreach:toggle_registration_attendance',
                      kwargs={'registration_id': registration.id})
        response = client.post(url, follow=True)
        self.assertEqual(response.status_code, 200)
Пример #15
0
 def DISABLED_test_rest_notes_problem_already_exists(self):
     raise SkipTest()
     client = Client()
     f = open(
         'advisornotes/testfiles/rest_notes_problem_already_exists.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json')
     before_count = len(Problem.objects.filter(person__emplid=200000172))
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json')
     after_count = len(Problem.objects.filter(person__emplid=200000172))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(before_count, after_count,
                      "Shouldn't duplicate problem")
Пример #16
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)
Пример #17
0
 def test_rest_notes_emplid_doesnt_exist(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_emplid_doesnt_exist.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Emplid '321' doesn't exist")
Пример #18
0
 def test_rest_notes_invalid_JSON(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_bad_json.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.content, 'Bad JSON in request body')
Пример #19
0
 def test_rest_notes_invalid_UTF8(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_bad_utf8.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.content, 'Bad UTF-8 encoded text')
Пример #20
0
 def test_rest_notes_not_JSON(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_valid_file.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'text/plain')
     self.assertEqual(response.status_code, 415)
     self.assertEqual(response.content, 'Contents must be JSON (application/json)')
Пример #21
0
 def test_rest_notes_missing_credential(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_missing_credential.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "The key 'secret' is not present. ")
Пример #22
0
 def test_rest_notes_empty_list(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_empty.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "No advising notes present")
Пример #23
0
 def test_rest_notes_bad_base64(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_bad_base64.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Invalid base64 data for note file attachment")
Пример #24
0
 def test_rest_notes_emplid_text_missing(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_emplid_missing.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Emplid or text not present in note")
Пример #25
0
 def test_rest_notes_file_data_not_string(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_file_data_not_string.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Note file data must be a string")
Пример #26
0
 def test_new_nonstudent_post_success(self):
     client = Client()
     client.login_user("dzhao")
     response = client.post(reverse('advisornotes.views.new_nonstudent'), {'first_name': 'test123', 'last_name': 'test_new_nonstudent_post', 'start_year': 2020})
     self.assertEqual(response.status_code, 302, 'Should have been redirected')
     q = NonStudent.objects.filter(first_name='test123')
     self.assertEqual(len(q), 1, "There should only be one result")
     self.assertEqual(q[0].last_name, 'test_new_nonstudent_post')
Пример #27
0
 def test_rest_notes_emplid_not_int(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_emplid_not_int.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Note emplid must be an integer")
Пример #28
0
 def test_new_nonstudent_post_success(self):
     client = Client()
     client.login_user("dzhao")
     response = client.post(reverse('advising:new_nonstudent'), {'first_name': 'test123', 'last_name': 'test_new_nonstudent_post', 'start_year': 2020})
     self.assertEqual(response.status_code, 302, 'Should have been redirected')
     q = NonStudent.objects.filter(first_name='test123')
     self.assertEqual(len(q), 1, "There should only be one result")
     self.assertEqual(q[0].last_name, 'test_new_nonstudent_post')
Пример #29
0
    def test_form_submission(self):
        """
        Check that submitting the page editing form results in the objects we expect.
        """
        crs = self._sample_setup()
        c = Client()
        c.login_user('ggbaker')

        pg = Page.objects.get(offering=crs, label="Index")

        url = reverse('offering:pages:edit_page',
                      kwargs={
                          'course_slug': crs.slug,
                          'page_label': pg.label
                      })
        form_data = {
            'offering': crs.id,
            'label': 'NewIndex',
            'can_read': 'ALL',
            'can_write': 'INST',
            'releasedate': '',
            'title': 'New Index',
            'markup_content_0': 'Unsafe <script>HTML</script>',
            'markup_content_1': 'html',
            'markup_content_2': 'on',
            'comment': 'the comment',
        }

        # bad submission: redisplay form
        resp = c.post(url, {})
        self.assertEqual(resp.status_code, 200)

        # good submission: save and redirect
        resp = c.post(url, form_data)
        self.assertEqual(resp.status_code, 302)

        pg = Page.objects.get(offering=crs, label="NewIndex")
        vr = pg.current_version()

        self.assertEqual(pg.can_write, 'INST')
        self.assertEqual(vr.title, 'New Index')
        self.assertEqual(vr.wikitext,
                         'Unsafe HTML')  # should be cleaned on the way in
        self.assertEqual(vr.config['markup'], 'html')
        self.assertEqual(vr.config['math'], True)
Пример #30
0
 def test_rest_notes_invalid_UTF8(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_bad_utf8.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json')
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.content, 'Bad UTF-8 encoded text')
Пример #31
0
 def test_rest_notes_missing_credential(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_missing_credential.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "The key 'secret' is not present. ")
Пример #32
0
 def test_rest_notes_invalid_JSON(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_bad_json.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json')
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.content, 'Bad JSON in request body')
Пример #33
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)

        url = reverse('offering:discussion:download', kwargs={'course_slug': self.offering.slug})
        response = basic_page_tests(self, client, url, check_valid=False)
        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')

        #  Make sure students can't download the json dump of discussions:
        member = Member.objects.filter(offering=self.offering, role='STUD').exclude(person__userid__isnull=True).first()
        client = Client()
        client.login_user(member.person.userid)
        url = reverse('offering:discussion:download', kwargs={'course_slug': self.offering.slug})
        response = client.get(url)
        self.assertEqual(response.status_code, 403)
Пример #34
0
 def DISABLED_test_rest_notes_problem_comments_not_string(self):
     raise SkipTest()
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_problem_comments_not_string.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Problem comments must be a string")
Пример #35
0
 def DISABLED_test_rest_notes_problem_fields_missing(self):
     raise SkipTest()
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_problem_fields_missing.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Necessary fields not present in problem")
Пример #36
0
 def DISABLED_test_rest_notes_problem_description_too_long(self):
     raise SkipTest()
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_problem_description_too_long.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Problem code & description must be less than or equal to 30 & 50 characters respectively")
Пример #37
0
 def test_rest_notes_empty_list(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_empty.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "No advising notes present")
Пример #38
0
 def DISABLED_test_rest_notes_problem_unit_invalid(self):
     raise SkipTest()
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_problem_unit_invalid.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Unit 'NOTREAL' does not exist")
Пример #39
0
 def DISABLED_test_rest_notes_problems_empty(self):
     raise SkipTest()
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_problems_empty.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "No problems present")
Пример #40
0
 def test_rest_notes_file_data_not_string(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_file_data_not_string.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Note file data must be a string")
Пример #41
0
 def test_rest_notes_invalid_token(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_invalid_token.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json; charset=utf-8')
     self.assertEqual(response.status_code, 422)
     from coredata.validate_rest import _token_not_found
     self.assertEqual(response.content, _token_not_found)
Пример #42
0
 def test_rest_notes_emplid_doesnt_exist(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_emplid_doesnt_exist.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Emplid '321' doesn't exist")
Пример #43
0
 def test_rest_notes_emplid_not_int(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_emplid_not_int.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Note emplid must be an integer")
Пример #44
0
 def DISABLED_test_rest_notes_problem_resolution_zero(self):
     raise SkipTest()
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_problem_resolution_zero.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Resolution_lasts must be greater than zero")
Пример #45
0
 def DISABLED_test_rest_notes_problems_empty(self):
     raise SkipTest()
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_problems_empty.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "No problems present")
Пример #46
0
 def test_rest_notes_bad_base64(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_bad_base64.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content,
                      "Invalid base64 data for note file attachment")
Пример #47
0
 def test_rest_notes_emplid_text_missing(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_emplid_missing.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content,
                      "Emplid or text not present in note")
Пример #48
0
 def test_rest_notes_not_JSON(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_valid_file.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'text/plain')
     self.assertEqual(response.status_code, 415)
     self.assertEqual(response.content,
                      'Contents must be JSON (application/json)')
Пример #49
0
 def DISABLED_test_rest_notes_problem_unit_invalid(self):
     raise SkipTest()
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_problem_unit_invalid.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Unit 'NOTREAL' does not exist")
Пример #50
0
 def test_rest_notes_no_generated_token(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_valid.json')
     data = f.read()
     f.close()
     UserConfig.objects.get(user__userid='dzhao', key='advisor-token').delete()
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     self.assertEqual(response.status_code, 422)
     from coredata.validate_rest import _token_not_found
     self.assertEqual(response.content, _token_not_found)
Пример #51
0
 def test_rest_notes_invalid_token(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_invalid_token.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json; charset=utf-8')
     self.assertEqual(response.status_code, 422)
     from coredata.validate_rest import _token_not_found
     self.assertEqual(response.content, _token_not_found)
Пример #52
0
 def test_rest_notes_file_success(self):
     client = Client()
     f = open('advisornotes/testfiles/rest_notes_valid_file.json')
     data = f.read()
     f.close()
     before_count = len(AdvisorNote.objects.filter(student__emplid=200000341))
     response = client.post(reverse('advisornotes.views.rest_notes'), data, 'application/json')
     after_count = len(AdvisorNote.objects.filter(student__emplid=200000341))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(before_count + 1, after_count, "Should be one more advisor note for student")
Пример #53
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)
Пример #54
0
    def test_annual_teaching(self):
        """
        Test the annual teaching value entry field
        """
        person = Person.objects.get(userid='ggbaker')
        unit = Unit.objects.get(slug='cmpt')
        editor = Person.objects.get(userid='dzhao')
        etype = 'NORM_TEACH'
        event = CareerEvent.objects.filter(unit=unit,
                                           person=person,
                                           event_type=etype)[0]
        event.config[
            'load'] = 2  # 2 courses/semester in database should be 6/year to the user
        event.get_handler().save(editor)

        c = Client()
        c.login_user(editor.userid)

        # make sure the form renders with value="6"
        url = reverse('faculty:change_event',
                      kwargs={
                          'userid': person.userid,
                          'event_slug': event.slug
                      })
        resp = c.get(url)
        inputs = [l for l in resp.content.split(b'\n') if b'name="load"' in l]
        inputs_correct_value = [l for l in inputs if b'value="6"' in l]
        self.assertEqual(len(inputs_correct_value), 1)

        # POST a change and make sure the right value ends up in the DB
        data = {
            'start_date_0': '2000-09-01',
            'end_date_0': '',
            'unit': str(unit.id),
            'load': '5',
            'comments': '',
        }
        c.post(url, data)
        new_ce = CareerEvent.objects.filter(unit=unit,
                                            person=person,
                                            event_type=etype)[0]
        self.assertEqual(new_ce.config['load'], '5/3')
Пример #55
0
class TestImportViews(TestCase):
    fixtures = ['test_data']

    def setUp(self):
        self.c_slug = TEST_COURSE_SLUG
        self.client = Client()
        self.c = CourseOffering.objects.get(slug = self.c_slug)
        self.a1 = NumericActivity(offering = self.c, name = 'test_assignment_1', 
                            short_name = 'ta1', status = 'RLS', 
                            due_date = datetime.now(), max_grade = 100,
                            position = 0)
        self.a1.save()

    def check_student_db_grade(self, grade, s, g):
        self.assertEquals(grade.member, s)
        self.assertEquals(grade.value, Decimal(g))
        self.assertEquals(grade.flag, 'GRAD')

    def test_import_view(self):
        self.client.login_user('ggbaker')

        # Import the file, check that resulting HTML has correct entries in fields for two affected students
        url = reverse('marking.views.mark_all_students', kwargs={'course_slug':self.c_slug, 'activity_slug':self.a1.slug})
        with open('marking/testfiles/newformat_noprob_userid.csv') as file:
            post_data = {'import-file-file':[file]}
            response = self.client.post(url+"?import=true", post_data, follow=True)
        self.assertEquals(response.status_code, 200)
        stud1 = Member.objects.get(person = Person.objects.get(userid = '0aaa0'), offering = self.c)
        stud2 = Member.objects.get(person = Person.objects.get(userid = '0aaa1'), offering = self.c)
        STUD1_GRADE = '88'
        STUD2_GRADE = '15'
        self.assertTrue(re.search(STUD1_GRADE, response.content))
        self.assertTrue(re.search(STUD2_GRADE, response.content))

        # Submit the grades, check that they were added to DB
	post_data={'0aaa0-value':STUD1_GRADE, '0aaa1-value':STUD2_GRADE}
        response = self.client.post(url, post_data, follow=True)
        self.assertEquals(response.status_code, 200)
        num_grades = NumericGrade.objects.filter(activity = self.a1).order_by('member__person__userid')
        self.assertEquals(len(num_grades), 2)
        self.check_student_db_grade(num_grades[0], stud1, STUD1_GRADE)
        self.check_student_db_grade(num_grades[1], stud2, STUD2_GRADE)
Пример #56
0
class TestImportViewsLet(TestCase):
    fixtures = ['basedata', 'coredata', 'grades']

    def setUp(self):
        self.c_slug = TEST_COURSE_SLUG
        self.client = Client()
        self.c = CourseOffering.objects.get(slug = self.c_slug)
        self.a1 = LetterActivity(offering = self.c, name = 'test_assignment_1_let', 
                            short_name = 'tal1', status = 'RLS', 
                            due_date = datetime.now(),
                            position = 0)
        self.a1.save()

    def check_student_db_grade(self, grade, s, g):
        self.assertEqual(grade.member, s)
        self.assertEqual(grade.letter_grade, g)
        self.assertEqual(grade.flag, 'GRAD')

    def test_import_view_let(self):
        self.client.login_user('ggbaker')

        # Import the file, check that resulting HTML has correct entries in fields for two affected students
        url = reverse('offering:mark_all_students', kwargs={'course_slug':self.c_slug, 'activity_slug':self.a1.slug})
        with open('marking/testfiles/newformat_noprob_userid_let.csv') as file:
            post_data = {'import-file-file':[file]}
            response = self.client.post(url+"?import=true", post_data, follow=True)
        self.assertEqual(response.status_code, 200)
        stud1 = Member.objects.get(person = Person.objects.get(userid = '0aaa0'), offering = self.c)
        stud2 = Member.objects.get(person = Person.objects.get(userid = '0aaa1'), offering = self.c)
        STUD1_GRADE = 'A'
        STUD2_GRADE = 'C-'
        self.assertContains(response, b'value="%b"' % (STUD1_GRADE.encode('utf8'),))
        self.assertContains(response, b'value="%b"' % (STUD2_GRADE.encode('utf8'),))

        # Submit the grades, check that they were added to DB
        post_data={'0aaa0-value':STUD1_GRADE, '0aaa1-value':STUD2_GRADE}
        response = self.client.post(url, post_data, follow=True)
        self.assertEqual(response.status_code, 200)
        let_grades = LetterGrade.objects.filter(activity = self.a1).order_by('member__person__userid')
        self.assertEqual(len(let_grades), 2)
        self.check_student_db_grade(let_grades[0], stud1, STUD1_GRADE)
        self.check_student_db_grade(let_grades[1], stud2, STUD2_GRADE)
Пример #57
0
 def DISABLED_test_rest_notes_problem_resolution_zero(self):
     raise SkipTest()
     client = Client()
     f = open(
         'advisornotes/testfiles/rest_notes_problem_resolution_zero.json')
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content,
                      "Resolution_lasts must be greater than zero")
Пример #58
0
 def DISABLED_test_rest_notes_problem_comments_not_string(self):
     raise SkipTest()
     client = Client()
     f = open(
         'advisornotes/testfiles/rest_notes_problem_comments_not_string.json'
     )
     data = f.read()
     f.close()
     response = client.post(reverse('advisornotes.views.rest_notes'), data,
                            'application/json')
     self.assertEqual(response.status_code, 422)
     self.assertEqual(response.content, "Problem comments must be a string")