Exemple #1
0
 def test_importInvalidXML(self):
     vlines = validXML.splitlines()
     vlines[6:6] = ["<unspecifiedElement>bla</unspecifiedElement>"]
     invalidXML = "\n".join(vlines)
     
     self.assertRaisesRegexp(XMLSyntaxError, "not expected",
                             lambda : Exercise.fromXMLString(invalidXML.encode('utf-8')))
     del vlines[6]
     vlines[7:7] = ['<tex_exercise lang="DE">double german</tex_exercise>']
     invalidXML2 = "\n".join(vlines)
     self.assertRaisesRegexp(XMLSyntaxError, "Duplicate key-sequence",
                             lambda : Exercise.fromXMLString(invalidXML2.encode('utf-8')))
Exemple #2
0
    def test_importInvalidXML(self):
        vlines = validXML.splitlines()
        vlines[6:6] = ["<unspecifiedElement>bla</unspecifiedElement>"]
        invalidXML = "\n".join(vlines)

        self.assertRaisesRegexp(
            XMLSyntaxError, "not expected",
            lambda: Exercise.fromXMLString(invalidXML.encode('utf-8')))
        del vlines[6]
        vlines[7:7] = ['<tex_exercise lang="DE">double german</tex_exercise>']
        invalidXML2 = "\n".join(vlines)
        self.assertRaisesRegexp(
            XMLSyntaxError, "Duplicate key-sequence",
            lambda: Exercise.fromXMLString(invalidXML2.encode('utf-8')))
Exemple #3
0
 def test_importValidXML(self):
     exercise = Exercise.fromXMLFile(dataPath("jemand1.xml"))
     self.assertEqual(exercise.schemaversion, 2)
     self.assertEqual(len(exercise.tags), 2)
     self.assertIn('aabc', exercise.tags)
     self.assertIsInstance(exercise.modified, datetime.datetime)
     self.assertIn('DE', exercise.tex_exercise)
     self.assertIn('DE', exercise.tex_solution)
     self.assertIn('EN', exercise.tex_solution)
     self.assertNotIn('EN', exercise.tex_exercise)
     self.assertIsInstance(exercise.number, int)
Exemple #4
0
 def test_importValidXML(self):
     exercise = Exercise.fromXMLFile(dataPath("jemand1.xml"))
     self.assertEqual(exercise.schemaversion, 2)
     self.assertEqual(len(exercise.tags), 2)
     self.assertIn('aabc', exercise.tags)
     self.assertIsInstance(exercise.modified, datetime.datetime)
     self.assertIn('DE', exercise.tex_exercise)
     self.assertIn('DE', exercise.tex_solution)
     self.assertIn('EN', exercise.tex_solution)
     self.assertNotIn('EN', exercise.tex_exercise)
     self.assertIsInstance(exercise.number, int)
Exemple #5
0
 def test_jsonExport(self):
     exercise = Exercise.fromXMLString(validXML.encode("utf-8"))
     jsonEx = exercise.toJSON()
     jsonDecoded = json.loads(jsonEx)
     for attrib, value in exercise.items():
         if isinstance(value, datetime.datetime):
             self.assertEqual(datetime.datetime.strptime(jsonDecoded[attrib], Exercise.DATEFMT),
                              value)
         else:
             self.assertEqual(jsonDecoded[attrib], value)
     for attrib in jsonDecoded:
         assert attrib in exercise
Exemple #6
0
 def test_jsonExport(self):
     exercise = Exercise.fromXMLString(validXML.encode("utf-8"))
     jsonEx = exercise.toJSON()
     jsonDecoded = json.loads(jsonEx)
     for attrib, value in exercise.items():
         if isinstance(value, datetime.datetime):
             self.assertEqual(
                 datetime.datetime.strptime(jsonDecoded[attrib],
                                            Exercise.DATEFMT), value)
         else:
             self.assertEqual(jsonDecoded[attrib], value)
     for attrib in jsonDecoded:
         assert attrib in exercise
Exemple #7
0
 def testRepositoryOperations(self):
     """Adds and removes exercises and checks the history."""
     numExercises = len(glob.glob(join(exdb.repo.repoPath(), "exercises", "*", "*.xml" )))
     self.assertEqual(len(exdb.sql.exercises()), numExercises)
     exes = exdb.sql.exercises()
     self.assertEqual(set(ex.creator for ex in exes), set(("jensmander", "foobar")))
     self.assertTrue(all(ex.number == 1 for ex in exes))
     
     exercise = Exercise.fromXMLFile(dataPath("jemand1.xml"))
     exercise.number = None
     exdb.addExercise(exercise, {})
     self.assertEqual(exercise.number, 1)
     self.assertEqual(len(exdb.sql.exercises()), numExercises+1)
     exdb.removeExercise("jensmander", 1)
     self.assertEqual(len(exdb.sql.exercises()), numExercises)
     exes = exdb.sql.exercises()
     self.assertNotIn("jensmander", (ex.creator for ex in exes))
     history = exdb.repo.history()
     self.assertEqual(history[0]["author"], "jensmander")
     self.assertEqual(history[0]["action"], "REMOVE")
     self.assertEqual(history[1]["action"], "ADD")
Exemple #8
0
 def test_xmlExport(self):
     self.maxDiff = None
     self.assertEqual(Exercise.fromXMLString(validXML.encode('utf-8')).toXML(),
                      validXML)
Exemple #9
0
 def test_importTooRecentSchema(self):
     invalidXML = validXML.replace('schemaversion="2"', 'schemaversion="1000"')
     self.assertRaises(VersionMismatchError,
                       lambda : Exercise.fromXMLString(invalidXML.encode('utf-8')))
Exemple #10
0
 def test_MissingExerciseTex(self):
     import lxml
     self.assertRaises(lxml.etree.XMLSyntaxError,
                       lambda : Exercise.fromXMLFile(dataPath("invalid14.xml")))
Exemple #11
0
 def test_readPlainXML(self):
     self.assertTrue(Exercise.fromXMLFile(dataPath("noschemaandencoding.xml")))
Exemple #12
0
 def test_readPlainXML(self):
     self.assertTrue(
         Exercise.fromXMLFile(dataPath("noschemaandencoding.xml")))
Exemple #13
0
 def test_importTooRecentSchema(self):
     invalidXML = validXML.replace('schemaversion="2"',
                                   'schemaversion="1000"')
     self.assertRaises(
         VersionMismatchError,
         lambda: Exercise.fromXMLString(invalidXML.encode('utf-8')))
Exemple #14
0
def loadFromXML(creator, number):
    from exdb.exercise import Exercise
    return Exercise.fromXMLFile(xmlPath(creator=creator, number=number))
Exemple #15
0
def loadFromXML(creator, number):
    from exdb.exercise import Exercise
    return Exercise.fromXMLFile(xmlPath(creator=creator, number=number))
Exemple #16
0
 def test_xmlExport(self):
     self.maxDiff = None
     self.assertEqual(
         Exercise.fromXMLString(validXML.encode('utf-8')).toXML(), validXML)
Exemple #17
0
 def test_MissingExerciseTex(self):
     import lxml
     self.assertRaises(
         lxml.etree.XMLSyntaxError,
         lambda: Exercise.fromXMLFile(dataPath("invalid14.xml")))