|
|
@@ -1,7 +1,8 @@
|
|
|
import unittest
|
|
|
from mock import Mock, patch, MagicMock
|
|
|
from django.conf import settings
|
|
|
-import hackathon.scripts.github as github
|
|
|
+from hackathon.scripts.github import getUserData
|
|
|
+
|
|
|
|
|
|
class GithubTests(unittest.TestCase):
|
|
|
|
|
|
@@ -9,14 +10,31 @@ class GithubTests(unittest.TestCase):
|
|
|
self.API_BASE_URL = 'https://api.github.com/users/DrkSephy'
|
|
|
self.clientID = 'client_id=2404a1e21aebd902f6db'
|
|
|
self.clientSecret = 'client_secret=3da44769d4b7c9465fa4c812669148a163607c23'
|
|
|
- self.jsonList = []
|
|
|
+ #@patch.object(github, 'getUserData')
|
|
|
+ def testGetUserData(self):
|
|
|
+ # Client and Secret ID
|
|
|
+ clientID = self.clientID
|
|
|
+ clientSecret = self.clientSecret
|
|
|
+ # Construct the URL
|
|
|
|
|
|
- @patch.object(github, 'getUserData')
|
|
|
- def testGetUserData(self, mock_getUserData):
|
|
|
- self.url = self.API_BASE_URL + '?' + self.clientID + '&' + self.clientSecret
|
|
|
- userData = Mock()
|
|
|
- match = {'name': 'test', 'blog': 'test', 'email': 'test', 'public_gists': 'test', 'public_repos': 'test','avatar_url': 'test', 'followers': 'test','following': 'test'}
|
|
|
- mock_getUserData.return_value = {'name': 'test', 'blog': 'test', 'email': 'test', 'public_gists': 'test', 'public_repos': 'test','avatar_url': 'test', 'followers': 'test','following': 'test'}
|
|
|
- self.assertEqual(github.getUserData(self.clientID, self.clientSecret), {'name': 'test', 'blog': 'test', 'email': 'test', 'public_gists': 'test', 'public_repos': 'test','avatar_url': 'test', 'followers': 'test','following': 'test'})
|
|
|
-
|
|
|
- # self.assertEqual('hello', 'hello')
|
|
|
+ self.url = self.API_BASE_URL + '?' + clientID + '&' + clientSecret
|
|
|
+ jsonList = []
|
|
|
+ parsedData = []
|
|
|
+ userData = {}
|
|
|
+ with patch('hackathon.scripts.github.getUserData') as mock_getUserData:
|
|
|
+ print 'hello'
|
|
|
+ # match = {'name': 'test', 'blog': 'test', 'email': 'test', 'public_gists': 'test', 'public_repos': 'test','avatar_url': 'test', 'followers': 'test','following': 'test'}
|
|
|
+ mock_getUserData.return_value = {'public_repos': 50, 'public_gists': 5, 'name': 'David Leonard', 'blog': 'http://drksephy.github.io', 'avatar_url': 'https://avatars.githubusercontent.com/u/1226900?v=3', 'followers': 52, 'following': 7, 'email': 'DrkSephy1025@gmail.com'}
|
|
|
+ jsonList.append(mock_getUserData.return_value)
|
|
|
+ for data in jsonList:
|
|
|
+ userData['name'] = mock_getUserData.return_value['name']
|
|
|
+ userData['blog'] = mock_getUserData.return_value['blog']
|
|
|
+ userData['email'] = mock_getUserData.return_value['email']
|
|
|
+ userData['public_gists'] = mock_getUserData.return_value['public_gists']
|
|
|
+ userData['public_repos'] = mock_getUserData.return_value['public_repos']
|
|
|
+ userData['avatar_url'] = mock_getUserData.return_value['avatar_url']
|
|
|
+ userData['followers'] = mock_getUserData.return_value['followers']
|
|
|
+ userData['following'] = mock_getUserData.return_value['following']
|
|
|
+ parsedData.append(userData)
|
|
|
+ print parsedData
|
|
|
+ self.assertEqual(getUserData(clientID, clientSecret), parsedData)
|