Exemplo n.º 1
0
    # User should be redirected to login.
    def testNoLogin(self):
        self.sudo('*****@*****.**')
        self.assertStatusCode(302)

    def testLoginToSudo(self):
        self.login('admin')
        self.sudo('*****@*****.**')
        self.assertStatusCode(200)
        self.logout()

    def testStudentAttemptToSudo(self):
        self.login('student1')
        self.sudo('*****@*****.**')
        self.assertStatusCode(404)

    def testNonExistantStudent(self):
        self.login('admin')
        self.sudo('*****@*****.**')
        self.assertStatusCode(404)

    def testCheckStudent2(self):
        self.login('staff')
        self.sudo('*****@*****.**')
        self.assertStatusCode(404)


if __name__ == "__main__":
    unittest.main()
Exemplo n.º 2
0
        if model == "User":
            subj = obj = self.accounts[obj_name]
        elif model == "Message":
            obj = self.backups[obj_name]
            subj = obj.messages[0]
        else:
            subj = obj = getattr(self, model.lower()+'s')[obj_name]

        if not obj:
            self.assertTrue(False, "Invalid test arguments %s" % model)

        if need == "index":
            query = obj.__class__.query() #pylint: disable=maybe-no-member
            query = obj.can(self.user, Need(need), obj, query=query)

            if not query:
                self.assertFalse(value.output, "|can| method returned false.")
                return

            queried_data = query.fetch()

            if value.output:
                self.assertIn(obj, queried_data)
            else:
                self.assertNotIn(obj, queried_data)
        else:
            self.assertEqual(value.output, subj.can(self.user, Need(need), obj))

if __name__ == "__main__":
    unittest.main()