def test_create_comment(self): a = api.Assignment(assignment_id='foo', duedate='someday') s = api.Student(student_id=12345, first_name='Jane', last_name='Doe', email='janedoe@nowhere') n = api.Notebook(notebook_id='blah', assignment=a, student=s) c = api.Comment(comment_id='foo', comment='lorem ipsum', notebook=n) assert c.comment_id == 'foo' assert c.comment == 'lorem ipsum' assert c.notebook == n assert c._id assert c.to_dict()['notebook'] == n._id
def test_create_notebook(self): a = api.Assignment(assignment_id='foo', duedate='someday') s = api.Student(student_id=12345, first_name='Jane', last_name='Doe', email='janedoe@nowhere') n = api.Notebook(notebook_id='blah', assignment=a, student=s) assert n.notebook_id == 'blah' assert n.assignment == a assert n.student == s assert n._id assert n.to_dict()['assignment'] == a._id assert n.to_dict()['student'] == s._id
def test_create_grade(self): a = api.Assignment(assignment_id='foo', duedate='someday') s = api.Student(student_id=12345, first_name='Jane', last_name='Doe', email='janedoe@nowhere') n = api.Notebook(notebook_id='blah', assignment=a, student=s) g = api.Grade(grade_id='foo', max_score=10, autoscore=1, score=5, notebook=n) assert g.grade_id == 'foo' assert g.max_score == 10 assert g.autoscore == 1 assert g.score == 5 assert g.notebook == n assert g._id assert g.to_dict()['notebook'] == n._id
def test_add_notebook(self): n1 = self._add_notebook() # try inserting a duplicate notebook assert_raises(DuplicateKeyError, self.gb.add_notebook, n1) # try inserting something with the wrong type assert_raises(ValueError, self.gb.add_notebook, n1.to_dict()) # check that the notebook was correctly added assert len(self.gb.notebooks) == 1 assert_equal(self.gb.notebooks[0].to_dict(), n1.to_dict()) assert_equal(self.gb.find_notebook(_id=n1._id).to_dict(), n1.to_dict()) # add another notebook for the same student but with a # different assignment a = self._add_assignment() n2 = api.Notebook(notebook_id='blargh', assignment=a, student=n1.student) self.gb.add_notebook(n2) # check that it was added correctly assert len(self.gb.notebooks) == 2 assert_equal(self.gb.find_notebook(_id=n2._id).to_dict(), n2.to_dict()) # check that both notebooks are associated with the student assert len(self.gb.find_notebooks(student=n1.student)) == 2 # check that the first notebook is associated with the correct # assignment nbs = self.gb.find_notebooks(assignment=n1.assignment) assert len(nbs) == 1 assert nbs[0]._id == n1._id # check that the second notebook is associated with the # correct assignment nbs = self.gb.find_notebooks(assignment=n2.assignment) assert len(nbs) == 1 assert nbs[0]._id == n2._id
def _add_notebook(self): a = self._add_assignment() s = self._add_student() n = api.Notebook(notebook_id='blah', assignment=a, student=s) self.gb.add_notebook(n) return n
def test_find_or_create_notebook(self): a = self._add_assignment() s = self._add_student() n1 = api.Notebook(notebook_id='blah', assignment=a, student=s) n2 = self.gb.find_or_create_notebook(**n1.to_dict()) assert_equal(n1.to_dict(), n2.to_dict())