-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,22 +102,20 @@ def check_day_reporting(self, day: datetime.date): | |
| f'enddate={end_day.strftime(DATE_FORMAT)}&fillblanks=true', | ||
| headers=self.headers | ||
| ) | ||
| if response.status_code == 200: | ||
| logging.info(f'Day report obtained for {day.isoformat()}') | ||
| day_report = json.loads(response.content.decode()) | ||
| for report in day_report: | ||
| if response.status_code != 200: | ||
| raise Exception(f'Day {day.isoformat()} problem.') | ||
| logging.info(f'Day report obtained for {day.isoformat()}') | ||
| day_report = json.loads(response.content.decode()) | ||
| for report in day_report: | ||
|
|
||
| # TODO in the future calculate the reported time and optimize the reports | ||
| date_reported = report['date'] | ||
| date_reported = f'{date_reported[6:]}-{date_reported[3:5]}-{date_reported[:2]}' | ||
| if report.get('tasks') and date_reported not in self.reported_days: | ||
| self.reported_days.append(date_reported) | ||
| logging.info(f'Day {date_reported} was previously reported') | ||
| # TODO in the future calculate the reported time and optimize the reports | ||
| date_reported = report['date'] | ||
| date_reported = f'{date_reported[6:]}-{date_reported[3:5]}-{date_reported[:2]}' | ||
| if report.get('tasks') and date_reported not in self.reported_days: | ||
| self.reported_days.append(date_reported) | ||
| logging.info(f'Day {date_reported} was previously reported') | ||
|
|
||
| self.reported_days = list(set(self.reported_days)) | ||
|
|
||
| else: | ||
| raise Exception(f'Day {day.isoformat()} problem.') | ||
| self.reported_days = list(set(self.reported_days)) | ||
|
|
||
| def get_reported_days( | ||
| self, | ||
|
|
@@ -136,19 +134,18 @@ def get_expected_calendar( | |
| f'{self.base_url}/api/Calendar/{year}/User/{self.userid}', | ||
| headers=self.headers | ||
| ) | ||
| if response.status_code == 200: | ||
| logging.info(f'Calendar obtained for year {year}') | ||
| calendar = json.loads(response.content.decode()) | ||
| for day in calendar: | ||
| if ( | ||
| (expected_day := day['date'][:10]) and | ||
| until.isoformat() >= expected_day >= self.start_day.isoformat() and | ||
| expected_day not in self.holidays and | ||
| (expected_minutes := day.get('expected')) | ||
| ): | ||
| self.expected_days[day['date'][:10]] = expected_minutes | ||
| else: | ||
| if response.status_code != 200: | ||
| raise Exception(f'Error obtaining calendar for year "{year}".') | ||
| logging.info(f'Calendar obtained for year {year}') | ||
| calendar = json.loads(response.content.decode()) | ||
| for day in calendar: | ||
| if ( | ||
| (expected_day := day['date'][:10]) and | ||
| until.isoformat() >= expected_day >= self.start_day.isoformat() and | ||
| expected_day not in self.holidays and | ||
| (expected_minutes := day.get('expected')) | ||
| ): | ||
| self.expected_days[day['date'][:10]] = expected_minutes | ||
|
Comment on lines
-139
to
+148
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def report(self): | ||
| logging.info('Reporting all ') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ def test_login(self): | |
| mock_post.return_value = response | ||
| client.login(username=self.username, password=self.password) | ||
| self.assertEqual(client.token, 'test_token') | ||
| self.assertEqual(client.headers['Authorization'], f'Bearer test_token') | ||
| self.assertEqual(client.headers['Authorization'], 'Bearer test_token') | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def test_login_status_code_not_200_raise_exception(self): | ||
| client = WorkmeterClient( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
WorkmeterClient.check_day_reportingrefactored with the following changes:swap-if-else-branches)remove-unnecessary-else)