Beispiel #1
0
 def test_refresh_view(self):
     database_client = database_api.DatabaseApi(
         user=service.DB_USER,
         password=service.DB_PASSWORD,
         host=service.DB_HOST,
         port=service.DB_PORT,
         database=service.DB_DATABASE,
     )
     repo_json = {"id": 21, "name": "harold", "owner": {"login": "******"}}
     database_client.insert_new_repositories([repo_json])
     expected_contributors = [
         {
             "author": {"login": "******"},
             "commit": {"author": {"date": "2012-07-09T16:13:30+12:00"}},
         },
         {
             "author": {"login": "******"},
             "commit": {"author": {"date": "2012-07-09T16:13:30+12:00"}},
         },
         {
             "author": {"login": "******"},
             "commit": {"author": {"date": "2011-07-09T16:13:30+12:00"}},
         },
         {
             "author": {"login": "******"},
             "commit": {"author": {"date": "2015-07-09T16:13:30+12:00"}},
         },
     ]
     database_client.upsert_contributors(
         repo_id=repo_json["id"], contributors=expected_contributors
     )
     database_client.refresh_view()
Beispiel #2
0
 def test_insert_new_repositories_duplicates(self):
     database_client = database_api.DatabaseApi(
         user=service.DB_USER,
         password=service.DB_PASSWORD,
         host=service.DB_HOST,
         port=service.DB_PORT,
         database=service.DB_DATABASE,
     )
     expected_repositories = [
         {"id": 21, "name": "harold", "owner": {"login": "******"}},
         {"id": 34, "name": "henry", "owner": {"login": "******"}},
         {"id": 21, "name": "ford", "owner": {"login": "******"}},
     ]
     database_client.insert_new_repositories(expected_repositories)
     result_repositories = database_client.listing_repositories()
     self.assertEqual(2, len(result_repositories))
     self.assertEqual(
         expected_repositories[0]["owner"]["login"], result_repositories[0]["owner"]
     )
     self.assertEqual(
         expected_repositories[0]["name"], result_repositories[0]["name"]
     )
     self.assertEqual(None, result_repositories[0]["last_commit_check"])
     self.assertEqual(
         expected_repositories[1]["owner"]["login"], result_repositories[1]["owner"]
     )
     self.assertEqual(
         expected_repositories[1]["name"], result_repositories[1]["name"]
     )
Beispiel #3
0
 def test_listing_existing_contributors_with_no_value(self):
     database_client = database_api.DatabaseApi(
         user=service.DB_USER,
         password=service.DB_PASSWORD,
         host=service.DB_HOST,
         port=service.DB_PORT,
         database=service.DB_DATABASE,
     )
     self.assertEqual(list(), database_client.listing_existing_contributors(21))
Beispiel #4
0
    def test_upsert_contributors_duplicates(self):
        database_client = database_api.DatabaseApi(
            user=service.DB_USER,
            password=service.DB_PASSWORD,
            host=service.DB_HOST,
            port=service.DB_PORT,
            database=service.DB_DATABASE,
        )
        repo_json = {"id": 21, "name": "harold", "owner": {"login": "******"}}
        database_client.insert_new_repositories([repo_json])
        expected_contributors = [
            {
                "author": {"login": "******"},
                "commit": {"author": {"date": "2012-07-09T16:13:30+12:00"}},
            },
            {
                "author": {"login": "******"},
                "commit": {"author": {"date": "2012-07-09T16:13:30+12:00"}},
            },
            {
                "author": {"login": "******"},
                "commit": {"author": {"date": "2011-07-09T16:13:30+12:00"}},
            },
            {
                "author": {"login": "******"},
                "commit": {"author": {"date": "2015-07-09T16:13:30+12:00"}},
            },
        ]
        database_client.upsert_contributors(
            repo_id=repo_json["id"], contributors=expected_contributors
        )
        result_contributors = database_client.listing_existing_contributors(21)
        self.assertEqual(2, len(result_contributors))
        self.assertEqual(
            expected_contributors[1]["author"]["login"], result_contributors[0]["login"]
        )
        # offset is +12 from github api
        self.assertEqual(
            "2012-07-09T04:13:30+00:00",
            result_contributors[0]["first_commit_at"].isoformat(),
        )
        self.assertEqual(None, result_contributors[0]["update_at"])

        self.assertEqual(
            expected_contributors[3]["author"]["login"], result_contributors[1]["login"]
        )
        self.assertEqual(
            "2011-07-09T04:13:30+00:00",
            result_contributors[1]["first_commit_at"].isoformat(),
        )
        self.assertNotEqual(None, result_contributors[1]["update_at"].isoformat())
Beispiel #5
0
 def test_listing_repositories(self):
     database_client = database_api.DatabaseApi(
         user=service.DB_USER,
         password=service.DB_PASSWORD,
         host=service.DB_HOST,
         port=service.DB_PORT,
         database=service.DB_DATABASE,
     )
     repo_json = {"id": 21, "name": "harold", "owner": {"login": "******"}}
     database_client.insert_new_repositories([repo_json])
     result_repositories = database_client.listing_repositories()
     self.assertEqual(1, len(result_repositories))
     self.assertEqual(repo_json["owner"]["login"], result_repositories[0]["owner"])
     self.assertEqual(repo_json["name"], result_repositories[0]["name"])
     self.assertEqual(None, result_repositories[0]["last_commit_check"])
Beispiel #6
0
def main(
    url_api: str,
    type_owner: str,
    owner: str,
    chunk_size: int,
    token: str,
    refresh_frequency: int,
):
    headers = {"Authorization": f"token {token}"} if token else {}
    github_client = github_api.GithubApi(url_api,
                                         headers=headers,
                                         chunk_size=chunk_size)
    database_client = database_api.DatabaseApi(
        user=service.DB_USER,
        password=service.DB_PASSWORD,
        host=service.DB_HOST,
        port=service.DB_PORT,
        database=service.DB_DATABASE,
    )
    refresh_thread = RefreshThread(database_client, refresh_frequency)
    refresh_thread.start()
    while True:
        loop(database_client, github_client, type_owner, owner)
Beispiel #7
0
 def test_listing_existing_contributors(self):
     database_client = database_api.DatabaseApi(
         user=service.DB_USER,
         password=service.DB_PASSWORD,
         host=service.DB_HOST,
         port=service.DB_PORT,
         database=service.DB_DATABASE,
     )
     repo_json = {"id": 21, "name": "harold", "owner": {"login": "******"}}
     database_client.insert_new_repositories([repo_json])
     contributor_json = {
         "author": {"login": "******"},
         "commit": {"author": {"date": "2012-07-09T16:13:30+12:00"}},
     }
     expected_contributors = [contributor_json]
     database_client.upsert_contributors(
         repo_id=repo_json["id"], contributors=expected_contributors
     )
     result_contributors = database_client.listing_existing_contributors(21)
     self.assertEqual(1, len(result_contributors))
     self.assertEqual(
         contributor_json["author"]["login"], result_contributors[0]["login"]
     )