예제 #1
0
    def test_listitem(self):
        c = Class("rclass",
                  "A class",
                  "an institution",
                  "*****@*****.**",
                  "password",
                  self.user,
                  qclass=999999)

        with self.assertRaises(NotSavedError):
            c.listitem(Sheet)
        with self.assertRaises(InvalidItemTypeError):
            c.listitem(int)

        s1 = Sheet("First", "First one")
        s2 = Sheet("Second", "Second one")
        s3 = Sheet("Third", "Third one")

        c.save(WIMS_URL, "myself", "toto")

        self.assertListEqual([], c.listitem(Sheet))

        c.additem(s1)
        c.additem(s2)
        c.additem(s3)

        self.assertListEqual(sorted([s1, s2, s3], key=lambda i: i.qsheet),
                             sorted(c.listitem(Sheet), key=lambda i: i.qsheet))

        c.delete()
예제 #2
0
    def test_delitem(self):
        c = Class("myclass",
                  "A class",
                  "an institution",
                  "*****@*****.**",
                  "password",
                  self.user,
                  qclass=999999)
        u = User("quser", "last", "first", "pass", "*****@*****.**")
        u2 = User("quser2", "last", "first", "pass", "*****@*****.**")

        with self.assertRaises(NotSavedError):
            c.delitem(u)
        with self.assertRaises(InvalidItemTypeError):
            c.delitem(int)

        c.save(WIMS_URL, "myself", "toto")
        c.additem(u)
        c.additem(u2)

        self.assertTrue(c.checkitem("quser", User))
        c.delitem(u)
        self.assertFalse(c.checkitem("quser", User))

        self.assertTrue(c.checkitem("quser2", User))
        c.delitem("quser2", User)
        self.assertFalse(c.checkitem("quser2", User))
예제 #3
0
    def test_save_without_qclass(self):
        c = Class("myclass", "A class", "an institution", "*****@*****.**",
                  "password", self.user)

        with self.assertRaises(NotSavedError):
            c.save()

        c.save(WIMS_URL, "myself", "toto")
        self.assertIsNotNone(c.qclass)
        c.delete()
예제 #4
0
    def test___contains__(self):
        c = Class("myclass",
                  "A class",
                  "an institution",
                  "*****@*****.**",
                  "password",
                  self.user,
                  qclass=999999)
        unknown = User("unknown", "last", "first", "pass", "*****@*****.**")

        with self.assertRaises(NotSavedError):
            unknown in c

        c.save(WIMS_URL, "myself", "toto")
        self.assertTrue(self.user in c)
        self.assertFalse(unknown in c)
예제 #5
0
    def test_getitem(self):
        c = Class("myclass",
                  "A class",
                  "an institution",
                  "*****@*****.**",
                  "password",
                  self.user,
                  qclass=999999)

        with self.assertRaises(NotSavedError):
            c.getitem("supervisor", User)
        with self.assertRaises(InvalidItemTypeError):
            c.getitem(1, int)

        c.save(WIMS_URL, "myself", "toto")
        user = c.getitem("supervisor", User)
        self.assertEqual(user.firstname, self.user.firstname)
예제 #6
0
    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
예제 #7
0
    def test_checkitem(self):
        c = Class("myclass",
                  "A class",
                  "an institution",
                  "*****@*****.**",
                  "password",
                  self.user,
                  qclass=999999)
        unknown = User("unknown", "last", "first", "pass", "*****@*****.**")

        with self.assertRaises(NotSavedError):
            c.checkitem("supervisor", User)
        with self.assertRaises(InvalidItemTypeError):
            c.checkitem(1)

        c.save(WIMS_URL, "myself", "toto")
        self.assertTrue(c.checkitem("supervisor", User))
        self.assertTrue(c.checkitem(self.user))
        self.assertFalse(c.checkitem("Unknown", User))
        self.assertFalse(c.checkitem(unknown))
예제 #8
0
    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")
예제 #9
0
    def test_additem(self):
        c = Class("myclass",
                  "A class",
                  "an institution",
                  "*****@*****.**",
                  "password",
                  self.user,
                  qclass=999999)
        u = User("quser", "last", "first", "pass", "*****@*****.**")

        with self.assertRaises(NotSavedError):
            c.additem(u)
        with self.assertRaises(InvalidItemTypeError):
            c.additem(int)

        c.save(WIMS_URL, "myself", "toto")
        c.additem(u)
        self.assertEqual(u._class.qclass, c.qclass)
        self.assertEqual(u.wclass, True)

        u2 = c.getitem("quser", User)
        self.assertEqual(u2.firstname, u.firstname)
예제 #10
0
    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()
예제 #11
0
    def test_list(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)

        c1.save(WIMS_URL, "myself", "toto")
        c2.save(WIMS_URL, "myself", "toto")
        c3.save(WIMS_URL, "myself", "toto")

        self.assertListEqual(
            sorted([c1, c2, c3], key=lambda i: i.qclass),
            sorted(Class.list(WIMS_URL, "myself", "toto", "rclass"),
                   key=lambda i: i.qclass))

        self.assertListEqual([],
                             Class.list(WIMS_URL, "myself", "toto",
                                        "unknown_rclass"))

        c1.delete()
        c2.delete()
        c3.delete()