コード例 #1
0
    def test_add_to_watchlist_success(self, symbol):
        """A user can add a share to their watchlist"""
        global displayName, email, password

        expected_response_code = 201
        symbol = symbol

        authentication_response = ApiFacade.authenticate_user(email, password)
        token = authentication_response.get_token()

        # get watchlist id
        viewdetails_response = ApiFacade.view_details(token)
        watchlist_id = viewdetails_response.get_main_watchlist_id()

        # add symbol to watchlist
        addtowatchlist_response = ApiFacade.add_to_watchlist(
            token, watchlist_id, symbol)

        # get updated watchlist
        viewwatchlist_response = ApiFacade.get_watchlist(token, watchlist_id)

        # check request went through
        self.assertEqual(addtowatchlist_response.get_http_status(),
                         expected_response_code,
                         msg="Expected HTTP{0}; got HTTP{1}".format(
                             expected_response_code,
                             addtowatchlist_response.get_http_status()))

        # check watchlist has been updated
        self.assertIsNotNone(
            viewwatchlist_response.get_share_by_symbol(symbol),
            msg=
            "Expected updated watchlist to contain {0} symbol {1}; got {2} match"
            .format(1, symbol, str(None)))
コード例 #2
0
    def test_get_watchlist_success(self):
        expected_response_code = 200
        expected_keys_in_share = [
            "symbol", "name", "lastPrice", "change", "changePercent"
        ]

        displayName, email, password = ("John Doe", "*****@*****.**",
                                        "12345678")
        registration_response = ApiFacade.register_user(
            displayName, email, password)
        authentication_response = ApiFacade.authenticate_user(email, password)
        token = authentication_response.get_token()

        # get watchlist id
        viewdetails_response = ApiFacade.view_details(token)
        watchlist_id = viewdetails_response.get_main_watchlist_id()

        # buy shares first
        viewwatchlist_response = ApiFacade.get_watchlist(token, watchlist_id)

        deletion_response = ApiFacade.delete_user(token)

        self.assertEqual(viewwatchlist_response.get_http_status(),
                         expected_response_code,
                         msg="Expected HTTP{0}; got HTTP{1}".format(
                             expected_response_code,
                             viewwatchlist_response.get_http_status()))

        for share in viewwatchlist_response.get_all_shares():
            for k in expected_keys_in_share:
                self.assertIsNotNone(
                    share[k],
                    msg="Expected value for key [{0}]; got [{1}]".format(
                        str(k), str(None)))