Exemplo n.º 1
0
 def test_getData(self):
     # Given
     with open("tests/resources/user.html") as userWeb:
         reply = userWeb.read()
     httpretty.enable()
     httpretty.register_uri(httpretty.GET, "https://github.com/iblancasa",
                            body=reply,
                            content_type="text/html")
     # When
     user = GitHubUser("iblancasa")
     user.getData()
     # Then
     self.assertEqual(user.numberOfRepos, 141)
     self.assertEqual(user.bio, "This is my bio.")
     self.assertEqual(user.private, 0)
     self.assertEqual(user.public, 0)
     self.assertEqual(user.contributions, 490)
     self.assertEqual(user.name, "iblancasa")
     self.assertEqual(user.join, "2013-06-24")
     self.assertEqual(user.followers, 107)
     self.assertEqual(user.organizations, 7)
     self.assertEqual(user.avatar,
                      "https://avatars0.githubusercontent.com/u/4806311")
     httpretty.disable()
     httpretty.reset()
Exemplo n.º 2
0
    def test_getRealContributions(self):
        # Given
        with open("tests/resources/user.html") as userWeb:
            reply = userWeb.read()
        httpretty.enable()
        httpretty.register_uri(httpretty.GET, "https://github.com/iblancasa",
                               body=reply,
                               content_type="text/html")
        # When
        user = GitHubUser("iblancasa")
        user.contributions = 490
        user.getRealContributions()
        # Then
        self.assertEqual(user.public, 490)
        self.assertEqual(user.private, 0)

        # Given
        with open("tests/resources/userprivate.html") as userWeb:
            reply = userWeb.read()
        httpretty.enable()
        httpretty.register_uri(httpretty.GET, "https://github.com/privateuser",
                               body=reply,
                               content_type="text/html")
        # When
        user = GitHubUser("privateuser")
        user.contributions = 2026
        user.getRealContributions()
        # Then
        self.assertEqual(user.public, 1116)
        self.assertEqual(user.private, 910)

        httpretty.disable()
        httpretty.reset()
Exemplo n.º 3
0
 def test__getBio(self):
     """Test the private method getBio."""
     # Given
     data = ""
     with open("tests/resources/user.html") as userWeb:
         data = userWeb.read()
     web = BeautifulSoup(data, "lxml")
     # When
     user = GitHubUser("iblancasa")
     user._GitHubUser__getBio(web)
     # Then
     self.assertEqual(user.bio, "This is my bio.")
Exemplo n.º 4
0
 def test__getOrganizations(self):
     """Test the private method getOrganizations."""
     # Given
     data = ""
     with open("tests/resources/user.html") as userWeb:
         data = userWeb.read()
     web = BeautifulSoup(data, "lxml")
     # When
     user = GitHubUser("iblancasa")
     user._GitHubUser__getOrganizations(web)
     # Then
     self.assertEqual(user.organizations, 7)
Exemplo n.º 5
0
 def test__getLocation(self):
     """Test the private method getLocation."""
     # Given
     data = ""
     with open("tests/resources/user.html") as userWeb:
         data = userWeb.read()
     web = BeautifulSoup(data, "lxml")
     # When
     user = GitHubUser("iblancasa")
     user._GitHubUser__getLocation(web)
     # Then
     self.assertEqual(user.location, "Granada, Andalucía, Spain")
Exemplo n.º 6
0
 def test__getAvatar(self):
     """Test the private method getAvatar."""
     # Given
     data = ""
     with open("tests/resources/user.html") as userWeb:
         data = userWeb.read()
     web = BeautifulSoup(data, "lxml")
     # When
     user = GitHubUser("iblancasa")
     user._GitHubUser__getAvatar(web)
     # Then
     self.assertEqual(user.avatar,
                      "https://avatars0.githubusercontent.com/u/4806311")
Exemplo n.º 7
0
    def _addUser(self, new_user):
        """Add new users to the list (private).

        Note:
            This method is private.
            If the user is yet in the list (or in excluded users list),
            he/she will not be added

        Args:
            new_user (str): name of a GitHub user to include in the ranking

        """
        self._lockReadAddUser.acquire()
        if new_user not in self._myusers and new_user not in self._excluded:
            self._lockReadAddUser.release()
            self._myusers.add(new_user)

            myNewUser = GitHubUser(new_user)
            myNewUser.getData()
            myNewUser.getRealContributions()

            userLoc = myNewUser.getLocation()
            if not any(s in userLoc for s in self._excludedLocations):
                self._dataUsers.append(myNewUser)

        else:
            self._lockReadAddUser.release()
Exemplo n.º 8
0
    def test_getNumberOfFollowers(self):
        """Test the private method getNumberOfFollowers."""
        # Given
        data = ""
        with open("tests/resources/user.html") as userWeb:
            data = userWeb.read()
        web = BeautifulSoup(data, "lxml")
        # When
        user = GitHubUser("iblancasa")
        user._GitHubUser__getNumberOfFollowers(web)
        # Then
        self.assertEqual(user.followers, 107)

        # Given
        data = ""
        with open("tests/resources/userk.html") as userWeb:
            data = userWeb.read()
        web = BeautifulSoup(data, "lxml")
        # When
        user = GitHubUser("vim-scripts")
        user._GitHubUser__getNumberOfFollowers(web)
        # Then
        self.assertEqual(user.followers, 3800)
Exemplo n.º 9
0
    def __addUser(self, new_user):
        """Add new users to the list.

        :param new_user: name of a GitHub user to include in
            the ranking
        :type new_user: str.
        """
        self.__lockReadAddUser.acquire()
        if new_user not in self.__myusers and \
                new_user not in self.__excluded:
            self.__lockReadAddUser.release()
            self.__logger.debug("__addUser: Adding " + new_user)
            self.__myusers.add(new_user)

            myNewUser = GitHubUser(new_user)
            myNewUser.getData()
            myNewUser.getRealContributions()

            userLoc = myNewUser.location
            if not any(s in userLoc for s in self.__excludedLocations):
                self.__dataUsers.append(myNewUser)
        else:
            self.__logger.debug("__addUser: Excluding " + new_user)
            self.__lockReadAddUser.release()
Exemplo n.º 10
0
 def test_export(self):
     # Given
     user = GitHubUser("iblancasa")
     user.numberOfRepos = 141
     user.bio = ""
     user.private = 0
     user.public = 0
     user.location = 'Granada, Andalucía, Spain'
     user.contributions = 490
     user.name = "iblancasa"
     user.join = "2013-06-24"
     user.followers = 107
     user.organizations = 7
     user.avatar = "https://avatars0.githubusercontent.com/u/4806311"
     # When
     exportedUser = {'name': 'iblancasa',
                     'bio': '',
                     'join': '2013-06-24',
                     'organizations': 7,
                     'private': 0,
                     'contributions':490,
                     'public': 0,
                     'location': 'Granada, Andalucía, Spain',
                     'avatar':
                         'https://avatars0.githubusercontent.com/u/4806311',
                     'repositories': 141,
                     'followers': 107
                    }
     # Then
     self.assertEqual(user.export(), exportedUser)
Exemplo n.º 11
0
def main(argv):
    user = GitHubUser(argv[0])
    user.getData()
    user.getRealContributions()
    print(user.export())