Skip to content

Conversation

wolkiewiczk
Copy link

Fixes #309 .

I was not able to run tests locally because of my postgresql broke from unknown reason. I am trying to fix it but decided to make a pull request anyway so you can check it. There was more to change than i previously thought but hope everything is ok. Please check my code and leave your comments if something is not ok.

@coveralls
Copy link

coveralls commented Jul 31, 2020

Coverage Status

Coverage increased (+1.5%) to 58.182% when pulling ee7870d on wolkiewiczk:bug-309-unable-to-set-password into fd378fc on ClearcodeHQ:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.5%) to 58.182% when pulling b4c5164 on wolkiewiczk:bug-309-unable-to-set-password into fd378fc on ClearcodeHQ:master.

)
password_file.write(self.password)
# Without seek(0), PostgreSQL will se password file as empty
password_file.seek(0)
Copy link
Member

Choose a reason for hiding this comment

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

flush, we don't need to read, so no need to seek

Copy link
Author

Choose a reason for hiding this comment

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

Right, I changed that to flush()

with tempfile.NamedTemporaryFile(mode='w') as password_file:
init_directory += (
'--pwfile "%s"' % password_file.name,
'-o "--auth=trust --username={} --pwfile={}"'.format(
Copy link
Member

Choose a reason for hiding this comment

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

you can have many -o outputs, add here only the pwfile

Copy link
Author

Choose a reason for hiding this comment

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

Didn't know about that! Surely that simplifies code. Added.


if self.password:
with tempfile.NamedTemporaryFile() as password_file:
with tempfile.NamedTemporaryFile(mode='w') as password_file:
Copy link
Member

Choose a reason for hiding this comment

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

when flushing, the mode=w is not needed.

Copy link
Author

Choose a reason for hiding this comment

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

Yea, I've added that to make write function accept password as str. Now i saw that in your pull request you've added password encoding in init so I decided to leave the default mode. If you think it is not a good idea to leave it not working without your pr then tell me about it and I will change.

assert postgresql_rand.status == psycopg2.extensions.STATUS_READY


def test_rand_postgres_port(postgresql_password):
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd love specific executor test, but I already have one on other Pull request. This is great as well!

Copy link
Member

Choose a reason for hiding this comment

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

Just the name overshadows the previous one

Copy link
Author

Choose a reason for hiding this comment

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

Oh, yes, sorry. Didn't see that. Fixed.

self.executable, 'initdb',
'-o "--auth=trust --username=%s"' % self.user,
'-D %s' % self.datadir,
self.executable, 'initdb', '-D {}'.format(self.datadir)
Copy link
Member

Choose a reason for hiding this comment

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

prefer f strings if migrating to other formatting type.

Copy link
Author

Choose a reason for hiding this comment

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

Sure, changed.

…ry write mode from tempfile, changed output flag to multiple ones
Copy link
Member

@fizyk fizyk left a comment

Choose a reason for hiding this comment

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

As I see it just the test name to be fixed. Other than that it's all good.

assert postgresql_rand.status == psycopg2.extensions.STATUS_READY


def test_rand_postgres_port(postgresql_password):
Copy link
Member

Choose a reason for hiding this comment

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

Just the name overshadows the previous one

@wolkiewiczk
Copy link
Author

@fizyk Could you resolve the merge conflicts please? I see that someone has made some fixed before me and i think it's better if you decide which of the solutions is better as you are the member of a core team.

@fizyk
Copy link
Member

fizyk commented Aug 17, 2020

@wolkiewiczk I will look at it, just got back from time off :)

@fizyk
Copy link
Member

fizyk commented Aug 21, 2020

@wolkiewiczk actually both are fine. I tried to rebase but messed something terribly during. So I think I'll leave as it is. Sorry for that. But you did good job anyway.

Thank you!

@fizyk fizyk closed this Aug 21, 2020
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.

Unable to set database password

3 participants