Exemplo n.º 1
0
class UserRegisterAPITest(CaptchaTest):
    def setUp(self):
        self.client = APIClient()
        self.register_url = self.reverse("user_register_api")
        # self.captcha = rand_str(4)

        self.data = {
            "username": "******",
            "password": "******",
            "real_name": "real_name",
            "email": "*****@*****.**",
        }
        #  "captcha": self._set_captcha(self.client.session)}

    def test_website_config_limit(self):
        SysOptions.allow_register = False
        resp = self.client.post(self.register_url, data=self.data)
        self.assertDictEqual(
            resp.data, {
                "error": "error",
                "data": "Register function has been disabled by admin"
            })

    # def test_invalid_captcha(self):
    #     self.data["captcha"] = "****"
    #     response = self.client.post(self.register_url, data=self.data)
    #     self.assertDictEqual(response.data, {"error": "error", "data": "Invalid captcha"})

    #     self.data.pop("captcha")
    #     response = self.client.post(self.register_url, data=self.data)
    #     self.assertTrue(response.data["error"] is not None)

    def test_register_with_correct_info(self):
        response = self.client.post(self.register_url, data=self.data)
        self.assertDictEqual(response.data, {
            "error": None,
            "data": "Succeeded"
        })

    def test_username_already_exists(self):
        self.test_register_with_correct_info()

        # self.data["captcha"] = self._set_captcha(self.client.session)
        self.data["email"] = "*****@*****.**"
        response = self.client.post(self.register_url, data=self.data)
        self.assertDictEqual(response.data, {
            "error": "error",
            "data": "Username already exists"
        })

    def test_email_already_exists(self):
        self.test_register_with_correct_info()

        # self.data["captcha"] = self._set_captcha(self.client.session)
        self.data["username"] = "******"
        response = self.client.post(self.register_url, data=self.data)
        self.assertDictEqual(response.data, {
            "error": "error",
            "data": "Email already exists"
        })
Exemplo n.º 2
0
    def setUp(self):
        self.client = APIClient()
        self.register_url = self.reverse("user_register_api")
        self.captcha = rand_str(4)

        self.data = {"username": "******", "password": "******","classNum": "1822107",
                     "real_name": "real_name", "email": "*****@*****.**",
                     "captcha": self._set_captcha(self.client.session)}
Exemplo n.º 3
0
    def setUp(self):
        self.client = APIClient()
        self.register_url = self.reverse("user_register_api")
        # self.captcha = rand_str(4)

        self.data = {
            "username": "******",
            "password": "******",
            "real_name": "real_name",
            "email": "*****@*****.**",
        }