def test_buy_shares_success(self):
        """A user can buy shares if balance is sufficient"""
        expected_response_code = 200
        symbol_to_buy = "ANZ"
        quantity = 100

        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 account id
        viewdetails_response = ApiFacade.view_details(token)
        account_id = viewdetails_response.get_main_account_id()

        buyshare_response = ApiFacade.buy_share(token, account_id,
                                                symbol_to_buy, quantity)

        deletion_response = ApiFacade.delete_user(token)

        self.assertEqual(buyshare_response.get_http_status(),
                         expected_response_code,
                         msg="Expected HTTP{0}; got HTTP{1}".format(
                             expected_response_code,
                             buyshare_response.get_http_status()))
Exemplo n.º 2
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)))
Exemplo n.º 3
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)))
    def test_sell_shares_success(self):
        """An authenticated user can sell shares that they own"""
        expected_response_code = 200
        symbol = "DDD"
        quantity = 100

        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 account id
        viewdetails_response = ApiFacade.view_details(token)
        account_id = viewdetails_response.get_main_account_id()

        # buy shares first
        buyshare_response = ApiFacade.buy_share(token, account_id, symbol,
                                                int(quantity))

        # sell the shares
        sellshare_response = ApiFacade.sell_share(token, account_id, symbol,
                                                  int(quantity / 3))

        deletion_response = ApiFacade.delete_user(token)

        self.assertEqual(sellshare_response.get_http_status(),
                         expected_response_code,
                         msg="Expected HTTP{0}; got HTTP{1}".format(
                             expected_response_code,
                             sellshare_response.get_http_status()))
	def test_viewDetails_success(self):
		"""An authenticated user can view their user account details"""
		expected_response_code = 200
		displayName, email, password, level = ("John Doe", "*****@*****.**", "12345678", "Investor")
		number_of_accounts, number_of_watchlists = (1, 1)

		registration_response = ApiFacade.register_user(displayName, email, password)
		authentication_response = ApiFacade.authenticate_user(email, password)
		viewdetails_response = ApiFacade.view_details(authentication_response.get_token())
		deletion_response = ApiFacade.delete_user(authentication_response.get_token())

		self.assertEqual(viewdetails_response.get_http_status(), expected_response_code, 
			msg = "Expected HTTP{0}; got HTTP{1}".format(expected_response_code, viewdetails_response.get_http_status()))
		
		self.assertEqual(viewdetails_response.get_displayName(), displayName,
			msg = "Expected displayName = {0}; got displayName = {1}".format(displayName, viewdetails_response.get_displayName()))
		
		self.assertEqual(viewdetails_response.get_email(), email,
			msg = "Expected email = {0}; got email = {1}".format(email, viewdetails_response.get_email()))
		
		self.assertEqual(viewdetails_response.get_level(), level,
			msg = "Expected level = {0}; got level = {1}".format(level, viewdetails_response.get_level()))
		
		self.assertEqual(len(viewdetails_response.get_accounts()), number_of_accounts,
			msg = "Expected len(accounts) = {0}; got len(accounts) = {1}"
			.format(number_of_accounts, len(viewdetails_response.get_accounts())))

		self.assertEqual(len(viewdetails_response.get_watchlists()), number_of_watchlists,
			msg = "Expected len(watchlists) = {0}; got len(watchlists) = {1}"
			.format(number_of_watchlists, len(viewdetails_response.get_watchlists())))
    def test_view_portfolio_success(self):
        """An authenticated user can sell shares that they own"""
        expected_response_code = 200
        expected_keys = ["id", "name", "balance", "positions"]
        symbol = "DDD"
        quantity = 100

        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 account id
        viewdetails_response = ApiFacade.view_details(token)
        account_id = viewdetails_response.get_main_account_id()

        # buy shares first
        portfolio_response = ApiFacade.get_portfolio(token, account_id)

        deletion_response = ApiFacade.delete_user(token)

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

        for k in expected_keys:
            self.assertEqual(k in portfolio_response.get_json_body(),
                             True,
                             msg="Expected key [{0}]; got [{1}]".format(
                                 k, str(None)))
    def test_view_transactions_success(self):
        """An authenticated user can sell shares that they own"""
        expected_response_code = 200
        expected_keys = [
            "items", "pageNumber", "pageSize", "totalPageCount",
            "totalRowCount"
        ]
        symbol = "DDD"
        quantity = 100

        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 account id
        viewdetails_response = ApiFacade.view_details(token)
        account_id = viewdetails_response.get_main_account_id()

        # buy a share
        buyshare_response = ApiFacade.buy_share(token, account_id, symbol,
                                                quantity)

        # buy shares first
        transactions_response = ApiFacade.get_transactions(token,
                                                           account_id,
                                                           page_number=None,
                                                           page_size=None,
                                                           start_date=None,
                                                           end_date=None)

        deletion_response = ApiFacade.delete_user(token)

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

        for k in expected_keys:
            self.assertEqual(k in transactions_response.get_json_body(),
                             True,
                             msg="Expected key [{0}]; got [{1}]".format(
                                 k, str(None)))

        #pprint(transactions_response.get_items())

        self.assertEqual(
            len(transactions_response.get_items()),
            4,
            msg="Expected {0} item in response; got {1} instead".format(
                1, len(transactions_response.get_items())))
	def test_deletion_userIsNotAuthenticated(self):
		"""An unauthenticated user cannot delete their user account"""
		expected_response_code = 401
		expected_response_body = None

		viewdetails_response = ApiFacade.view_details(token = None)

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

		self.assertEqual(viewdetails_response.get_json_body(), expected_response_body, 
			msg = "Expected body = {0}; got body = {1}".format(expected_response_body, viewdetails_response.get_json_body()))
Exemplo n.º 9
0
    def test_edit_user_success(self):
        """A user can edit their profile with valid details"""
        expected_messages = [None]
        expected_response_code = 204
        displayName, email, password = ("John Doe", "*****@*****.**",
                                        "12345678")
        new_displayName, new_email = ("Edited John", "*****@*****.**")

        register_response = ApiFacade.register_user(displayName, email,
                                                    password)
        authentication_response = ApiFacade.authenticate_user(email, password)
        token = authentication_response.get_token()
        edituser_response = ApiFacade.edit_user(token, new_displayName,
                                                new_email)
        viewdetails_response = ApiFacade.view_details(token)
        deletion_response = ApiFacade.delete_user(
            authentication_response.get_token())

        response_status_match = edituser_response.get_http_status(
        ) == expected_response_code

        self.assertEqual(
            response_status_match,
            True,
            msg="Expected HTTP{0}; got HTTP{1}; on data [{2}][{3}][{4}]".
            format(expected_response_code, edituser_response.get_http_status(),
                   displayName, email, password))

        self.assertEqual(
            viewdetails_response.get_email(),
            new_email,
            msg="Email not updated; expected {{0}}; got {{1}}".format(
                new_email, viewdetails_response.get_email()))

        self.assertEqual(
            viewdetails_response.get_displayName(),
            new_displayName,
            msg="Email not updated; expected {{0}}; got {{1}}".format(
                new_displayName, viewdetails_response.get_displayName()))