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()
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)
def setUp(self): self.c_slug = TEST_COURSE_SLUG self.c = CourseOffering.objects.get(slug = self.c_slug) self.a1 = LetterActivity(offering = self.c, name = 'test_assignment_let_1', short_name = 'tal1', status = 'RLS', due_date = datetime.now(), position = 0) self.a1.save() self.students = self.c.members.filter(person__role='STUD') self.userids = [p.userid for p in self.students] self.emplids = [p.emplid for p in self.students]
def test_sort_letter(self): """ Test sorting letter grades """ s, c = create_offering() a = LetterActivity(name="Assignment 1", short_name="A1", status="RLS", offering=c, position=2, due_date=None, group=False) a.save() ms = [] for i in range(10): p = Person.objects.get(userid="0aaa%i"%i) m = Member(person=p, offering=c, role="STUD", added_reason="UNK") m.save() ms.append(m) g = LetterGrade(activity=a, member=ms[0], letter_grade="B+", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[1], letter_grade="A", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[2], letter_grade="D", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[3], letter_grade="B-", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[4], letter_grade="P", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[5], letter_grade="GN", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[6], letter_grade="F", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[7], letter_grade="DE", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[8], letter_grade="C-", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[9], letter_grade="N", flag="GRAD") g.save(entered_by='ggbaker') g_objs = LetterGrade.objects.filter(activity=a) gs = [g.letter_grade for g in g_objs] gs_sort = sorted_letters(gs) self.assertEquals(gs_sort, ['A', 'B+', 'B-', 'C-', 'D', 'P', 'F', 'DE', 'N', 'GN']) # pre-sort by userid for median testing (so we know which subsets we're grabbing) gs = [(int(g.member.person.userid[4:]), g.letter_grade) for g in g_objs] gs.sort() gs = [g for u,g in gs] # odd-length case self.assertEquals(median_letters(sorted_letters(gs[0:5])), "B-") # even length with median at boundary self.assertEquals(median_letters(sorted_letters(gs[0:6])), "B-/D") # empty list self.assertEquals(median_letters([]), u"\u2014")
def test_sort_letter(self): """ Test sorting letter grades """ s, c = create_offering() a = LetterActivity(name="Assignment 1", short_name="A1", status="RLS", offering=c, position=2, due_date=None, group=False) a.save() ms = [] for i in range(10): p = Person.objects.get(userid="0aaa%i"%i) m = Member(person=p, offering=c, role="STUD", added_reason="UNK") m.save() ms.append(m) g = LetterGrade(activity=a, member=ms[0], letter_grade="B+", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[1], letter_grade="A", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[2], letter_grade="D", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[3], letter_grade="B-", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[4], letter_grade="P", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[5], letter_grade="GN", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[6], letter_grade="F", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[7], letter_grade="DE", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[8], letter_grade="C-", flag="GRAD") g.save(entered_by='ggbaker') g = LetterGrade(activity=a, member=ms[9], letter_grade="N", flag="GRAD") g.save(entered_by='ggbaker') g_objs = LetterGrade.objects.filter(activity=a) gs = [g.letter_grade for g in g_objs] gs_sort = sorted_letters(gs) self.assertEqual(gs_sort, ['A', 'B+', 'B-', 'C-', 'D', 'P', 'F', 'DE', 'N', 'GN']) # pre-sort by userid for median testing (so we know which subsets we're grabbing) gs = [(int(g.member.person.userid[4:]), g.letter_grade) for g in g_objs] gs.sort() gs = [g for u,g in gs] # odd-length case self.assertEqual(median_letters(sorted_letters(gs[0:5])), "B-") # even length with median at boundary self.assertEqual(median_letters(sorted_letters(gs[0:6])), "B-/D") # empty list self.assertEqual(median_letters([]), "\u2014")
class TestImportFunctionsLetter(TestCase): fixtures = ['basedata', 'coredata', 'grades'] def setUp(self): self.c_slug = TEST_COURSE_SLUG self.c = CourseOffering.objects.get(slug=self.c_slug) self.a1 = LetterActivity(offering=self.c, name='test_assignment_let_1', short_name='tal1', status='RLS', due_date=datetime.now(), position=0) self.a1.save() self.students = self.c.members.filter(person__role='STUD') self.userids = [p.userid for p in self.students] self.emplids = [p.emplid for p in self.students] def get_test_file(self, name): with open(name, 'r') as inp: r = csv.reader(inp) self.values = [] for line in r: self.values.append(line) def compare_grade_lists(self, data_returned): for sname, grade in self.values: self.assertIn(sname, data_returned.keys()) self.assertEqual(data_returned[sname], grade) def test_import_grades_new_format_l(self): inName = 'marking/testfiles/newformat_noprob_userid_let.csv' self.get_test_file(inName) del self.values[0] # Delete header row data_to_return = {} with open(inName, 'r') as inp: err = _compose_imported_grades(inp, self.students, data_to_return, self.a1) self.assertEqual(err, []) self.assertEqual(len(data_to_return), len(self.values)) self.compare_grade_lists(data_to_return) def test_import_grades_old_format_l(self): inName = 'marking/testfiles/oldformat_noprob_let.csv' self.get_test_file(inName) data_to_return = {} with open(inName, 'r') as inp: err = _compose_imported_grades(inp, self.students, data_to_return, self.a1) self.assertEqual(err, []) self.assertEqual(len(data_to_return), len(self.values)) self.compare_grade_lists(data_to_return)
class TestImportFunctionsLetter(TestCase): fixtures = ['basedata', 'coredata', 'grades'] def setUp(self): self.c_slug = TEST_COURSE_SLUG self.c = CourseOffering.objects.get(slug = self.c_slug) self.a1 = LetterActivity(offering = self.c, name = 'test_assignment_let_1', short_name = 'tal1', status = 'RLS', due_date = datetime.now(), position = 0) self.a1.save() self.students = self.c.members.filter(person__role='STUD') self.userids = [p.userid for p in self.students] self.emplids = [p.emplid for p in self.students] def get_test_file(self, name): with open(name, 'r') as inp: r = csv.reader(inp) self.values = [] for line in r: self.values.append(line) def compare_grade_lists(self, data_returned): for sname, grade in self.values: self.assertIn(sname, list(data_returned.keys())) self.assertEqual(data_returned[sname], grade) def test_import_grades_new_format_l(self): inName = 'marking/testfiles/newformat_noprob_userid_let.csv' self.get_test_file(inName) del self.values[0] # Delete header row data_to_return = {} with open(inName, 'rb') as inp: err = _compose_imported_grades(inp, self.students, data_to_return, self.a1) self.assertEqual(err, []) self.assertEqual(len(data_to_return), len(self.values)) self.compare_grade_lists(data_to_return) def test_import_grades_old_format_l(self): inName = 'marking/testfiles/oldformat_noprob_let.csv' self.get_test_file(inName) data_to_return = {} with open(inName, 'rb') as inp: err = _compose_imported_grades(inp, self.students, data_to_return, self.a1) self.assertEqual(err, []) self.assertEqual(len(data_to_return), len(self.values)) self.compare_grade_lists(data_to_return)
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)
def test_activities(self): """ Test activity classes: subclasses, selection, sorting. """ s, c = create_offering() a = NumericActivity(name="Assignment 1", short_name="A1", status="RLS", offering=c, position=2, max_grade=15) a.save() a = NumericActivity(name="Assignment 2", short_name="A2", status="RLS", offering=c, position=6, max_grade=15) a.save() a = LetterActivity(name="Project", short_name="Proj", status="URLS", offering=c, position=1) a.save() a = CalNumericActivity(name="Total", short_name="Total", status="URLS", offering=c, position=42, max_grade=30, formula="[A1]+[A2]") a.save() allact = all_activities_filter(offering=c) self.assertEqual(len(allact), 4) self.assertEqual(allact[0].slug, 'proj') # make sure position=1 is first self.assertEqual(type(allact[1]), NumericActivity) self.assertEqual(type(allact[3]), CalNumericActivity)
def test_replace_activity(self): """ Can we safely replace an activity with one of the same name/shortname? """ c = CourseOffering.objects.get(slug=self.course_slug) a = NumericActivity(offering=c, name="Assign1", short_name="A1", status="RLS", group=False, deleted=False, max_grade=10, position=1) a.save() a.safely_delete() self.assertEqual(a.deleted, True) self.assertNotEqual(a.name, 'Assign1') self.assertNotEqual(a.short_name, 'A1') # replace with same type a = CalNumericActivity(offering=c, name="Assign1", short_name="A1", status="URLS", group=True, deleted=False, max_grade=15, position=2) a.save() a.safely_delete() # replace with a different type a = LetterActivity(offering=c, name="Assign1", short_name="A1", status="RLS", group=False, deleted=False, position=3) a.save()
def create_test_offering(): """ main test course: interesting data for grades, marking, submission, groups """ from grades.models import Activity, LetterActivity, CalNumericActivity, CalLetterActivity from submission.models import SubmissionComponent from submission.models.code import CodeComponent from submission.models.pdf import PDFComponent from groups.models import Group, GroupMember from marking.models import ActivityComponent crs = CourseOffering.objects.get(slug=TEST_COURSE_SLUG) crs.set_labtut(True) crs.set_url("http://www.cs.sfu.ca/CC/165/common/") crs.set_taemail("*****@*****.**") crs.save() # create example activities a1 = NumericActivity.objects.get(offering=crs, slug='a1') a2 = NumericActivity(offering=crs, name="Assignment 2", short_name="A2", status="URLS", due_date=crs.semester.start + datetime.timedelta(days=70), percent=10, group=True, max_grade=20, position=2) a2.set_url("http://www.cs.sfu.ca/CC/165/common/a2") a2.save() pr = LetterActivity(offering=crs, name="Project", short_name="Proj", status="URLS", due_date=crs.semester.start + datetime.timedelta(days=80), percent=40, group=True, position=3) pr.save() re = LetterActivity(offering=crs, name="Report", short_name="Rep", status="URLS", due_date=crs.semester.start + datetime.timedelta(days=81), percent=10, group=False, position=4) re.save() ex = NumericActivity(offering=crs, name="Final Exam", short_name="Exam", status="URLS", due_date=None, percent=30, group=False, max_grade=90, position=5) ex.save() to = CalNumericActivity(offering=crs, name="Final Percent", short_name="Perc", status="INVI", due_date=None, percent=0, group=False, max_grade=100, formula="[[activitytotal]]", position=6) to.save() to = CalLetterActivity(offering=crs, name="Letter Grade", short_name="Letter", status="INVI", due_date=None, percent=0, group=False, numeric_activity=to, position=6) to.save() # make A1 submittable and markable s = CodeComponent(activity=a1, title=u"Cöde File", description="The code you're submitting.", allowed=".py,.java") s.save() s = PDFComponent(activity=a1, title="Report", description="Report on what you did.", specified_filename="report.pdf") s.save() m = ActivityComponent( numeric_activity=a1, max_mark=5, title=u"Part ➀", description="Part ➀ was done well and seems to work.", position=1, slug='part-1') m.save() m = ActivityComponent( numeric_activity=a1, max_mark=5, title="Part 2", description="Part 2 was done well and seems to work.", position=2) m.save() # create some groups members = list(Member.objects.filter(offering=crs, role='STUD')) random.shuffle(members) m = members.pop() g = Group(name="SomeGroup", courseoffering=crs, manager=m) g.save() for m in [m, members.pop()]: gm = GroupMember(group=g, student=m, confirmed=True, activity=a2) gm.save() m = members.pop() g = Group(name="AnotherGroup", courseoffering=crs, manager=m) g.save() for m in [m, members.pop(), members.pop()]: gm = GroupMember(group=g, student=m, confirmed=True, activity=a2) gm.save() gm = GroupMember(group=g, student=m, confirmed=True, activity=pr) gm.save() return itertools.chain( Activity.objects.all(), NumericActivity.objects.all(), LetterActivity.objects.all(), CalNumericActivity.objects.all(), CalLetterActivity.objects.all(), SubmissionComponent.objects.all(), CodeComponent.objects.all(), PDFComponent.objects.all(), Group.objects.all(), GroupMember.objects.all(), ActivityComponent.objects.all(), )
def create_test_offering(): """ main test course: interesting data for grades, marking, submission, groups """ from grades.models import Activity, LetterActivity, CalNumericActivity, CalLetterActivity from submission.models import SubmissionComponent from submission.models.code import CodeComponent from submission.models.pdf import PDFComponent from groups.models import Group, GroupMember from marking.models import ActivityComponent crs = CourseOffering.objects.get(slug=TEST_COURSE_SLUG) crs.set_labtut(True) crs.set_url("http://www.cs.sfu.ca/CC/165/common/") crs.set_taemail("*****@*****.**") crs.save() # create example activities a1 = NumericActivity.objects.get(offering=crs, slug='a1') a2 = NumericActivity(offering=crs, name="Assignment 2", short_name="A2", status="URLS", due_date=crs.semester.start + datetime.timedelta(days=70), percent=10, group=True, max_grade=20, position=2) a2.set_url("http://www.cs.sfu.ca/CC/165/common/a2") a2.save() pr = LetterActivity(offering=crs, name="Project", short_name="Proj", status="URLS", due_date=crs.semester.start + datetime.timedelta(days=80), percent=40, group=True, position=3) pr.save() re = LetterActivity(offering=crs, name="Report", short_name="Rep", status="URLS", due_date=crs.semester.start + datetime.timedelta(days=81), percent=10, group=False, position=4) re.save() ex = NumericActivity(offering=crs, name="Final Exam", short_name="Exam", status="URLS", due_date=None, percent=30, group=False, max_grade=90, position=5) ex.save() to = CalNumericActivity(offering=crs, name="Final Percent", short_name="Perc", status="INVI", due_date=None, percent=0, group=False, max_grade=100, formula="[[activitytotal]]", position=6) to.save() to = CalLetterActivity(offering=crs, name="Letter Grade", short_name="Letter", status="INVI", due_date=None, percent=0, group=False, numeric_activity=to, position=6) to.save() # make A1 submittable and markable s = CodeComponent(activity=a1, title="Code File", description="The code you're submitting.", allowed=".py,.java") s.save() s = PDFComponent(activity=a1, title="Report", description="Report on what you did.", specified_filename="report.pdf") s.save() m = ActivityComponent(numeric_activity=a1, max_mark=5, title="Part 1", description="Part 1 was done well and seems to work.", position=1) m.save() m = ActivityComponent(numeric_activity=a1, max_mark=5, title="Part 2", description="Part 2 was done well and seems to work.", position=2) m.save() # create some groups members = list(Member.objects.filter(offering=crs, role='STUD')) random.shuffle(members) m = members.pop() g = Group(name="SomeGroup", courseoffering=crs, manager=m) g.save() for m in [m, members.pop()]: gm = GroupMember(group=g, student=m, confirmed=True, activity=a2) gm.save() m = members.pop() g = Group(name="AnotherGroup", courseoffering=crs, manager=m) g.save() for m in [m, members.pop(), members.pop()]: gm = GroupMember(group=g, student=m, confirmed=True, activity=a2) gm.save() gm = GroupMember(group=g, student=m, confirmed=True, activity=pr) gm.save() return itertools.chain( Activity.objects.all(), NumericActivity.objects.all(), LetterActivity.objects.all(), CalNumericActivity.objects.all(), CalLetterActivity.objects.all(), SubmissionComponent.objects.all(), CodeComponent.objects.all(), PDFComponent.objects.all(), Group.objects.all(), GroupMember.objects.all(), ActivityComponent.objects.all(), )
def test_class_1(slug): """ main test course: 20 students, TA, some assignments """ crs = CourseOffering.objects.get(slug=slug) crs.set_labtut(True) crs.set_url("http://www.cs.sfu.ca/CC/165/common/") crs.set_taemail("*****@*****.**") crs.save() for i in range(10): lab = "D1%02i" % (random.randint(1,4)) p = Person.objects.get(userid="0aaa%i"%(i)) if Member.objects.filter(person=p, offering=crs, role="STUD"): # randomly added by other student-adder: skip continue m = Member(person=p, offering=crs, role="STUD", credits=3, career="UGRD", added_reason="AUTO", labtut_section=lab) m.save() if not Member.objects.filter(person__userid='ggbaker', offering=crs, role='INST'): Member(person=Person.objects.get(userid='ggbaker'), offering=crs, role='INST').save() # create a TA p = Person(emplid=fake_emplid(), userid="0grad1", last_name="Gradstudent", first_name="Douglas", middle_name="", pref_first_name="Doug") p.save() m = Member(person=p, offering=crs, role="TA", credits=0, career="NONS", added_reason="AUTO", labtut_section=None) m.save() # create example activities crs.activity_set.all().update(deleted=True) a1 = NumericActivity(offering=crs, name="Assignment 1", short_name="A1", status="RLS", due_date=crs.semester.start + datetime.timedelta(days=60), percent=10, group=False, max_grade=10, position=1) a1.set_url("http://www.cs.sfu.ca/CC/165/common/a1") a1.save() a2 = NumericActivity(offering=crs, name="Assignment 2", short_name="A2", status="URLS", due_date=crs.semester.start + datetime.timedelta(days=70), percent=10, group=True, max_grade=20, position=2) a2.save() pr = LetterActivity(offering=crs, name="Project", short_name="Proj", status="URLS", due_date=crs.semester.start + datetime.timedelta(days=80), percent=40, group=True, position=3) pr.save() re = LetterActivity(offering=crs, name="Report", short_name="Rep", status="URLS", due_date=crs.semester.start + datetime.timedelta(days=81), percent=10, group=False, position=4) re.save() ex = NumericActivity(offering=crs, name="Final Exam", short_name="Exam", status="URLS", due_date=None, percent=30, group=False, max_grade=90, position=5) ex.save() to = CalNumericActivity(offering=crs, name="Final Percent", short_name="Perc", status="INVI", due_date=None, percent=0, group=False, max_grade=100, formula="[[activitytotal]]", position=6) to.save() to = CalLetterActivity(offering=crs, name="Letter Grade", short_name="Letter", status="INVI", due_date=None, percent=0, group=False, numeric_activity=to, position=6) to.save() # make A1 submittable and markable s = CodeComponent(activity=a1, title="Code File", description="The code you're submitting.", allowed=".py,.java") s.save() s = PDFComponent(activity=a1, title="Report", description="Report on what you did.", specified_filename="report.pdf") s.save() m = ActivityComponent(numeric_activity=a1, max_mark=5, title="Part 1", description="Part 1 was done well and seems to work.", position=1) m.save() m = ActivityComponent(numeric_activity=a1, max_mark=5, title="Part 2", description="Part 2 was done well and seems to work.", position=2) m.save() # create some groups g = Group(name="SomeGroup", courseoffering=crs, manager=Member.objects.get(offering=crs, person__userid="0aaa0", role='STUD')) g.save() for userid in ['0aaa0', '0aaa1', '0aaa5', '0aaa8']: gm = GroupMember(group=g, student=Member.objects.get(offering=crs, person__userid=userid), confirmed=True, activity=a2) gm.save() g = Group(name="AnotherGroup", courseoffering=crs, manager=Member.objects.get(offering=crs, person__userid="0aaa4")) g.save() for userid in ['0aaa4', '0aaa6', '0aaa7', '0aaa2']: gm = GroupMember(group=g, student=Member.objects.get(offering=crs, person__userid=userid), confirmed=True, activity=a2) gm.save() gm = GroupMember(group=g, student=Member.objects.get(offering=crs, person__userid=userid), confirmed=True, activity=pr) gm.save()
def test_class_1(slug): """ main test course: 20 students, TA, some assignments """ crs = CourseOffering.objects.get(slug=slug) crs.set_labtut(True) crs.set_url("http://www.cs.sfu.ca/CC/165/common/") crs.set_taemail("*****@*****.**") crs.save() for i in range(10): lab = "D1%02i" % (random.randint(1, 4)) p = Person.objects.get(userid="0aaa%i" % (i)) if Member.objects.filter(person=p, offering=crs, role="STUD"): # randomly added by other student-adder: skip continue m = Member(person=p, offering=crs, role="STUD", credits=3, career="UGRD", added_reason="AUTO", labtut_section=lab) m.save() if not Member.objects.filter( person__userid='ggbaker', offering=crs, role='INST'): Member(person=Person.objects.get(userid='ggbaker'), offering=crs, role='INST').save() # create a TA p = Person(emplid=fake_emplid(), userid="0grad1", last_name="Gradstudent", first_name="Douglas", middle_name="", pref_first_name="Doug") p.save() m = Member(person=p, offering=crs, role="TA", credits=0, career="NONS", added_reason="AUTO", labtut_section=None) m.save() # create example activities crs.activity_set.all().update(deleted=True) a1 = NumericActivity(offering=crs, name="Assignment 1", short_name="A1", status="RLS", due_date=crs.semester.start + datetime.timedelta(days=60), percent=10, group=False, max_grade=10, position=1) a1.set_url("http://www.cs.sfu.ca/CC/165/common/a1") a1.save() a2 = NumericActivity(offering=crs, name="Assignment 2", short_name="A2", status="URLS", due_date=crs.semester.start + datetime.timedelta(days=70), percent=10, group=True, max_grade=20, position=2) a2.save() pr = LetterActivity(offering=crs, name="Project", short_name="Proj", status="URLS", due_date=crs.semester.start + datetime.timedelta(days=80), percent=40, group=True, position=3) pr.save() re = LetterActivity(offering=crs, name="Report", short_name="Rep", status="URLS", due_date=crs.semester.start + datetime.timedelta(days=81), percent=10, group=False, position=4) re.save() ex = NumericActivity(offering=crs, name="Final Exam", short_name="Exam", status="URLS", due_date=None, percent=30, group=False, max_grade=90, position=5) ex.save() to = CalNumericActivity(offering=crs, name="Final Percent", short_name="Perc", status="INVI", due_date=None, percent=0, group=False, max_grade=100, formula="[[activitytotal]]", position=6) to.save() to = CalLetterActivity(offering=crs, name="Letter Grade", short_name="Letter", status="INVI", due_date=None, percent=0, group=False, numeric_activity=to, position=6) to.save() # make A1 submittable and markable s = CodeComponent(activity=a1, title="Code File", description="The code you're submitting.", allowed=".py,.java") s.save() s = PDFComponent(activity=a1, title="Report", description="Report on what you did.", specified_filename="report.pdf") s.save() m = ActivityComponent( numeric_activity=a1, max_mark=5, title="Part 1", description="Part 1 was done well and seems to work.", position=1) m.save() m = ActivityComponent( numeric_activity=a1, max_mark=5, title="Part 2", description="Part 2 was done well and seems to work.", position=2) m.save() # create some groups g = Group(name="SomeGroup", courseoffering=crs, manager=Member.objects.get(offering=crs, person__userid="0aaa0", role='STUD')) g.save() for userid in ['0aaa0', '0aaa1', '0aaa5', '0aaa8']: gm = GroupMember(group=g, student=Member.objects.get(offering=crs, person__userid=userid), confirmed=True, activity=a2) gm.save() g = Group(name="AnotherGroup", courseoffering=crs, manager=Member.objects.get(offering=crs, person__userid="0aaa4")) g.save() for userid in ['0aaa4', '0aaa6', '0aaa7', '0aaa2']: gm = GroupMember(group=g, student=Member.objects.get(offering=crs, person__userid=userid), confirmed=True, activity=a2) gm.save() gm = GroupMember(group=g, student=Member.objects.get(offering=crs, person__userid=userid), confirmed=True, activity=pr) gm.save()