teststeam.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import unittest
  2. from mock import Mock, patch, MagicMock
  3. from django.conf import settings
  4. from hackathon.scripts.steam import *
  5. class SteamTests(unittest.TestCase):
  6. def setup(self):
  7. self.API_URL = 'http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/'
  8. self.APIKEY = '231E98D442E52B87110816C3D5114A1D'
  9. self.userID = 'Marorin'
  10. self.steamnum = '76561197997115778'
  11. def testGetUserIDNum(self):
  12. '''Test for steam.py method'''
  13. # Pulling from setUp
  14. userID = self.userID
  15. API_URL = self.API_URL
  16. APIKEY = self.APIKEY
  17. # constructing the URL
  18. self.url = API_URL + '?' + APIKEY + '&' + userID
  19. with patch('hackathon.scripts.steam.steamIDpulling') as mock_steamIDPulling:
  20. # Mocking the return value of this method.
  21. mock_steamIDpulling = 76561197997115778
  22. self.assertEqual(steamIDPulling(userID,APIKEY),mock_steamIDpulling)
  23. def testgamespulling(self):
  24. '''Test gamesPulling method'''
  25. # Using test account due to huge JSON from normal one.
  26. steamnum = self.steamnum
  27. with patch("requests.get") as mock_gamespulling:
  28. mock_gamespulling.returnvalue = [{"response": {"game_count": 0}}]
  29. self.assertEqual(gamesPulling(steamnum,APIKEY), mock_gamespulling.returnvalue)