def test_should_throw_exception_when_requesting_github_repository_api_fails( self, request_mock): request_mock.get(url='https://api.github.com/repos/mirrorhanyu/WeGit', reason='request repository fails', status_code=500) with self.assertRaises(HTTPError) as context: repository.get_repository(self.event, None) self.assertEqual(context.exception.response.reason, 'request repository fails')
def test_should_return_correct_response_when_requesting_github_repository_api_success( self, request_mock): request_mock.get(url='https://api.github.com/repos/mirrorhanyu/WeGit', text=json.dumps(self.repository), status_code=200) request_mock.get( url='https://api.github.com/repos/mirrorhanyu/WeGit/readme', text=json.dumps(self.readme_response), status_code=200) request_mock.get( url= 'https://raw.githubusercontent.com/mirrorhanyu/WeGit/master/README.md', text=self.readme, status_code=200) repository_response = repository.get_repository(self.event, None) repository_response_status_code = repository_response.get('statusCode') repository_response_body = json.loads(repository_response.get('body')) self.assertEqual(repository_response_status_code, 200) self.assertEqual(len(repository_response_body.keys()), 7) self.assertEqual( repository_response_body.get('description'), 'unofficial github wechat mini program 民间 Github 微信小程序') self.assertEqual(repository_response_body.get('subscribersCount'), 1) self.assertEqual(repository_response_body.get('stargazersCount'), 1) self.assertEqual(repository_response_body.get('forksCount'), 1) self.assertEqual(repository_response_body.get('license'), None) self.assertEqual(repository_response_body.get('openIssues'), 4) self.assertEqual(repository_response_body.get('readme'), '### WeGit README')
def list_activities(args): r = repository.get_repository(get_token(args), args.update_cache) p = predicates.get_predicate_from_filters(args.utc, args.filter) f = formatters.get_formatter(args.json, args.quiet, args.verbose, args.utc) for activity in r.get_activities(): if p.matches(activity): print(f.format(activity))
def activities_gps(args): r = repository.get_repository(get_token(args), args.update_cache) f = formatters.get_formatter_gps(args.json) for id in args.id: if not id.isdigit(): print('activity {} needs to be a number'.format(id)) continue print(f.format(*r.get_gps(int(id))))
def update_activities(args): r = repository.get_repository(get_token(args)) data = get_update_data(args) for id in args.id: if not id.isdigit(): print('activity {} needs to be a number'.format(id)) continue r.update_activity(int(id), data)
def activities_details(args): r = repository.get_repository(get_token(args), args.update_cache) f = formatters.get_formatter_details(args.json, args.quiet, args.verbose, args.utc) for id in args.id: if not id.isdigit(): print('activity {} needs to be a number'.format(id)) continue activity = r.get_activity_detail(int(id)) print( f.format(activity) if activity is not None else 'activity {} not found'.format(id))
def get_repositories(check_accessible=True): status_code, response_text = crowdin_request(None, '/account/get-projects', 'GET', {'json': 'true'}) projects = json.loads(response_text)['projects'] repositories_df = pd.read_csv('%s/repositories.csv' % initial_dir, comment='#') repositories_df.fillna('', inplace=True) repositories = [ get_repository(projects, **x) for x in repositories_df.to_dict('records') ] if check_accessible: for git_repository, crowdin_repository in repositories: assert (is_repository_accessible(git_repository.origin)) assert (is_repository_accessible(git_repository.upstream)) return repositories
def list_shoes(args): r = repository.get_repository(get_token(args)) for shoe in r.get_shoes(): print('{id:<20} {name:<20}'.format(**shoe))
def list_bikes(args): r = repository.get_repository(get_token(args)) for bike in r.get_bikes(): print('{id:<20} {name:<20}'.format(**bike))