def get_commit(self, sha_or_branch) -> Commit: """ Github response example: https://api.github.com/repos/Ulauncher/Ulauncher/commits/a1304f5a """ project_path = self._get_project_path() url = self.url_commit_template.format(project_path=project_path, commit=sha_or_branch) resp = json.loads(urlopen(url).read().decode('utf-8')) return { 'sha': resp['sha'], 'time': iso_to_datetime(resp['commit']['committer']['date']) }
def gh_ext(self, mocker): gh_ext = mocker.patch('ulauncher.api.server.ExtensionDownloader.GithubExtension').return_value gh_ext.get_ext_id.return_value = 'com.github.ulauncher.ulauncher-timer' gh_ext.get_download_url.return_value = 'https://github.com/Ulauncher/ulauncher-timer/archive/master.zip' gh_ext.get_last_commit.return_value = { 'last_commit': '64e106c', 'last_commit_time': '2017-05-01T07:30:39' } gh_ext.find_compatible_version.return_value = { 'sha': '64e106c', 'time': iso_to_datetime('2017-05-01T07:30:39Z') } return gh_ext
def test_get_commit(self, gh_ext, mocker): urlopen = mocker.patch('ulauncher.api.server.GithubExtension.urlopen') urlopen.return_value = io.BytesIO( dumps({ 'sha': '64e106c57ad90f9f02e9941dfa9780846b7457b9', 'commit': { 'committer': { 'date': '2017-05-01T07:30:39Z' } } }).encode('utf-8')) commit = gh_ext.get_commit('64e106c57') assert commit['sha'] == '64e106c57ad90f9f02e9941dfa9780846b7457b9' assert commit['time'] == iso_to_datetime('2017-05-01T07:30:39Z')
def test_iso_to_datetime__with_timezone(): assert str(iso_to_datetime('2019-01-04T16:41:24+0200', False)) == '2019-01-04 16:41:24+02:00'
def test_iso_to_datetime(): assert str( iso_to_datetime('2017-05-01T07:30:39Z')) == '2017-05-01 07:30:39'