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

Enable connecting to a custom MusicBrainz server #210

Merged
merged 3 commits into from Jan 6, 2018
Merged

Enable connecting to a custom MusicBrainz server #210

merged 3 commits into from Jan 6, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jan 1, 2018

Adresses #172 with a new [musicbrainz] section in the config.

@Freso
Copy link
Member

Freso commented Jan 2, 2018

Does this make it default to https://musicbrainz.org/ ? Is it possible to use this with a non-HTTPS localhost?

@Freso
Copy link
Member

Freso commented Jan 2, 2018

Also, I know that whipper is lacking a lot of tests right now, but it does have some. It would be great if this new code could also have tests. At the very least unit tests for get_musicbrainz_server() and getMusicBrainzSubmitURL().

self._config.write()

self.assertEquals(self._config.get_musicbrainz_server(),
'192.168.2.141:5000')
Copy link
Member

Choose a reason for hiding this comment

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

I would have these calls listed without empty lines between them, and preferably with a #comment just prior to them to give a more "prosaic" version of what's going on.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it might even be nicer to make the "prosaic" comments the msg= param to assertEquals(), as mentioned below.

self.assertEquals(self._config.get_musicbrainz_server(),
'192.168.2.141:5000')

self._config._parser.remove_section('musicbrainz')
Copy link
Member

Choose a reason for hiding this comment

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

This seems like something that should be done in a "tear down" function/method. What happens if the test breaks before it gets to this call?

Copy link
Author

Choose a reason for hiding this comment

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

I agree, but I can't see a good way to handle it, since it's not common to the all (or even the majority) of the tests.

self._config.write()

self.assertEquals(self._config.get_musicbrainz_server(),
'192.168.2.141:5000')
Copy link
Member

Choose a reason for hiding this comment

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

And again here with the blank lines.

@Freso
Copy link
Member

Freso commented Jan 4, 2018

Seems like the flake8 error is in whipper/common/cache.py, so not a file you're touching in the PR, so that can be ignored.

@JoeLametta
Copy link
Collaborator

JoeLametta commented Jan 4, 2018

Travis Flake8 build is failing (bare except), but tests do pass.

Fixed that a few minutes ago (master branch).

server = self.get('musicbrainz', 'server') or 'musicbrainz.org'
server_url = server if re.match(r'^\D*//', server) else '//' + server
return urlparse(server_url).netloc

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this is an alternative without regex?

>>> server
'musicbrainz.org'
>>> server_url = urlparse(server)
>>> if server_url.scheme == '': server_url = urlparse('//' + server)
...
>>> server_url.netloc
'musicbrainz.org'

To be fair, I'd even prefer it to accept only scheme == '' or scheme in ('http', 'https').

This way, afaik, people can set the server to 'ftp://musicbrainz.org' and have it still work.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or even only accept no scheme only, since the documentation states:

the MusicBrainz server to connect to, in `host:[port]` format. Defaults to `musicbrainz.org`.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For the record, you don't have to change it, but we should update the documentation to reflect what we actually accept in any case. Otherwise it looks great!

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for implementation without using the regular expression, I like the no-scheme suggestion the best.

Copy link
Author

@ghost ghost Jan 5, 2018

Choose a reason for hiding this comment

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

@MerlijnWajer The alternative would be cleaner, but it doesn't quite work in some cases:

>>> urlparse('192.168.2.97:5000/hello').scheme
192.168.2.97
>>> k = urlparse('192.168.2.97/hello')
>>> k.scheme
''
>>> k.netloc
''

set_hostname will only accept host:[port], so perhaps it's best to just add to the docs - The schema and anything after the port number will be stripped out before use. or something similar.

Copy link
Collaborator

Choose a reason for hiding this comment

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

192.168.2.97/hello is indeed not what the docs specify. If you can only set the hostname I would simply not accept 192.168.2.97/hello as valid URL. If anything, it'll be confusing to people who do set the URI and expect it to have any effect.

def test_get_musicbrainz_server(self):
# Test default return value
self.assertEquals(self._config.get_musicbrainz_server(),
'musicbrainz.org')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be worth adding a msg= param to assertEquals to say that this a test of the default value.

'192.168.2.141:5000/hello/world')
self._config.write()
self.assertEquals(self._config.get_musicbrainz_server(),
'192.168.2.141:5000')
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be worth stating that the expected behaviour is for get_musicbrainz_server() to strip the path after the port number in a msg= param, but I don't feel strongly about it.

@RecursiveForest
Copy link
Contributor

Overall this looks great to me.

Under the new [musicbrainz] section in the config,
you can set a server to connect to.

Closes #172.
@MerlijnWajer
Copy link
Collaborator

MerlijnWajer commented Jan 6, 2018

Thanks!

@MerlijnWajer MerlijnWajer merged commit 74e3f7b into whipper-team:master Jan 6, 2018
@ghost ghost deleted the custom-mbserver branch January 7, 2018 01:10
@JoeLametta
Copy link
Collaborator

@naiveaiguy Thank you for the PR!

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.

5 participants