示例#1
0
文件: testing.py 项目: tjkind/coursys
def create_test_offering():
    """
    Create a CourseOffering (and related stuff) that can be used in tests with no fixtures
    """
    s = create_fake_semester('1144')
    u = Unit(label='BABL', name="Department of Babbling")
    u.save()
    o = CourseOffering(subject='BABL',
                       number='123',
                       section='F104',
                       semester=s,
                       component='LEC',
                       owner=u,
                       title='Babbling for Baferad Ferzizzles',
                       enrl_cap=100,
                       enrl_tot=5,
                       wait_tot=0)
    o.save()

    i = Person(first_name='Insley',
               last_name='Instructorberg',
               emplid=20000009,
               userid='instr')
    i.save()
    s = Person(first_name='Stanley',
               last_name='Studentson',
               emplid=20000010,
               userid='student')
    s.save()

    Member(offering=o, person=i, role='INST').save()
    Member(offering=o, person=s, role='STUD').save()

    return o
示例#2
0
文件: tests.py 项目: avacariu/coursys
def create_offering():
    s = create_semester()
    c = CourseOffering(subject="CMPT", number="120", section="D100", semester=s, component="LEC",
                graded=True, crse_id=11111, class_nbr=22222, campus='BRNBY', title="Computer Stuff",
                enrl_cap=100, enrl_tot=99, wait_tot=2)
    c.save()
    return s, c
示例#3
0
    def test_bitfield(self):
        s, c1 = create_offering()
        c2 = CourseOffering(subject="CMPT",
                            number="121",
                            section="D100",
                            semester=s,
                            component="LEC",
                            graded=True,
                            crse_id=11112,
                            class_nbr=22223,
                            campus='BRNBY',
                            title="Other Stuff",
                            enrl_cap=100,
                            enrl_tot=99,
                            wait_tot=2)
        c2.save()

        c1.flags = CourseOffering.flags.quant
        c1.save()
        self.assertEqual(
            self._flag_filter(
                [CourseOffering.flags.quant, CourseOffering.flags.bhum]),
            set())
        self.assertEqual(self._flag_filter([CourseOffering.flags.quant]), {c1})
        self.assertEqual(self._flag_filter([~CourseOffering.flags.quant]),
                         {c2})
        self.assertEqual(self._flag_filter([~CourseOffering.flags.bhum]),
                         {c1, c2})

        c1.flags = 0
        c1.save()
        self.assertEqual(self._flag_filter([CourseOffering.flags.quant]),
                         set())
        self.assertEqual(self._flag_filter([~CourseOffering.flags.quant]),
                         {c1, c2})
示例#4
0
文件: tests.py 项目: avacariu/coursys
    def test_course_offering(self):
        """
        Create and test a course offering
        """
        s, c = create_offering()
        
        # should have a get_absolute_url
        url = c.get_absolute_url()
        self.assertEquals(url, str(url))
        self.assertEquals(url[0], '/')
        self.assertEquals(str(c), "CMPT 120 D100 (Fall 2007)")
        self.assertEquals(c.name(), "CMPT 120 D1")

        # check uniqueness criteria
        c2 = CourseOffering(subject="CMPT", number="120", section="D100", semester=s, component="LAB",
                graded=True, crse_id=11112, class_nbr=22223, campus='SURRY',
                enrl_cap=101, enrl_tot=100, wait_tot=3)
        # south doesn't seem to create the constraints in SQLite for testing
        #self.assertRaises(IntegrityError, c2.save)

        c2 = CourseOffering(subject="CMPT", number="121", section="D100", semester=s, component="LAB",
                graded=True, crse_id=11111, class_nbr=22223, campus='SURRY',
                enrl_cap=101, enrl_tot=100, wait_tot=3)
        # south doesn't seem to create the constraints in SQLite for testing
        #self.assertRaises(IntegrityError, c2.save)

        c2 = CourseOffering(subject="MACM", number="121", section="D102", semester=s, component="LAB",
                graded=True, crse_id=11112, class_nbr=22222, campus='SURRY',
                enrl_cap=101, enrl_tot=100, wait_tot=3)
        # south doesn't seem to create the constraints in SQLite for testing
        #self.assertRaises(IntegrityError, c2.save)

        # test some course memberships
        p1 = Person(emplid=210012345, userid="test1",
                last_name="Lname", first_name="Fname", pref_first_name="Fn", middle_name="M")
        p1.save()
        m = Member(person=p1, offering=c, role="INST", credits=0, career="NONS", added_reason="AUTO")
        m.save()
        
        self.assertEqual( str(list(c.instructors())), "[<Person: Lname, Fname>]")
        self.assertEqual( str(list(c.tas())), "[]")
        self.assertEqual( c.student_count(), 0)

        m.role = "TA"
        m.save()
        self.assertEqual( str(list(c.instructors())), "[]")
        self.assertEqual( str(list(c.tas())), "[<Person: Lname, Fname>]")
        self.assertEqual( c.student_count(), 0)

        m.role = "STUD"
        m.save()
        self.assertEqual( str(list(c.instructors())), "[]")
        self.assertEqual( str(list(c.tas())), "[]")
        self.assertEqual( c.student_count(), 1)
        
        self.assertEqual( str(m), "test1 (210012345) in CMPT 120 D100 (Fall 2007)")
示例#5
0
    def setUp(self):
        p1 = Person(emplid=210012345,
                    userid="test1",
                    last_name="Lname",
                    first_name="Fname",
                    pref_first_name="Fn",
                    middle_name="M")
        p1.save()

        s = Semester(name="1077",
                     start=date(2007, 9, 4),
                     end=date(2007, 12, 3))
        s.save()

        unit = Unit.objects.get(label="CMPT")
        self.co1 = CourseOffering(owner=unit,
                                  subject="CMPT",
                                  number="120",
                                  section="D100",
                                  semester=s,
                                  component="LEC",
                                  graded=True,
                                  crse_id=11111,
                                  class_nbr=22222,
                                  campus='BRNBY',
                                  title="Computer Stuff",
                                  enrl_cap=100,
                                  enrl_tot=99,
                                  wait_tot=2)

        self.co2 = CourseOffering(owner=unit,
                                  subject="CMPT",
                                  number="165",
                                  section="D100",
                                  semester=s,
                                  component="LEC",
                                  graded=True,
                                  crse_id=22222,
                                  class_nbr=11111,
                                  campus='SURRY',
                                  title="Web Stuff",
                                  enrl_cap=85,
                                  enrl_tot=80,
                                  wait_tot=4)
        self.co1.save()
        self.co2.save()
示例#6
0
文件: tests.py 项目: avacariu/coursys
 def setUp(self):
     p1 = Person(emplid=210012345, userid="test1",
             last_name="Lname", first_name="Fname", pref_first_name="Fn", middle_name="M")
     p1.save()
     
     s = Semester(name="1077", start=date(2007,9,4), end=date(2007,12,3))
     s.save()
 
     unit = Unit.objects.get(label="CMPT")
     self.co1 = CourseOffering(owner=unit, subject="CMPT", number="120", section="D100", semester=s, component="LEC",
                         graded=True, crse_id=11111, class_nbr=22222, campus='BRNBY', title="Computer Stuff",
                         enrl_cap=100, enrl_tot=99, wait_tot=2)
     
     self.co2 = CourseOffering(owner=unit, subject="CMPT", number="165", section="D100", semester=s, component="LEC",
                         graded=True, crse_id=22222, class_nbr=11111, campus='SURRY', title="Web Stuff",
                         enrl_cap=85, enrl_tot=80, wait_tot=4)
     self.co1.save()
     self.co2.save()
示例#7
0
文件: tests.py 项目: sfu-fas/coursys
    def test_bitfield(self):
        s, c1 = create_offering()
        c2 = CourseOffering(subject="CMPT", number="121", section="D100", semester=s, component="LEC",
                           graded=True, crse_id=11112, class_nbr=22223, campus='BRNBY', title="Other Stuff",
                           enrl_cap=100, enrl_tot=99, wait_tot=2)
        c2.save()

        c1.flags = CourseOffering.flags.quant
        c1.save()
        self.assertEqual(self._flag_filter([CourseOffering.flags.quant, CourseOffering.flags.bhum]), set())
        self.assertEqual(self._flag_filter([CourseOffering.flags.quant]), {c1})
        self.assertEqual(self._flag_filter([~CourseOffering.flags.quant]), {c2})
        self.assertEqual(self._flag_filter([~CourseOffering.flags.bhum]), {c1, c2})

        c1.flags = 0
        c1.save()
        self.assertEqual(self._flag_filter([CourseOffering.flags.quant]), set())
        self.assertEqual(self._flag_filter([~CourseOffering.flags.quant]), {c1, c2})
示例#8
0
def create_test_offering():
    """
    Create a CourseOffering (and related stuff) that can be used in tests with no fixtures
    """
    s = create_fake_semester('1144')
    u = Unit(label='BABL', name="Department of Babbling")
    u.save()
    o = CourseOffering(subject='BABL', number='123', section='F104', semester=s, component='LEC', owner=u,
                       title='Babbling for Baferad Ferzizzles', enrl_cap=100, enrl_tot=5, wait_tot=0)
    o.save()

    i = Person(first_name='Insley', last_name='Instructorberg', emplid=20000009, userid='instr')
    i.save()
    s = Person(first_name='Stanley', last_name='Studentson', emplid=20000010, userid='student')
    s.save()

    Member(offering=o, person=i, role='INST').save()
    Member(offering=o, person=s, role='STUD').save()

    return o
示例#9
0
class ApplicationTest(TestCase):
    fixtures = ['basedata', 'coredata', 'ta_ra']

    def setUp(self):
        p1 = Person(emplid=210012345,
                    userid="test1",
                    last_name="Lname",
                    first_name="Fname",
                    pref_first_name="Fn",
                    middle_name="M")
        p1.save()

        s = Semester(name="1077",
                     start=date(2007, 9, 4),
                     end=date(2007, 12, 3))
        s.save()

        unit = Unit.objects.get(label="CMPT")
        self.co1 = CourseOffering(owner=unit,
                                  subject="CMPT",
                                  number="120",
                                  section="D100",
                                  semester=s,
                                  component="LEC",
                                  graded=True,
                                  crse_id=11111,
                                  class_nbr=22222,
                                  campus='BRNBY',
                                  title="Computer Stuff",
                                  enrl_cap=100,
                                  enrl_tot=99,
                                  wait_tot=2)

        self.co2 = CourseOffering(owner=unit,
                                  subject="CMPT",
                                  number="165",
                                  section="D100",
                                  semester=s,
                                  component="LEC",
                                  graded=True,
                                  crse_id=22222,
                                  class_nbr=11111,
                                  campus='SURRY',
                                  title="Web Stuff",
                                  enrl_cap=85,
                                  enrl_tot=80,
                                  wait_tot=4)
        self.co1.save()
        self.co2.save()

    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_fresh.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: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: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: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>')

    def test_pages(self):
        c = Client()

        # TUG/instructor views
        c.login_user('dzhao')
        offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
        ta = Member.objects.filter(offering=offering, role="TA")[0]
        test_views(self, c, 'offering:', ['new_tug'], {
            'course_slug': offering.slug,
            'userid': ta.person.userid
        })

        # create TUG to view/edit
        tug = TUG(member=ta, base_units=5)
        for f in list(tug.config_meta.keys()):
            tug.config[f] = {'weekly': 1, 'total': 13, 'note': 'somenote'}
        tug.save()
        test_views(self, c, 'offering:', ['view_tug', 'edit_tug'], {
            'course_slug': offering.slug,
            'userid': ta.person.userid
        })

        # admin views
        c.login_user('dzhao')
        test_views(self, c, 'tugs:', ['all_tugs_admin'], {})
        test_views(self, c, 'ta:', ['view_postings'], {})
        post = TAPosting.objects.filter(unit__label='CMPT')[0]
        test_views(self, c, 'ta:', [
            'new_application', 'new_application_manual',
            'view_all_applications', 'print_all_applications',
            'print_all_applications_by_course', 'view_late_applications',
            'assign_tas', 'all_contracts'
        ], {'post_slug': post.slug})
        test_views(self, c, 'ta:', ['assign_bus'], {
            'post_slug': post.slug,
            'course_slug': offering.slug
        })

        contr = TAContract.objects.filter(posting=post)[0]
        test_views(self, c, 'ta:', [
            'edit_application', 'view_application', 'preview_offer',
            'view_contract', 'edit_contract'
        ], {
            'post_slug': post.slug,
            'userid': contr.application.person.userid
        })

        # applicant views
        c.login_user(contr.application.person.userid)
        test_views(self, c, 'ta:', ['accept_contract'], {
            'post_slug': post.slug,
            'userid': contr.application.person.userid
        })
示例#10
0
文件: tests.py 项目: tjkind/coursys
 def setUp(self):
     """
         Build a TACategory, TAContract, and two TACourses
     """
     unit = Unit(label="TEST", name="A Fake Unit for Testing") 
     unit.save()
     person = Person(emplid="300000000",
                     userid="testy",
                     first_name="Testy",
                     last_name="Testerson")
     person.save()
     semester = Semester(name="1147",
                         start=datetime.date.today(),
                         end=datetime.date.today())
     semester.save()
     course1 = Course(subject="TEST", 
                     number="100",
                     title="Intro to Testing")
     course1.save()
     course2 = Course(subject="TEST", 
                     number="200",
                     title="Advanced Testing")
     course2.save()
     courseoffering1 = CourseOffering(subject="TEST",
                                      number="100",
                                      section="D100",
                                      semester=semester,
                                      component="LEC",
                                      owner=unit,
                                      title="Intro to Testing",
                                      campus="BRNBY",
                                      enrl_cap=100,
                                      enrl_tot=100,
                                      wait_tot=50,
                                      course=course1)
     courseoffering1.save()
     courseoffering2 = CourseOffering(subject="TEST",
                                      number="200",
                                      section="D200",
                                      semester=semester,
                                      component="LEC",
                                      owner=unit,
                                      title="Advanced Testing",
                                      campus="BRNBY",
                                      enrl_cap=100,
                                      enrl_tot=100,
                                      wait_tot=50,
                                      course=course2)
     courseoffering2.save()
     account = Account(unit=unit, 
                       account_number=1337, 
                       position_number=5,
                       title="A Fake Account for Testing")
     account.save()
     four_weeks_later = datetime.date.today() + datetime.timedelta(days=28)
     hiring_semester = HiringSemester(semester=semester,
                               unit=unit,
                               deadline_for_acceptance=datetime.date.today(),
                               pay_start=datetime.date.today(),
                               pay_end=four_weeks_later,
                               payperiods=2.5)
     hiring_semester.save()
     category = TACategory(account=account,
                           hiring_semester=hiring_semester,
                           code="TST",
                           title="Test Contract Category",
                           hours_per_bu=decimal.Decimal("42"),
                           holiday_hours_per_bu=decimal.Decimal("1.1"),
                           pay_per_bu=decimal.Decimal("125.00"),
                           scholarship_per_bu=decimal.Decimal("25.00"),
                           bu_lab_bonus=decimal.Decimal("0.17"))
     category.save()
     contract = TAContract(category=category,
                           person=person,
                           status="NEW",
                           sin="123456789",
                           deadline_for_acceptance=datetime.date.today(),
                           pay_start=datetime.date.today(),
                           pay_end=datetime.date.today() + datetime.timedelta(days=10),
                           payperiods=2.5,
                           appointment="INIT",
                           conditional_appointment=True,
                           created_by="classam",
                           tssu_appointment=True)
     contract.save()
     tacourse = TACourse(course=courseoffering1,
                         contract=contract,
                         bu=decimal.Decimal('3.0'),
                         labtut=True)
     tacourse.save()
     tacourse2 = TACourse(course=courseoffering2,
                          contract=contract,
                          bu=decimal.Decimal('2.0'),
                          labtut=False)
     tacourse2.save()
示例#11
0
    def global_data(self):
        univ, _ = Unit.objects.get_or_create(label='UNIV', name='Simon Fraser University', parent=None)
        fas, _ = Unit.objects.get_or_create(label='FAS', name='Faculty of Applied Sciences', parent=univ)
        fas.config['informal_name'] = 'Applied Sciences'
        fas.save()
        cmpt, _ = Unit.objects.get_or_create(label='CMPT')
        cmpt.name = 'School of Computing Science'
        cmpt.config['informal_name'] = 'Computing Science'
        cmpt.parent = fas
        cmpt.save()
        ensc, _ = Unit.objects.get_or_create(label='ENSC')
        ensc.name = 'School of Engineering Science'
        ensc.config['informal_name'] = 'Engineering Science'
        ensc.parent = fas
        ensc.save()
        mse, _ = Unit.objects.get_or_create(label='MSE')
        mse.name = 'Mechatronic Systems Engineering'
        mse.config['informal_name'] = 'Mechatronics'
        mse.parent = fas
        mse.save()
        phil, _ = Unit.objects.get_or_create(label='PHIL')
        phil.name = 'Department of Philosophy'
        phil.parent = None
        phil.save()

        create_fake_semester('1134')
        create_fake_semester('1137')
        create_fake_semester('1141')
        create_fake_semester('1144')
        create_fake_semester('1147')

        danyu = get_or_create_nosave(Person, userid='dzhao', first_name='DanYu', last_name='Zhao')
        danyu.emplid = 220000123
        danyu.save()

        greg = get_or_create_nosave(Person, userid='ggbaker', first_name='Gregory', last_name='Baker')
        greg.emplid = 220000124
        greg.save()

        diana = get_or_create_nosave(Person, userid='diana', first_name='Diana', last_name='Cukierman')
        diana.emplid = 220000125
        diana.save()

        tony = get_or_create_nosave(Person, userid='dixon', first_name='Anthony', last_name='Dixon')
        tony.emplid = 220000126
        tony.save()

        brad = get_or_create_nosave(Person, userid='bbart', first_name='Bradley', last_name='Bart')
        brad.emplid = 220000127
        brad.save()

        farid = get_or_create_nosave(Person, userid='mfgolnar', first_name='Farid', last_name='Golnaraghi')
        farid.emplid = 220000128
        farid.save()

        phillip = get_or_create_nosave(Person, userid='phillip', first_name='Phillip', last_name='Philosophy')
        phillip.emplid = 220000129
        phillip.save()

        try:
            o = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
        except CourseOffering.DoesNotExist:
            o = CourseOffering(slug=TEST_COURSE_SLUG, semester=Semester.current(), subject='CMPT', number='123',
                               enrl_cap=10, enrl_tot=5, wait_tot=0)
            o.save()

        m, _ = Member.objects.get_or_create(person=greg, offering=o, role='INST')
        m.added_reason = 'AUTO'
        m.save()
示例#12
0
    def global_data(self):
        univ, _ = Unit.objects.get_or_create(label='UNIV',
                                             name='Simon Fraser University',
                                             parent=None)
        fas, _ = Unit.objects.get_or_create(label='FAS',
                                            name='Faculty of Applied Sciences',
                                            parent=univ)
        fas.config['informal_name'] = 'Applied Sciences'
        fas.save()
        cmpt, _ = Unit.objects.get_or_create(label='CMPT')
        cmpt.name = 'School of Computing Science'
        cmpt.config['informal_name'] = 'Computing Science'
        cmpt.parent = fas
        cmpt.save()
        ensc, _ = Unit.objects.get_or_create(label='ENSC')
        ensc.name = 'School of Engineering Science'
        ensc.config['informal_name'] = 'Engineering Science'
        ensc.parent = fas
        ensc.save()
        mse, _ = Unit.objects.get_or_create(label='MSE')
        mse.name = 'Mechatronic Systems Engineering'
        mse.config['informal_name'] = 'Mechatronics'
        mse.parent = fas
        mse.save()
        phil, _ = Unit.objects.get_or_create(label='PHIL')
        phil.name = 'Department of Philosophy'
        phil.parent = None
        phil.save()

        create_fake_semester('1134')
        create_fake_semester('1137')
        create_fake_semester('1141')
        create_fake_semester('1144')
        create_fake_semester('1147')

        danyu = get_or_create_nosave(Person,
                                     userid='dzhao',
                                     first_name='DanYu',
                                     last_name='Zhao')
        danyu.emplid = 220000123
        danyu.save()

        greg = get_or_create_nosave(Person,
                                    userid='ggbaker',
                                    first_name='Gregory',
                                    last_name='Baker')
        greg.emplid = 220000124
        greg.save()

        diana = get_or_create_nosave(Person,
                                     userid='diana',
                                     first_name='Diana',
                                     last_name='Cukierman')
        diana.emplid = 220000125
        diana.save()

        tony = get_or_create_nosave(Person,
                                    userid='dixon',
                                    first_name='Anthony',
                                    last_name='Dixon')
        tony.emplid = 220000126
        tony.save()

        brad = get_or_create_nosave(Person,
                                    userid='bbart',
                                    first_name='Bradley',
                                    last_name='Bart')
        brad.emplid = 220000127
        brad.save()

        farid = get_or_create_nosave(Person,
                                     userid='mfgolnar',
                                     first_name='Farid',
                                     last_name='Golnaraghi')
        farid.emplid = 220000128
        farid.save()

        phillip = get_or_create_nosave(Person,
                                       userid='phillip',
                                       first_name='Phillip',
                                       last_name='Philosophy')
        phillip.emplid = 220000129
        phillip.save()

        try:
            o = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
        except CourseOffering.DoesNotExist:
            o = CourseOffering(slug=TEST_COURSE_SLUG,
                               semester=Semester.current(),
                               subject='CMPT',
                               number='123',
                               enrl_cap=10,
                               enrl_tot=5,
                               wait_tot=0)
            o.save()

        m, _ = Member.objects.get_or_create(person=greg,
                                            offering=o,
                                            role='INST')
        m.added_reason = 'AUTO'
        m.save()
示例#13
0
def import_offering(subject, number, section, strm, crse_id, class_nbr, component, title, campus,
                    enrl_cap, enrl_tot, wait_tot, cancel_dt, acad_org, instr_mode, rqmnt_designtn, units,
                    create_units=False):
    """
    Import one offering. Returns CourseOffering or None.
    
    Arguments must be in the same order as CLASS_TBL_FIELDS.
    """
    global REQ_DES
    if not REQ_DES:
        REQ_DES = get_reqmnt_designtn()
    semester = Semester.objects.get(name=strm)
    graded = True # non-graded excluded in with "class_type='E'" in query

    # make sure the data is as we expect:
    if not CAMPUSES.has_key(campus):
        raise KeyError, "Unknown campus: %r." % (campus)
    if not COMPONENTS.has_key(component):
        raise KeyError, "Unknown course component: %r." % (component)
    if not INSTR_MODE.has_key(instr_mode):
        raise KeyError, "Unknown instructional mode: %r." % (instr_mode)

    if cancel_dt is not None:
        # mark cancelled sections
        component = "CAN"

    if section == 'G':
        section = 'G100' # fix broken data somebody entered

    owner = get_unit(acad_org, create=create_units)

    # search for existing offerings both possible ways and make sure we're consistent
    c_old1 = CourseOffering.objects.filter(subject=subject, number=number, section=section, semester=semester).select_related('course')
    c_old2 = CourseOffering.objects.filter(class_nbr=class_nbr, semester=semester)
    c_old = list(set(c_old1) | set(c_old2))
    
    if len(c_old)>1:
        raise KeyError, "Already duplicate courses: %r %r" % (c_old1, c_old2)
    elif len(c_old)==1:
        # already in DB: update things that might have changed
        c = c_old[0]
    else:
        # new record: create.
        c = CourseOffering(subject=subject, number=number, section=section, semester=semester)

    c.section = section
    c.crse_id = crse_id
    c.class_nbr = class_nbr
    c.component = component
    c.graded = graded
    c.title = title
    c.campus = campus
    c.enrl_cap = enrl_cap
    c.enrl_tot = enrl_tot
    c.wait_tot = wait_tot
    c.owner = owner
    c.instr_mode = instr_mode
    c.units = units
    c.slug = c.autoslug() # rebuild slug in case section changes for some reason

    # set the WQB flags
    flags = REQMNT_DESIGNTN_FLAGS[REQ_DES.get(rqmnt_designtn, '')]
    for pos, key in enumerate(c.flags.keys()):
        c.flags.set_bit(pos, key in flags)

    c.save_if_dirty()
    
    crs = c.course
    if crs.title != c.title:
        crs.title = c.title
        crs.save()

    return c
示例#14
0
文件: tests.py 项目: avacariu/coursys
class ApplicationTest(TestCase):
    fixtures = ['test_data']
    def setUp(self):
        p1 = Person(emplid=210012345, userid="test1",
                last_name="Lname", first_name="Fname", pref_first_name="Fn", middle_name="M")
        p1.save()
        
        s = Semester(name="1077", start=date(2007,9,4), end=date(2007,12,3))
        s.save()
    
        unit = Unit.objects.get(label="CMPT")
        self.co1 = CourseOffering(owner=unit, subject="CMPT", number="120", section="D100", semester=s, component="LEC",
                            graded=True, crse_id=11111, class_nbr=22222, campus='BRNBY', title="Computer Stuff",
                            enrl_cap=100, enrl_tot=99, wait_tot=2)
        
        self.co2 = CourseOffering(owner=unit, subject="CMPT", number="165", section="D100", semester=s, component="LEC",
                            graded=True, crse_id=22222, class_nbr=11111, campus='SURRY', title="Web Stuff",
                            enrl_cap=85, enrl_tot=80, wait_tot=4)
        self.co1.save()
        self.co2.save()

    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>')



    def test_pages(self):
        c = Client()

        # TUG/instructor views
        c.login_user('ggbaker')
        offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
        ta = Member.objects.filter(offering=offering, role="TA")[0]
        test_views(self, c, 'ta.views.', ['new_tug'], {'course_slug': offering.slug, 'userid': ta.person.userid})

        # create TUG to view/edit
        tug = TUG(member=ta, base_units=5)
        for f in tug.config_meta.keys():
            tug.config[f] = {'weekly': 1, 'total': 13, 'note': 'somenote'}
        tug.save()
        test_views(self, c, 'ta.views.', ['view_tug', 'edit_tug'], {'course_slug': offering.slug, 'userid': ta.person.userid})

        # admin views
        c.login_user('ggbaker')
        test_views(self, c, 'ta.views.', ['all_tugs_admin', 'view_postings'], {})
        post = TAPosting.objects.filter(unit__label='CMPT')[0]
        test_views(self, c, 'ta.views.', ['new_application', 'new_application_manual', 'view_all_applications',
                    'print_all_applications', 'print_all_applications_by_course', 'view_late_applications',
                    'assign_tas', 'all_contracts'],
                {'post_slug': post.slug})
        test_views(self, c, 'ta.views.', ['assign_bus'],
                {'post_slug': post.slug, 'course_slug': offering.slug})

        app = TAApplication.objects.filter(posting=post)[0]
        test_views(self, c, 'ta.views.', ['edit_application', 'view_application', 'preview_offer', 'view_contract',
                                          'edit_contract'],
                   {'post_slug': post.slug, 'userid': app.person.userid})

        # applicant views
        c.login_user(app.person.userid)
        test_views(self, c, 'ta.views.', ['accept_contract'],
                   {'post_slug': post.slug, 'userid': app.person.userid})
示例#15
0
文件: tests.py 项目: avacariu/coursys
 def setUp(self):
     """
         Build a TACategory, TAContract, and two TACourses
     """
     unit = Unit(label="TEST", name="A Fake Unit for Testing") 
     unit.save()
     person = Person(emplid="300000000",
                     userid="testy",
                     first_name="Testy",
                     last_name="Testerson")
     person.save()
     semester = Semester(name="1147",
                         start=datetime.date.today(),
                         end=datetime.date.today())
     semester.save()
     course1 = Course(subject="TEST", 
                     number="100",
                     title="Intro to Testing")
     course1.save()
     course2 = Course(subject="TEST", 
                     number="200",
                     title="Advanced Testing")
     course2.save()
     courseoffering1 = CourseOffering(subject="TEST",
                                      number="100",
                                      section="D100",
                                      semester=semester,
                                      component="LEC",
                                      owner=unit,
                                      title="Intro to Testing",
                                      campus="BRNBY",
                                      enrl_cap=100,
                                      enrl_tot=100,
                                      wait_tot=50,
                                      course=course1)
     courseoffering1.save()
     courseoffering2 = CourseOffering(subject="TEST",
                                      number="200",
                                      section="D200",
                                      semester=semester,
                                      component="LEC",
                                      owner=unit,
                                      title="Advanced Testing",
                                      campus="BRNBY",
                                      enrl_cap=100,
                                      enrl_tot=100,
                                      wait_tot=50,
                                      course=course2)
     courseoffering2.save()
     account = Account(unit=unit, 
                       account_number=1337, 
                       position_number=5,
                       title="A Fake Account for Testing")
     account.save()
     four_weeks_later = datetime.date.today() + datetime.timedelta(days=28)
     hiring_semester = HiringSemester(semester=semester,
                               unit=unit,
                               deadline_for_acceptance=datetime.date.today(),
                               pay_start=datetime.date.today(),
                               pay_end=four_weeks_later,
                               payperiods=2.5)
     hiring_semester.save()
     category = TACategory(account=account,
                           hiring_semester=hiring_semester,
                           code="TST",
                           title="Test Contract Category",
                           hours_per_bu=decimal.Decimal("42"),
                           holiday_hours_per_bu=decimal.Decimal("1.1"),
                           pay_per_bu=decimal.Decimal("100.00"),
                           scholarship_per_bu=decimal.Decimal("25.00"),
                           bu_lab_bonus=decimal.Decimal("0.17"))
     category.save()
     contract = TAContract(category=category,
                           person=person,
                           status="NEW",
                           sin="123456789",
                           deadline_for_acceptance=datetime.date.today(),
                           pay_start=datetime.date.today(),
                           pay_end=datetime.date.today() + datetime.timedelta(days=10),
                           payperiods=2.5,
                           appointment="INIT",
                           conditional_appointment=True,
                           created_by="classam",
                           tssu_appointment=True)
     contract.save()
     tacourse = TACourse(course=courseoffering1,
                         contract=contract,
                         bu=decimal.Decimal('3.0'),
                         labtut=True)
     tacourse.save()
     tacourse2 = TACourse(course=courseoffering2,
                          contract=contract,
                          bu=decimal.Decimal('2.0'),
                          labtut=False)
     tacourse2.save()
示例#16
0
def import_offering(subject, number, section, strm, crse_id, class_nbr, component, title, campus,
                    enrl_cap, enrl_tot, wait_tot, cancel_dt, acad_org, instr_mode, rqmnt_designtn, units,
                    create_units=False):
    """
    Import one offering. Returns CourseOffering or None.
    
    Arguments must be in the same order as CLASS_TBL_FIELDS.
    """
    global REQ_DES
    if not REQ_DES:
        REQ_DES = get_reqmnt_designtn()
    semester = Semester.objects.get(name=strm)
    graded = True # non-graded excluded in with "class_type='E'" in query

    # make sure the data is as we expect:
    if campus not in CAMPUSES:
        raise KeyError("Unknown campus: %r." % (campus))
    if component not in COMPONENTS:
        raise KeyError("Unknown course component: %r." % (component))
    if instr_mode not in INSTR_MODE:
        raise KeyError("Unknown instructional mode: %r." % (instr_mode))

    if cancel_dt is not None:
        # mark cancelled sections
        component = "CAN"

    if section == 'G':
        section = 'G100' # fix broken data somebody entered
    if section == 'R':
        section = 'G100' # fix different broken data somebody entered

    owner = get_unit(acad_org, create=create_units)

    # search for existing offerings both possible ways and make sure we're consistent
    c_old1 = CourseOffering.objects.filter(subject=subject, number=number, section=section, semester=semester).select_related('course')
    c_old2 = CourseOffering.objects.filter(class_nbr=class_nbr, semester=semester)
    c_old = list(set(c_old1) | set(c_old2))
    
    if len(c_old)>1:
        raise KeyError("Already duplicate courses: %r %r" % (c_old1, c_old2))
    elif len(c_old)==1:
        # already in DB: update things that might have changed
        c = c_old[0]
    else:
        # new record: create.
        c = CourseOffering(subject=subject, number=number, section=section, semester=semester)

    c.section = section
    c.crse_id = crse_id
    c.class_nbr = class_nbr
    c.component = component
    c.graded = graded
    c.title = title
    c.campus = campus
    c.enrl_cap = enrl_cap
    c.enrl_tot = enrl_tot
    c.wait_tot = wait_tot
    c.owner = owner
    c.instr_mode = instr_mode
    c.units = units
    c.slug = c.autoslug() # rebuild slug in case section changes for some reason

    # set the WQB flags
    flags = REQMNT_DESIGNTN_FLAGS[REQ_DES.get(rqmnt_designtn, '')]
    for pos, key in enumerate(c.flags.keys()):
        c.flags.set_bit(pos, key in flags)

    c.save_if_dirty()
    
    crs = c.course
    if crs.title != c.title:
        crs.title = c.title
        crs.save()

    EnrolmentHistory.from_offering(c, save=True)

    return c