bumblebee-status/tests/modules/contrib/test_publicip.py

65 lines
1.7 KiB
Python
Raw Normal View History

import pytest
2020-09-03 03:10:09 +02:00
from unittest import TestCase, mock
2020-09-03 03:10:09 +02:00
import core.config
import core.widget
import modules.contrib.publicip
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")
2022-07-29 14:00:28 +02:00
@mock.patch('util.location.location_info')
def test_public_ip(self, location_mock):
location_mock.return_value = {
'public_ip': '5.12.220.2',
'latitude': 0,
'longitude': 2,
'country': 'some country',
'country_code': 'sc',
'city_name': '???',
}
2020-09-03 03:10:09 +02:00
module = build_module()
module.update()
2022-07-29 14:00:28 +02:00
assert widget(module).full_text() == '5.12.220.2 (sc)'
2020-09-03 03:10:09 +02:00
2022-07-29 14:00:28 +02:00
@mock.patch('util.location.location_info')
def test_public_ip2(self, location_mock):
location_mock.return_value = {
'public_ip': None,
'latitude': 0,
'longitude': 2,
'country': 'some country',
'country_code': 'sc',
'city_name': '???',
}
module = build_module()
module.update()
assert widget(module).full_text() == 'n/a'
2022-07-29 14:00:28 +02:00
@mock.patch('util.location.location_info')
def test_public_ip_with_exception(self, location_mock):
location_mock.side_effect = Exception
2020-09-03 03:10:09 +02:00
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