Ejemplo n.º 1
0
 def switch_to_user_role(self, role: UserKind):
     for user_id in self.user_map:
         if self.user_map[user_id].role == role:
             active_user = self.user_map[user_id]
     login_request = LoginRequest(active_user.username, "kerflaag")
     response = self.simulate_post("/auth/token",
                                   json=login_request.to_json())
     self.assertEqual(response.status, falcon.HTTP_200)
     login_response = LoginResponse.from_json(response.json)
     self.current_token = login_response.token
     return login_response
Ejemplo n.º 2
0
    def test_can_create_users(self):
        n = NewUserRequest("staff", "*****@*****.**", UserKind.STAFF, "kerflaag")
        response = self.simulate_post("/auth/users", json=n.to_json())
        self.assertEqual(response.status, falcon.HTTP_201)

        login_request = LoginRequest("staff", "kerflaag")
        response = self.simulate_post("/auth/token",
                                      json=login_request.to_json())
        self.assertEqual(response.status, falcon.HTTP_200)
        login_response = LoginResponse.from_json(response.json)

        self.assertTrue(login_response.password_reset_needed)
Ejemplo n.º 3
0
    def test_admin_can_reset_user_password(self):
        current_id = [
            x for x in self.user_map
            if self.user_map[x].role != UserKind.ADMINISTRATOR
        ][0]
        password_change = {"newPassword": "******"}

        response = self.simulate_put(
            "/auth/users/{}/password".format(current_id), json=password_change)
        self.assertEqual(response.status, falcon.HTTP_202)

        current_user = self.user_map[current_id]
        login_request = LoginRequest(current_user.username, "Blarg")
        response = self.simulate_post("/auth/token",
                                      json=login_request.to_json())
        login_response = LoginResponse.from_json(response.json)
        self.assertTrue(login_response.password_reset_needed)
Ejemplo n.º 4
0
 def test_from_json(self):
     ref = {"token": "blasdfasdf", "passwordResetNeeded": True}
     n = LoginResponse.from_json(ref)
     self.assertEqual(n.token, "blasdfasdf")
     self.assertTrue(n.password_reset_needed)