Example #1
0
    def test_search_repos_by_user(self):
        self.mock_uri("https://api.github.com/users/drusk/repos",
                      testutil.read("user_repos.json"))

        repos = self.searcher.search_repos_by_user("drusk")

        assert_that(repos, has_length(16))
        assert_that(repos, contains_inanyorder(
            "MOP",
            "scratch",
            "fishcounter",
            "config-files",
            "WeightRep",
            "drusk.github.com",
            "algorithms",
            "cadcVOFS",
            "query-gateway",
            "query-composer",
            "pml",
            "pml-applications",
            "uvic-transcript-parser",
            "archive",
            "investment-tracker",
            "drusk-gwt-oracle-example"
        ))
Example #2
0
    def test_search_users_by_location_in_single_call(self):
        self.mock_uri("https://api.github.com/search/users",
                      testutil.read("victoria_search_page1.json"))

        users = self.searcher.search_users_by_location("victoria")

        assert_that(users, has_length(100))
    def test_get_user(self):
        for user in json.loads(testutil.read("victoria_users.json")):
            self.db.insert_user(user, "victoria")

        user = self.db.get_user("drusk")

        assert_that(user["login"], equal_to("drusk"))
        assert_that(user["html_url"], equal_to("https://github.com/drusk"))
Example #4
0
    def test_resolve_source_repo_to_source(self):
        self.mock_uri("https://api.github.com/repos/drusk/algorithms",
                      testutil.read("repo_is_source.json"))

        owner, repo_name = self.searcher.resolve_repo_to_source("drusk", "algorithms")

        assert_that(owner, equal_to("drusk"))
        assert_that(repo_name, equal_to("algorithms"))
Example #5
0
    def test_resolve_forked_repo_to_source(self):
        self.mock_uri("https://api.github.com/repos/drusk/MOP",
                      testutil.read("repo_is_fork.json"))

        owner, repo_name = self.searcher.resolve_repo_to_source("drusk", "MOP")

        assert_that(owner, equal_to("ijiraq"))
        assert_that(repo_name, equal_to("MOP"))
Example #6
0
    def test_get_user_language_stats(self):
        self.searcher.search_repos_by_user = Mock(return_value=["algorithms", "pml"])

        self.mock_uri("https://api.github.com/repos/drusk/algorithms/languages",
                      testutil.read("language_stats_algorithms.json"))
        self.mock_uri("https://api.github.com/repos/drusk/pml/languages",
                      testutil.read("language_stats_pml.json"))

        language_stats = self.searcher.get_user_language_stats("drusk")

        assert_that(language_stats, equal_to(
            {
                "Java": 150390,
                "Python": 273059,
                "Shell": 5407
            }
        ))
    def test_save_and_retrieve_user_who_was_not_already_in_database(self):
        user = json.loads(testutil.read("user_drusk.json"))

        self.db.insert_user(user, "victoria")

        retrieved_user = self.db.get_user("drusk")
        assert_that(retrieved_user["login"], equal_to("drusk"))
        assert_that(retrieved_user["name"], equal_to("David Rusk"))
        assert_that(retrieved_user["public_repos"], equal_to(16))
Example #8
0
    def test_get_repo_language_stats(self):
        self.mock_uri("https://api.github.com/repos/drusk/algorithms/languages",
                      testutil.read("language_stats_algorithms.json"))

        language_stats = self.searcher.get_repo_language_stats("drusk", "algorithms")

        assert_that(language_stats, equal_to(
            {
                "Java": 150390,
                "Python": 4713
            }
        ))
    def test_save_and_retrieve_user_already_in_database(self):
        userid = "drusk"
        language_stats = {"Python": 12345, "Java": 6789}

        self.db.insert_user_language_stats(userid, language_stats)

        user = json.loads(testutil.read("user_drusk.json"))

        self.db.insert_user(user, "victoria")

        # Make sure language data is still there
        assert_that(self.db.get_user_language_stats(userid),
                    equal_to(language_stats))
Example #10
0
    def test_search_user(self):
        self.mock_uri("https://api.github.com/users/drusk",
                      testutil.read("user_drusk.json"))

        user = self.searcher.search_user("drusk")

        assert_that(user["login"], equal_to("drusk"))
        assert_that(user["name"], equal_to("David Rusk"))
        assert_that(user["company"], none())
        assert_that(user["location"], equal_to("Victoria, BC"))
        assert_that(user["hireable"], equal_to(False))
        assert_that(user["hireable"], equal_to(False))
        assert_that(user["public_repos"], equal_to(16))
        assert_that(user["followers"], equal_to(1))
        assert_that(user["following"], equal_to(0))
    def test_save_and_retrieve_users_by_location(self):
        location = "victoria"
        retrieved_users = self.db.get_users(location=location)
        assert_that(retrieved_users, has_length(0))

        users = json.loads(testutil.read("victoria_users.json"))
        assert_that(users, has_length(649))

        unique_userids = {user["login"] for user in users}
        assert_that(unique_userids, has_length(554))

        for user in users:
            self.db.insert_user(user, location)

        retrieved_users = self.db.get_users(location=location)
        assert_that(retrieved_users, has_length(554))