2020-07-20 13:56:18 +02:00
|
|
|
import pytest
|
2020-09-03 03:10:09 +02:00
|
|
|
from unittest import TestCase, mock
|
2020-07-20 13:56:18 +02:00
|
|
|
|
2020-09-03 03:10:09 +02:00
|
|
|
import core.config
|
|
|
|
import core.widget
|
|
|
|
import modules.contrib.publicip
|
2020-07-20 13:56:18 +02:00
|
|
|
|
2020-09-03 03:10:09 +02:00
|
|
|
|
|
|
|
def build_module():
|
|
|
|
config = core.config.Config([])
|
|
|
|
return modules.contrib.publicip.Module(config=config, theme=None)
|
|
|
|
|
|
|
|
def widget(module):
|
|
|
|
return module.widgets()[0]
|
|
|
|
|
|
|
|
class PublicIPTest(TestCase):
|
|
|
|
def test_load_module(self):
|
|
|
|
__import__("modules.contrib.publicip")
|
|
|
|
|
|
|
|
@mock.patch('util.location.public_ip')
|
|
|
|
def test_public_ip(self, public_ip_mock):
|
|
|
|
public_ip_mock.return_value = '5.12.220.2'
|
|
|
|
|
|
|
|
module = build_module()
|
|
|
|
module.update()
|
|
|
|
|
|
|
|
assert widget(module).full_text() == '5.12.220.2'
|
|
|
|
|
|
|
|
@mock.patch('util.location.public_ip')
|
|
|
|
def test_public_ip_with_exception(self, public_ip_mock):
|
|
|
|
public_ip_mock.side_effect = Exception
|
|
|
|
|
|
|
|
module = build_module()
|
|
|
|
module.update()
|
|
|
|
|
|
|
|
assert widget(module).full_text() == 'n/a'
|
|
|
|
|
2020-09-03 03:16:58 +02:00
|
|
|
def test_interval_seconds(self):
|
2020-09-03 03:10:09 +02:00
|
|
|
module = build_module()
|
|
|
|
|
|
|
|
assert module.parameter('interval') == 3600
|