Beispiel #1
0
    def test_is_logged_in(self):
        fake_username = "******"
        fake_password = "******"

        api = cunyfirstapi.CUNYFirstAPI(fake_username, fake_password)
        session = api.get_current_session()
        self.assertFalse(api.is_logged_in(session))
        self.assertFalse(api.is_logged_in())
        api.login()

        # Invalid credentials were passed in
        # user should still not be logged in
        self.assertFalse(api.is_logged_in())
        self.assertFalse(api.is_logged_in(session))

        if is_ci():
            global username
            global password
            api2 = cunyfirstapi.CUNYFirstAPI(username, password)
            session = api.get_current_session()

            self.assertFalse(api2.is_logged_in(session))
            self.assertFalse(api2.is_logged_in())
            api2.login()

            # valid credentials were passed in
            # user should be logged in
            self.assertTrue(api2.is_logged_in(session))
            self.assertTrue(api2.is_logged_in())
Beispiel #2
0
def main():
    args = parse()
    try:
        username = input(
            "Enter username: "******"Enter password: "******"Enter phone number: ") if not args.phone else args.phone
        prod = False if not args.prod else True

        api = cunyfirstapi.CUNYFirstAPI(username, password)
        api.login()
        if api.is_logged_in():
            run(username, password, args.school.upper(), number)
            print_to_screen(
                "Check your phone for a text!\n" \
                + "The service will check for new grades every 5 min and text you when anything changes.\n" \
                + "The service will continue for 5 days and then require you to sign-in again.\n" \
                + "Please only sign in once.\n" \
                + "Enjoy!",
                "ok",
                "Hold Tight!",
            )
        else:
            print_to_screen(
                "The username/password combination you entered seems to be invalid.\n" \
                + "Please try again.",
                "error",
                "Oh No!",
            )

    except Exception as e:
        print(str(e))
Beispiel #3
0
    def test_restart_session(self):
        fake_username = "******"
        fake_password = "******"
        api = cunyfirstapi.CUNYFirstAPI(fake_username, fake_password)

        first_session = api.get_current_session()
        api.restart_session()
        second_session = api.get_current_session()

        self.assertIsNotNone(first_session)
        self.assertIsNotNone(second_session)
        self.assertNotEqual(first_session, second_session)
Beispiel #4
0
def main():
    args = parse()
    try:
        username = input(
            "Enter username: "******"Enter password: "******"Enter phone number: ") if not args.phone else args.phone
        prod = False if not args.prod else True

        username = re.sub(r'@login\.cuny\.edu', '', username).lower()
        if user_exists(username, args.school.upper()):
            print_to_screen(
                "Seems that you already have a session running.\n" \
                + "If you think there is a mistake, contact me @ [email protected]",
                "error",
                "Oh No!",
            )
            return

        password = decrypt(encrypted_password,
                           '../../private/keys/private.pem')

        api = cunyfirstapi.CUNYFirstAPI(username, password)
        api.login()
        if api.is_logged_in():
            add_to_db(username, encrypted_password, args.school.upper(),
                      number)
            print_to_screen(
                "Check your phone for a text!\n" \
                + "The service will check for new grades every 30 min and text you when anything changes.\n" \
                + "The service will continue for 2 weeks and then require you to sign-in again.\n" \
                + "Please only sign in once.\n" \
                + "Enjoy!",
                "ok",
                "Hold Tight!",
            )

            api.logout()
        else:
            print_to_screen(
                "The username/password combination you entered seems to be invalid.\n" \
                + "Please try again.",
                "error",
                "Oh No!",
            )

    except Exception as e:
        traceback.print_exc()
Beispiel #5
0
def main():
    args = parse()
    try:
        username = input(
            "Enter username: "******"Enter password: "******"Enter phone number: ") if not args.phone else args.phone
        prod = False if not args.prod else True

        state = LoginState.determine_state(args)
        if(check_user_exists(username, state)):
            print_to_screen(
                "Seems that you already have a session running.\n" \
                + "If you think there is a mistake, contact me @ [email protected]",
                "error",
                "Oh No!",
            )
            return

        api = cunyfirstapi.CUNYFirstAPI(username, password)
        api.login()
        if api.is_logged_in():
            run(username, password, args.school.upper(), number)
            print_to_screen(
                "Check your phone for a text!\n" \
                + "The service will check for new grades every 30 min and text you when anything changes.\n" \
                + "The service will continue for 2 weeks and then require you to sign-in again.\n" \
                + "Please only sign in once.\n" \
                + "Enjoy!",
                "ok",
                "Hold Tight!",
            )
        else:
            print_to_screen(
                "The username/password combination you entered seems to be invalid.\n" \
                + "Please try again.",
                "error",
                "Oh No!",
            )

    except Exception as e:
        print(str(e))
Beispiel #6
0
 def test_get_session(self):
     fake_username = "******"
     fake_password = "******"
     api = cunyfirstapi.CUNYFirstAPI(fake_username, fake_password)
     self.assertIsNotNone(api.get_current_session())
Beispiel #7
0
 def test_api_init(self):
     fake_username = "******"
     fake_password = "******"
     api = cunyfirstapi.CUNYFirstAPI(fake_username, fake_password)
     self.assertEqual(api._username, fake_username)
     self.assertEqual(api._password, fake_password)