def test_save_and_refresh(self): c = Class("myclass", "A class", "an institution", "*****@*****.**", "password", self.user, qclass=999999) with self.assertRaises(NotSavedError): c.save() with self.assertRaises(NotSavedError): c.refresh() c.save(WIMS_URL, "myself", "toto") c = Class.get(WIMS_URL, "myself", "toto", 999999, "myclass") c2 = Class.get(WIMS_URL, "myself", "toto", 999999, "myclass") self.assertEqual(c.institution, "an institution") self.assertEqual(c2.institution, "an institution") c.institution = "modified" c.save() self.assertEqual(c.institution, "modified") self.assertEqual(c2.institution, "an institution") c2.refresh() self.assertEqual(c2.institution, "modified") self.api.delclass(99999999, "myclass")
def test_init_and_properties(self): c = Class.get(WIMS_URL, "myself", "toto", 9001, "myclass") u = User.get(c, "supervisor") self.assertIn("firstname", u.infos) u = User("supervisor", "last", "first", "pass", "*****@*****.**") self.assertEqual(u.fullname, "First Last") with self.assertRaises(NotSavedError): u.infos
def test_delete(self): c = Class("myclass", "A class", "an institution", "*****@*****.**", "password", self.user, qclass=999999) with self.assertRaises(NotSavedError): c.delete() c.save(WIMS_URL, "myself", "toto") Class.get(WIMS_URL, "myself", "toto", c.qclass, c.rclass) # Ok c.delete() with self.assertRaises(AdmRawError): Class.get(WIMS_URL, "myself", "toto", c.qclass, c.rclass) # Should raise the exception
def test_init_and_properties(self): c = Class.get(WIMS_URL, "myself", "toto", 9001, "myclass") self.assertEqual(c.url, WIMS_URL) self.assertEqual(c.ident, "myself") self.assertEqual(c.passwd, "toto") self.assertIn("description", c.infos) c = Class("myclass", "A class", "an institution", "*****@*****.**", "password", self.user, qclass=999999) with self.assertRaises(NotSavedError): c.url with self.assertRaises(NotSavedError): c.ident with self.assertRaises(NotSavedError): c.passwd with self.assertRaises(NotSavedError): c.infos with self.assertRaises(ValueError): Class("myclass", "A class", "an institution", "*****@*****.**", "password", self.user, qclass=999999, lang="Wrong") with self.assertRaises(ValueError): Class("myclass", "A class", "an institution", "*****@*****.**", "password", self.user, qclass=999999, level="Wrong") with self.assertRaises(ValueError): Class("myclass", "A class", "an institution", "*****@*****.**", "password", self.user, qclass=999999, expiration="Wrong")
def test_eq(self): c1 = Class("rclass", "A class", "an institution", "*****@*****.**", "password", self.user) c2 = Class("rclass", "A class", "an institution", "*****@*****.**", "password", self.user) c3 = Class("rclass", "A class", "an institution", "*****@*****.**", "password", self.user) with self.assertRaises(NotSavedError): c1 == c3 c1.save(WIMS_URL, "myself", "toto") c2.save(WIMS_URL, "myself", "toto") c3.save(WIMS_URL, "myself", "toto") self.assertEqual( c1, Class.get(WIMS_URL, "myself", "toto", c1.qclass, c1.rclass)) self.assertNotEqual( c2, Class.get(WIMS_URL, "myself", "toto", c1.qclass, c1.rclass)) self.assertNotEqual(c2, 1) c1.delete() c2.delete() c3.delete()
def test_scores(self): # Put a dummy class with existing scores if not already added qclass = 6948902 if not Class.check(self.api.url, self.api.ident, self.api.passwd, qclass, "myclass"): archive = os.path.join(os.path.dirname(__file__), "resources/6948902.tgz") command("docker cp %s wims-minimal:/home/wims/log/classes/" % archive) command('docker exec wims-minimal bash -c ' '"tar -xzf /home/wims/log/classes/6948902.tgz -C /home/wims/log/classes/"' ) command( 'docker exec wims-minimal bash -c "chmod 644 /home/wims/log/classes/6948902/.def"' ) command( 'docker exec wims-minimal bash -c ' '"chown wims:wims /home/wims/log/classes/6948902 -R"' ) command('docker exec wims-minimal bash -c "rm /home/wims/log/classes/6948902.tgz"') command( "docker exec wims-minimal bash -c " "\"echo ':6948902,20200626,Institution,test,en,0,H4,dmi,S S,+myself/myclass+,' " '>> /home/wims/log/classes/.index"' ) with self.assertRaises(NotSavedError): Sheet().scores() c = Class.get(self.api.url, self.api.ident, self.api.passwd, qclass, "myclass") s1 = c.getitem(1, Sheet) s2 = c.getitem(2, Sheet) u = c.getitem("qcoumes", User) es1_1 = ExerciseScore(None, u, 3.3, 10, 10, 10, 0, 10, 1, 3) ss1 = SheetScore(s1, u, 7.17, 3.3, 100, 100, 100, 1, [es1_1]) es2_1 = ExerciseScore(None, u, 4.59, 10, 10, 10, 0, 10, 1, 2) es2_2 = ExerciseScore(None, u, 5.41, 10, 10, 10, 10, 10, 1, 2) ss2 = SheetScore(s2, u, 8.12, 5, 100, 100, 100, 1, [es2_1, es2_2]) self.assertEqual(s1.scores("qcoumes"), ss1) self.assertEqual(s1.scores(), [ss1]) self.assertEqual(s2.scores("qcoumes"), ss2) self.assertEqual(s2.scores(), [ss2]) with self.assertRaises(ValueError): s1.scores("unknown")
def test_append_slash(self): url = WIMS_URL if not WIMS_URL.endswith('/') else WIMS_URL[:-1] c = Class.get(url, "myself", "toto", 9001, "myclass") self.assertEqual(c.url, url + "/")