示例#1
0
def vanguard_current_holdings():
    try:
        user = auth()
    except AuthenticationFailed:
        return rAuthError

    try:
        vanguard_user = VanguardUser(user)
    except KeyError:
        return rNotEnrolled

    res = None
    try:
        v = Vanguard()
        v.login(vanguard_user.username, vanguard_user.password)
        question = v.get_security_question()
        answer = vanguard_user.security_questions.get(question)
        v.answer_security_question(answer)

        current_holdings = v.get_current_holdings()
    finally:
        v.close_browser()
        if len(current_holdings) == 0:
            return rInternalServerError

    return jsonify(current_holdings)
示例#2
0
def vanguard_total_assets():
    try:
        user = auth()
    except AuthenticationFailed:
        return rAuthError

    try:
        vanguard_user = VanguardUser(user)
    except KeyError:
        return rNotEnrolled

    res = None
    try:
        v = Vanguard()
        v.login(vanguard_user.username, vanguard_user.password)
        question = v.get_security_question()
        answer = vanguard_user.security_questions.get(question)
        v.answer_security_question(answer)

        total_assets = v.get_total_assets()
        res = dict(total=total_assets)
    finally:
        v.close_browser()
        if res is None:
            return rInternalServerError

    return jsonify(res)
示例#3
0
def vanguard_current_holdings():
    try:
        user = auth()
    except AuthenticationFailed:
        return rAuthError

    try:
        vanguard_user = VanguardUser(user)
    except KeyError:
        return rNotEnrolled

    res = None
    try:
        v = Vanguard()
        v.login(vanguard_user.username, vanguard_user.password)
        question = v.get_security_question()
        answer = vanguard_user.security_questions.get(question)
        v.answer_security_question(answer)

        current_holdings = v.get_current_holdings()
        res = dict(current_holdings=current_holdings)
    finally:
        v.close_browser()
        if res is None:
            return rInternalServerError

    return jsonify(res)
示例#4
0
class TestBrowser(TestCase):
    def setUp(self):
        self.v = Vanguard()

    def tearDown(self):
        self.v.close_browser()

    def test_can_login(self):
        self.v.login(tests_config.TEST_USER, tests_config.TEST_PASSWORD)

    def test_can_get_security_question(self):
        self.v.login(tests_config.TEST_USER, tests_config.TEST_PASSWORD)
        question = self.v.get_security_question()

    def test_can_answer_security_question(self):
        self.v.login(tests_config.TEST_USER, tests_config.TEST_PASSWORD)
        question = self.v.get_security_question()

        answer = tests_config.TEST_SECURITY_QUESTIONS.get(question)
        self.assertIsNotNone(answer)

        self.v.answer_security_question(answer)

    def test_can_go_to_balances_and_holdings(self):
        self.v.login(tests_config.TEST_USER, tests_config.TEST_PASSWORD)

        question = self.v.get_security_question()
        answer = tests_config.TEST_SECURITY_QUESTIONS.get(question)
        self.v.answer_security_question(answer)

        self.v.go_to_balances_and_holdings()
        self.assertEqual(self.v.browser.title, "Balances and holdings")

    def test_can_get_total_assets(self):
        self.v.login(tests_config.TEST_USER, tests_config.TEST_PASSWORD)

        question = self.v.get_security_question()
        answer = tests_config.TEST_SECURITY_QUESTIONS.get(question)
        self.v.answer_security_question(answer)

        self.v.get_total_assets()

    def test_can_get_current_holdings(self):
        self.v.login(tests_config.TEST_USER, tests_config.TEST_PASSWORD)

        question = self.v.get_security_question()
        answer = tests_config.TEST_SECURITY_QUESTIONS.get(question)
        self.v.answer_security_question(answer)

        self.v.get_current_holdings()
示例#5
0
class TestBrowser(TestCase):
    def setUp(self):
        self.v = Vanguard()

    def tearDown(self):
        self.v.close_browser()

    def test_can_login(self):
        self.v.login(tests_config.TEST_USER, tests_config.TEST_PASSWORD)

    def test_can_get_security_question(self):
        self.v.login(tests_config.TEST_USER, tests_config.TEST_PASSWORD)
        question = self.v.get_security_question()

    def test_can_answer_security_question(self):
        self.v.login(tests_config.TEST_USER, tests_config.TEST_PASSWORD)
        question = self.v.get_security_question()

        answer = tests_config.TEST_SECURITY_QUESTIONS.get(question)
        self.assertIsNotNone(answer)

        self.v.answer_security_question(answer)

    def test_can_go_to_balances_and_holdings(self):
        self.v.login(tests_config.TEST_USER, tests_config.TEST_PASSWORD)

        question = self.v.get_security_question()
        answer = tests_config.TEST_SECURITY_QUESTIONS.get(question)
        self.v.answer_security_question(answer)

        self.v.go_to_balances_and_holdings()
        self.assertEqual(self.v.browser.title, "Balances and holdings")

    def test_can_get_total_assets(self):
        self.v.login(tests_config.TEST_USER, tests_config.TEST_PASSWORD)

        question = self.v.get_security_question()
        answer = tests_config.TEST_SECURITY_QUESTIONS.get(question)
        self.v.answer_security_question(answer)

        self.v.get_total_assets()

    def test_can_get_current_holdings(self):
        self.v.login(tests_config.TEST_USER, tests_config.TEST_PASSWORD)

        question = self.v.get_security_question()
        answer = tests_config.TEST_SECURITY_QUESTIONS.get(question)
        self.v.answer_security_question(answer)

        self.v.get_current_holdings()