2014-09-02 15:10:42 -04:00
|
|
|
"""
|
|
|
|
OnionShare | https://onionshare.org/
|
|
|
|
|
2017-01-06 21:58:15 -05:00
|
|
|
Copyright (C) 2017 Micah Lee <micah@micahflee.com>
|
2014-09-02 15:10:42 -04:00
|
|
|
|
|
|
|
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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
2017-04-19 12:06:54 -04:00
|
|
|
import socket
|
2017-05-16 14:05:48 -04:00
|
|
|
from onionshare import common
|
2014-08-26 21:38:46 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_platform_returns_platform_system():
|
2014-11-18 11:39:04 -05:00
|
|
|
"""get_platform() returns platform.system() when ONIONSHARE_PLATFORM is not defined"""
|
2017-05-16 14:05:48 -04:00
|
|
|
p = common.platform.system
|
|
|
|
common.platform.system = lambda: 'Sega Saturn'
|
|
|
|
assert common.get_platform() == 'Sega Saturn'
|
|
|
|
common.platform.system = p
|
2017-04-19 12:06:54 -04:00
|
|
|
|
|
|
|
def test_get_available_port_returns_an_open_port():
|
|
|
|
"""get_available_port() should return an open port within the range"""
|
|
|
|
for i in range(100):
|
2017-05-16 14:05:48 -04:00
|
|
|
port = common.get_available_port(1024, 2048)
|
2017-04-19 12:06:54 -04:00
|
|
|
assert 1024 <= port <= 2048
|
|
|
|
socket.socket().bind(("127.0.0.1", port))
|