Skip to content
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

Merged

Conversation

oleksiyVeretiuk
Copy link

@oleksiyVeretiuk oleksiyVeretiuk commented Dec 11, 2018

This change is Reviewable

@coveralls
Copy link

coveralls commented Dec 11, 2018

Pull Request Test Coverage Report for Build 2858

  • 54 of 63 (85.71%) changed or added relevant lines in 3 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.9%) to 71.953%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/openprocurement/api/utils.py 0 4 0.0%
src/openprocurement/api/auth.py 53 58 91.38%
Files with Coverage Reduction New Missed Lines %
src/openprocurement/api/utils.py 1 61.57%
Totals Coverage Status
Change from base Build 2845: 0.9%
Covered Lines: 1942
Relevant Lines: 2699

💛 - Coveralls

src/openprocurement/api/auth.py Show resolved Hide resolved
'level': (
value.split(',', 1)[1] if
',' in value else
ALL_ACCREDITATIONS_GRANTED
Copy link

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Underscore на початку назви означає приватність. Тому в імпорті воно дивиться дуже погано. Рекомендую просто прибрати underscore з назви тих функцій, бо не бачу в них потребу щось приховувати.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нема змін по цій пропозиції?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В перший раз не помітив виправлю в наступних комітах

Copy link

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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут і далі в тестах бачу багато перевірок на кількість викликів та взагалі фактів викликів.
Яку практичну користь вони переслідують?

Рекомендую перевірити себе так:
У всіх assert-методах unittest-у останнім параметром можна передати стрічку, яка буде виведена при неуспішності умови.

Яке повідомлення можна було б виводити при неуспішності твердження на кількість виклику методу? Наскільки розумію, шось типу: той метод мав викликатись і відпрацювати 1 раз, але не відпрацював жодного. Як на мене, в цьому мало практичної користі. Тому раджу ті assert-и, до яких не можна придумати змістовні пояснення, просто видалити. Бо при подальших змінах в коді перевірки на кількість викликів падають, і незрозуміло чому і навіщо вони були зроблені.

Якщо ж вони там важливі - додай комент, будь ласка, а ще краще - допиши їм такі повідомлення про неуспішність. Тоді все набагато зрозумілішим стає.
🎩

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Це потрібно по великому рахунку, щоб перевірити коректність роботи скрипта відносно його flow. Тут використовуються моки, отже певний функціонал емулюється в цьому випадку нам не важливо як відпрацює та функція нам є важливим те, що вона була викликана і повернула певний результат від якого може залежити виклик інакшої функції і.т.д. Стосовно коментарів ти маєш на увазі під кожен assert проставити внаслідок чого він викликаєтсья?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так, щоб було якесь пояснення його причини.

@oleksiyVeretiuk oleksiyVeretiuk changed the title Loaders for auth WIP Loaders for auth Dec 13, 2018
create_users_from_group,
_ini_auth,
_yaml_auth,
_json_auth
Copy link

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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можна якісь коменти або еррор меседжі по цих асертах? Бо незрозуміло що вони тестують.

@oleksiyVeretiuk oleksiyVeretiuk changed the title WIP Loaders for auth Loaders for auth Dec 14, 2018
if not config:
LOGGER.warning("Auth file '%s' was empty, no user will be added",
file_path)
for item in config:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут іменування item i config потрібно змінити на доцільніші.

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()))
Copy link
Member

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 вартувало б тут присвоїти, а не просто апдейтнути.

Copy link
Author

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

Copy link
Member

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 присвоюватимемо у читабельну проміжну змінну.



# Backward compatibility for `file` type
auth_mapping['file'] = ini_auth
Copy link
Member

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 не дасть аналогічного ефекту?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хочеш зробити декоратор на декоруєму функцію?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавити другий декоратор

@leits leits merged commit ddf85b2 into openprocurement:ea_core_master Dec 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants