-
Notifications
You must be signed in to change notification settings - Fork 73
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
Loaders for auth #415
Loaders for auth #415
Conversation
Pull Request Test Coverage Report for Build 2858
💛 - Coveralls |
ab4a7d5
to
89f5f0b
Compare
src/openprocurement/api/auth.py
Outdated
'level': ( | ||
value.split(',', 1)[1] if | ||
',' in value else | ||
ALL_ACCREDITATIONS_GRANTED |
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.
Дуже незрозумілий код. Чи не можна його винести в окрему функцію і трохи більше прокоментувати? Бо мені геть незрозуміло що відбувається і навіщо.
Подальший код цієї функції також незрозумілий.
create_users_from_group, | ||
_ini_auth, | ||
_yaml_auth, | ||
_json_auth |
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.
Underscore на початку назви означає приватність. Тому в імпорті воно дивиться дуже погано. Рекомендую просто прибрати underscore з назви тих функцій, бо не бачу в них потребу щось приховувати.
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.
Нема змін по цій пропозиції?
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.
В перший раз не помітив виправлю в наступних комітах
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.
Ок
self.assertEqual(self.mock_get_path.call_count, 1) | ||
self.mock_get_path.assert_called_with(self.app_meta) | ||
|
||
self.assertEqual(self.mock_config_parser_class.call_count, 1) |
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.
Тут і далі в тестах бачу багато перевірок на кількість викликів та взагалі фактів викликів.
Яку практичну користь вони переслідують?
Рекомендую перевірити себе так:
У всіх assert
-методах unittest
-у останнім параметром можна передати стрічку, яка буде виведена при неуспішності умови.
Яке повідомлення можна було б виводити при неуспішності твердження на кількість виклику методу? Наскільки розумію, шось типу: той метод мав викликатись і відпрацювати 1 раз, але не відпрацював жодного
. Як на мене, в цьому мало практичної користі. Тому раджу ті assert
-и, до яких не можна придумати змістовні пояснення, просто видалити. Бо при подальших змінах в коді перевірки на кількість викликів падають, і незрозуміло чому і навіщо вони були зроблені.
Якщо ж вони там важливі - додай комент, будь ласка, а ще краще - допиши їм такі повідомлення про неуспішність. Тоді все набагато зрозумілішим стає.
🎩
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.
Це потрібно по великому рахунку, щоб перевірити коректність роботи скрипта відносно його flow. Тут використовуються моки, отже певний функціонал емулюється в цьому випадку нам не важливо як відпрацює та функція нам є важливим те, що вона була викликана і повернула певний результат від якого може залежити виклик інакшої функції і.т.д. Стосовно коментарів ти маєш на увазі під кожен assert проставити внаслідок чого він викликаєтсья?
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.
Так, щоб було якесь пояснення його причини.
…penprocurement.api into loaders_for_auth
create_users_from_group, | ||
_ini_auth, | ||
_yaml_auth, | ||
_json_auth |
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.
Нема змін по цій пропозиції?
self.assertEqual(self.mock_create_users.call_count, 2) | ||
self.mock_create_users.assert_called_with(config_sections[-1], config_items) | ||
self.assertEqual(self.mock_create_users_ini.call_count, 2) | ||
self.mock_create_users_ini.assert_called_with(config_sections[-1], config_items) |
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.
Можна якісь коменти або еррор меседжі по цих асертах? Бо незрозуміло що вони тестують.
f6139fc
to
321d2af
Compare
src/openprocurement/api/auth.py
Outdated
if not config: | ||
LOGGER.warning("Auth file '%s' was empty, no user will be added", | ||
file_path) | ||
for item in config: |
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.
Тут іменування item
i config
потрібно змінити на доцільніші.
src/openprocurement/api/auth.py
Outdated
LOGGER.warning("Auth file '%s' was empty, no user will be added", | ||
file_path) | ||
for item in config: | ||
users.update(create_users_from_group(item, config[item].items())) |
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.
config[item].items()
треба "впихнути" в якусь зрозумілу змінну, що ж ми тут витягнули.
Cаму змінну users
вартувало б тут присвоїти, а не просто апдейтнути.
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.
users не вийде переприсвоїти, адже функція create_users_from_group повертає словник з користувачами для певної групи і єдиний спосіб то внести в users це оновити через update
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.
Та, ти правий. Давай перенесемо визначення users
перед цим for
-ом. а значення create_users_from_group
присвоюватимемо у читабельну проміжну змінну.
src/openprocurement/api/auth.py
Outdated
|
||
|
||
# Backward compatibility for `file` type | ||
auth_mapping['file'] = ini_auth |
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.
Явне навішування @auth(auth_type="ini")
на ini_auth
не дасть аналогічного ефекту?
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.
Хочеш зробити декоратор на декоруєму функцію?
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.
Добавити другий декоратор
This change is