def test_post_portfolio_joinLeague(self): league_data_1 = create_league(self.base_url, self.headers) league_data_2 = create_league(self.base_url, self.headers) league_data_3 = create_league(self.base_url, self.headers) resP1 = requests.post(url=self.url, data=json.dumps({ "name": 'p1', 'inviteCode': league_data_1['inviteCode'] }), headers=self.headers) self.assertEquals(resP1.status_code, 200) resP2 = requests.post(url=self.url, data=json.dumps({ "name": 'p2', 'inviteCode': league_data_2['inviteCode'] }), headers=self.headers) self.assertEquals(resP2.status_code, 200) resP3 = requests.post(url=self.url, data=json.dumps({ "name": 'p3', 'inviteCode': league_data_3['inviteCode'] }), headers=self.headers) self.assertEquals(resP3.status_code, 200) resGet = requests.get(url=self.url, headers=self.headers) resGetData = self.getJson(resGet) self.assertEquals(len(resGetData), 3) # Now do the delete resDel = requests.delete(url=self.url + "/" + str(self.getJson(resP2)["id"]), headers=self.headers) # Check to see if deleted resGet = requests.get(url=self.url, headers=self.headers) resGetData = self.getJson(resGet) self.assertEquals(len(resGetData), 2) self.assertEquals(resGetData[0]["id"], self.getJson(resP1)["id"]) self.assertEquals(resGetData[1]["id"], self.getJson(resP3)["id"])
def setUp(self): self.headers = {'Content-Type': 'application/json', 'App-Version': '*'} register_data = register_david_janzen(self.base_url, self.headers) self.assertTrue('id' in register_data) self.assertTrue(register_data['id'] > 0) login_data = login_david_janzen(self.base_url, self.headers) self.assertIsNotNone(login_data['userId']) self.assertIsNotNone(login_data['token']) self.headers['Authorization'] = 'token ' + login_data['token'] league_data = create_league(self.base_url, self.headers) self.assertIsNotNone(league_data['id']) self.assertIsNotNone(league_data['inviteCode']) self.assertIsNotNone(league_data['startPos']) portfolio_data = create_portfolio(self.base_url, self.headers, league_data['inviteCode']) self.assertTrue('id' in portfolio_data) self.assertTrue(portfolio_data['id'] > 0) self.assertTrue('buyPower' in portfolio_data) self.assertEquals(portfolio_data['buyPower'], 5000) self.portfolio_id = portfolio_data['id'] self.url = self.base_url + '/watchlists'
def test_getPortfolios_multiplePortfolios(self): league_data = create_league(self.base_url, self.headers) self.assertIsNotNone(league_data['id']) self.assertIsNotNone(league_data['inviteCode']) self.assertIsNotNone(league_data['startPos']) portfolioBody = { 'name': 'myothernewportfolio', 'inviteCode': league_data['inviteCode'] } portfolioResponse = requests.post(url=self.url, data=json.dumps(portfolioBody), headers=self.headers) portfolioResponseData = self.getJson(portfolioResponse) self.assertEquals(portfolioResponse.status_code, 200) self.assertTrue('id' in portfolioResponseData) self.assertTrue(portfolioResponseData['id'] > 0) self.assertTrue('buyPower' in portfolioResponseData) self.assertEquals(portfolioResponseData['buyPower'], 5000) response = requests.get(url=self.url, headers=self.headers) responseData = self.getJson(response) self.assertEquals(response.status_code, 200) self.assertEquals(len(responseData), 2)
def setUp(self): self.headers = {'Content-Type': 'application/json', 'App-Version': '*'} register_data = register_david_janzen(self.base_url, self.headers) self.assertTrue('id' in register_data) self.assertTrue(register_data['id'] > 0) login_data = login_david_janzen(self.base_url, self.headers) self.assertIsNotNone(login_data['userId']) self.assertIsNotNone(login_data['token']) self.headers['Authorization'] = 'token ' + login_data['token'] league_data = create_league(self.base_url, self.headers) self.assertIsNotNone(league_data['id']) self.assertIsNotNone(league_data['inviteCode']) self.assertIsNotNone(league_data['startPos']) portfolio_data = create_portfolio(self.base_url, self.headers, league_data['inviteCode']) self.assertTrue('id' in portfolio_data) self.assertTrue(portfolio_data['id'] > 0) self.assertTrue('buyPower' in portfolio_data) self.assertEquals(portfolio_data['buyPower'], 5000) self.portfolioId = portfolio_data['id'] self.invite_code = league_data['inviteCode'] self.url = self.base_url + '/portfolios' # Manually add leagues that aren't in the acceptable date range self.cursor.execute( 'INSERT INTO League(name, start, end, startPos, inviteCode, ' + 'ownerId) ' + 'VALUES("plannedleague", "2100-01-01", "2110-01-01",' + ' 1000, "ic1", %s)', [register_data["id"]]) self.planned_league_id = self.cursor.lastrowid self.cursor.execute( 'INSERT INTO League(name, start, end, startPos, inviteCode, ' + 'ownerId) ' + 'VALUES("endedleague", "2020-02-22", "2020-02-27",' + ' 1000, "ic2", %s)', [register_data["id"]]) self.ended_league_id = self.cursor.lastrowid self.cursor.execute( 'INSERT INTO League(name, start, end, startPos, inviteCode, ' + 'ownerId) ' + 'VALUES("activeleague", "1900-01-01", "2100-01-01",' + ' 1000, "ic3", %s)', [register_data["id"]]) self.active_league_id = self.cursor.lastrowid
def setUp(self): self.headers = {'Content-Type': 'application/json', 'App-Version': '*'} register_data = register_david_janzen(self.base_url, self.headers) self.assertTrue('id' in register_data) self.assertTrue(register_data['id'] > 0) login_data = login_david_janzen(self.base_url, self.headers) self.assertIsNotNone(login_data['userId']) self.assertIsNotNone(login_data['token']) self.headers['Authorization'] = 'token ' + login_data['token'] league_data = create_league(self.base_url, self.headers) self.assertIsNotNone(league_data['id']) self.assertIsNotNone(league_data['inviteCode']) self.assertIsNotNone(league_data['startPos']) portfolio_data = create_portfolio(self.base_url, self.headers, league_data['inviteCode']) self.assertTrue('id' in portfolio_data) self.assertTrue(portfolio_data['id'] > 0) self.assertTrue('buyPower' in portfolio_data) self.assertEquals(portfolio_data['buyPower'], 5000) self.portfolioId = portfolio_data['id'] self.url = self.base_url + '/portfolios' self.invite_code = league_data['inviteCode'] self.user_id = login_data['userId'] # Adding PortfolioHistory stuff manually self.cursor.execute( 'INSERT INTO PortfolioHistory(portfolioId, datetime, value) VALUES(%s, DATE_SUB(CURDATE(), INTERVAL 2 DAY), %s)', (portfolio_data['id'], 2950)) self.cursor.execute( 'INSERT INTO PortfolioHistory(portfolioId, datetime, value) VALUES(%s, DATE_SUB(CURDATE(), INTERVAL 1 DAY), %s)', (portfolio_data['id'], 3000)) self.cursor.execute( 'INSERT INTO PortfolioHistory(portfolioId, datetime, value) VALUES(%s, NOW(), %s)', (portfolio_data['id'], 3010))
def setUp(self): self.headers = {'Content-Type': 'application/json', 'App-Version': '*'} register_data = register_david_janzen(self.base_url, self.headers) self.assertTrue('id' in register_data) self.assertTrue(register_data['id'] > 0) login_data = login_david_janzen(self.base_url, self.headers) self.assertIsNotNone(login_data['userId']) self.assertIsNotNone(login_data['token']) self.headers['Authorization'] = 'token ' + login_data['token'] league_data = create_league(self.base_url, self.headers) self.assertIsNotNone(league_data['id']) self.assertIsNotNone(league_data['inviteCode']) self.assertIsNotNone(league_data['startPos']) self.user_id = login_data['userId'] self.league_id = league_data['id'] self.invite_code = league_data['inviteCode'] self.league_start_pos = league_data['startPos'] self.url = self.base_url + '/portfolios'