-
-
Notifications
You must be signed in to change notification settings - Fork 399
/
Copy pathtest_util_mbserver.py
118 lines (100 loc) · 4.38 KB
/
test_util_mbserver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# -*- coding: utf-8 -*-
#
# Picard, the next-generation MusicBrainz tagger
#
# Copyright (C) 2021-2022 Laurent Monin
# Copyright (C) 2021-2022 Philipp Wolfer
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from test.picardtestcase import PicardTestCase
from picard.const import MUSICBRAINZ_SERVERS
from picard.util.mbserver import (
build_submission_url,
get_submission_server,
is_official_server,
)
class IsOfficialServerTest(PicardTestCase):
def test_official(self):
for host in MUSICBRAINZ_SERVERS:
self.assertTrue(is_official_server(host))
def test_not_official(self):
self.assertFalse(is_official_server('test.musicbrainz.org'))
self.assertFalse(is_official_server('example.com'))
self.assertFalse(is_official_server('127.0.0.1'))
self.assertFalse(is_official_server('localhost'))
class GetSubmissionServerTest(PicardTestCase):
def test_official(self):
for host in MUSICBRAINZ_SERVERS:
self.set_config_values(setting={
'server_host': host,
'server_port': 80,
'use_server_for_submission': False,
})
self.assertEqual((host, 443), get_submission_server())
def test_use_unofficial(self):
self.set_config_values(setting={
'server_host': 'example.com',
'server_port': 8042,
'use_server_for_submission': True,
})
self.assertEqual(('example.com', 8042), get_submission_server())
def test_unofficial_fallback(self):
self.set_config_values(setting={
'server_host': 'test.musicbrainz.org',
'server_port': 80,
'use_server_for_submission': False,
})
self.assertEqual((MUSICBRAINZ_SERVERS[0], 443), get_submission_server())
def test_named_tuple(self):
self.set_config_values(setting={
'server_host': 'example.com',
'server_port': 8042,
'use_server_for_submission': True,
})
server = get_submission_server()
self.assertEqual('example.com', server.host)
self.assertEqual(8042, server.port)
class BuildSubmissionUrlTest(PicardTestCase):
def test_official(self):
for host in MUSICBRAINZ_SERVERS:
self.set_config_values(setting={
'server_host': host,
'server_port': 80,
'use_server_for_submission': False,
})
self.assertEqual('https://%s' % host, build_submission_url())
self.assertEqual('https://%s/' % host, build_submission_url('/'))
self.assertEqual('https://%s/some/path?foo=1&bar=baz' % host,
build_submission_url('/some/path', {'foo': 1, 'bar': 'baz'}))
def test_use_unofficial(self):
self.set_config_values(setting={
'server_host': 'example.com',
'server_port': 8042,
'use_server_for_submission': True,
})
self.assertEqual('http://example.com:8042', build_submission_url())
self.assertEqual('http://example.com:8042/', build_submission_url('/'))
self.assertEqual('http://example.com:8042/some/path?foo=1&bar=baz',
build_submission_url('/some/path', {'foo': 1, 'bar': 'baz'}))
def test_unofficial_fallback(self):
self.set_config_values(setting={
'server_host': 'test.musicbrainz.org',
'server_port': 80,
'use_server_for_submission': False,
})
self.assertEqual('https://musicbrainz.org', build_submission_url())
self.assertEqual('https://musicbrainz.org/', build_submission_url('/'))
self.assertEqual('https://musicbrainz.org/some/path?foo=1&bar=baz',
build_submission_url('/some/path', {'foo': 1, 'bar': 'baz'}))