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

Only create a section when we initialise #89

Merged
merged 9 commits into from
Apr 20, 2018

Conversation

drewsonne
Copy link
Contributor

We should not create a section when reading/writing only if it does not exist.

We should only create a section if we are trying to modify/write to the config file and the section does not exist.

@codecov-io
Copy link

codecov-io commented Apr 20, 2018

Codecov Report

Merging #89 into master will decrease coverage by 0.49%.
The diff coverage is 70%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #89     +/-   ##
=========================================
- Coverage   75.57%   75.08%   -0.5%     
=========================================
  Files           6        6             
  Lines         303      309      +6     
=========================================
+ Hits          229      232      +3     
- Misses         74       77      +3
Impacted Files Coverage Δ
onelogin_aws_cli/configuration.py 94.73% <70%> (-5.27%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2fc2451...900f957. Read the comment docs.

@@ -69,7 +72,7 @@ def section(self, section_name: str):
:return:
"""
if not self.has_section(section_name):
self.add_section(section_name)
return None
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to check that section_name != self.default_section. has_section will return false for self.default_section and that's going to lead to weirdness.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh... do we assume the defaults section always exists?

If we do not assume it always exists and it doesn't exist we end up in a case where we can not know if it exists.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, it's confusing, that's why I had to add that confusing has_defaults prop in the other PR.
Although please let me know if there's an easier way to approach it.

@slycoder
Copy link
Contributor

Agree this makes things much cleaner, thanks.

@drewsonne
Copy link
Contributor Author

I stole some of your code, I hope you do not mind, but there will probably be merge conflicts

@drewsonne drewsonne force-pushed the feature/explicit-section-create branch from f46ce5f to 63b73d5 Compare April 20, 2018 06:42

self.file = config_file

if self.file is not None:
self.load()

@property
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically not needed anymore (at least in this PR) =)

if not self.has_section(section_name):
self.add_section(section_name)
section_missing = not self.has_section(section_name)
not_default = self.default_section != section_name
Copy link
Contributor

Choose a reason for hiding this comment

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

Could probably use some coverage for this case, but your other PR will probably cover it just by calling login without -C

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I was thinking that when the test cases passed after I modified it

def __init__(self, config_file=None):
super().__init__(default_section='defaults')

self['defaults'] = dict(save_password=False)
self[self.default_section] = self.DEFAULTS
Copy link
Contributor

Choose a reason for hiding this comment

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

The reason I added the dict is to create a copy (in case changes in to the defaults across multiple instantiations in the unittests cross-pollute)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool, I rolled that commit back

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have to come back to the test case another day, so we can either wait, or I'll create an issue to add the new test case.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can just push this and worry about it in one of the other PRs =).

@drewsonne drewsonne force-pushed the feature/explicit-section-create branch from 429547c to 900f957 Compare April 20, 2018 07:13
@slycoder slycoder merged commit b7653d4 into physera:master Apr 20, 2018
@drewsonne drewsonne deleted the feature/explicit-section-create branch April 20, 2018 07:19
@drewsonne drewsonne restored the feature/explicit-section-create branch April 21, 2018 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants