Rename module ogn.gateway to ogn.client

Renamed also class ognGateway to AprsClient to comply with the PEP8 naming
convention and to emphasis that it is a generic aprs client, not ogn specific.
pull/2/head
Fabian P. Schmidt 2016-02-28 12:28:43 +01:00
rodzic bf03ac39dd
commit abae52b165
6 zmienionych plików z 37 dodań i 37 usunięć

Wyświetl plik

@ -2,7 +2,7 @@ import socket
import logging
from time import time
from ogn.gateway import settings
from ogn.client import settings
def create_aprs_login(user_name, pass_code, app_name, app_version, aprs_filter=None):
@ -12,7 +12,7 @@ def create_aprs_login(user_name, pass_code, app_name, app_version, aprs_filter=N
return "user {} pass {} vers {} {} filter {}\n".format(user_name, pass_code, app_name, app_version, aprs_filter)
class ognGateway:
class AprsClient:
def __init__(self, aprs_user, aprs_filter=''):
self.logger = logging.getLogger(__name__)
self.logger.info("Connect to OGN as {} with filter '{}'".format(aprs_user, (aprs_filter if aprs_filter else 'full-feed')))

Wyświetl plik

@ -2,7 +2,7 @@ APRS_SERVER_HOST = 'aprs.glidernet.org'
APRS_SERVER_PORT_FULL_FEED = 10152
APRS_SERVER_PORT_CLIENT_DEFINED_FILTERS = 14580
APRS_APP_NAME = 'ogn-gateway-python'
APRS_APP_NAME = 'python-ogn-client'
PACKAGE_VERSION = '0.2.1'
APRS_APP_VER = PACKAGE_VERSION[:3]

Wyświetl plik

@ -0,0 +1,34 @@
import unittest
import unittest.mock as mock
from ogn.client.client import create_aprs_login, AprsClient
from ogn.client.settings import APRS_APP_NAME, APRS_APP_VER
class OgnClientTest(unittest.TestCase):
def test_create_aprs_login(self):
basic_login = create_aprs_login('klaus', -1, 'myApp', '0.1')
self.assertEqual('user klaus pass -1 vers myApp 0.1\n', basic_login)
login_with_filter = create_aprs_login('klaus', -1, 'myApp', '0.1', 'r/48.0/11.0/100')
self.assertEqual('user klaus pass -1 vers myApp 0.1 filter r/48.0/11.0/100\n', login_with_filter)
def test_initialisation(self):
client = AprsClient(aprs_user='testuser', aprs_filter='')
self.assertEqual(client.aprs_user, 'testuser')
self.assertEqual(client.aprs_filter, '')
@mock.patch('ogn.client.client.socket')
def test_connect_full_feed(self, mock_socket):
client = AprsClient(aprs_user='testuser', aprs_filter='')
client.connect()
client.sock.send.assert_called_once_with('user testuser pass -1 vers {} {}\n'.format(APRS_APP_NAME, APRS_APP_VER).encode('ascii'))
client.sock.makefile.asser_called_once_with('rw')
@mock.patch('ogn.client.client.socket')
def test_disconnect(self, mock_socket):
client = AprsClient(aprs_user='testuser', aprs_filter='')
client.connect()
client.disconnect()
client.sock.shutdown.assert_called_once_with(0)
client.sock.close.assert_called_once_with()

Wyświetl plik

@ -1,34 +0,0 @@
import unittest
import unittest.mock as mock
from ogn.gateway.client import create_aprs_login, ognGateway
from ogn.gateway.settings import APRS_APP_NAME, APRS_APP_VER
class GatewayTest(unittest.TestCase):
def test_create_aprs_login(self):
basic_login = create_aprs_login('klaus', -1, 'myApp', '0.1')
self.assertEqual('user klaus pass -1 vers myApp 0.1\n', basic_login)
login_with_filter = create_aprs_login('klaus', -1, 'myApp', '0.1', 'r/48.0/11.0/100')
self.assertEqual('user klaus pass -1 vers myApp 0.1 filter r/48.0/11.0/100\n', login_with_filter)
def test_initialisation(self):
self.gw = ognGateway(aprs_user='testuser', aprs_filter='')
self.assertEqual(self.gw.aprs_user, 'testuser')
self.assertEqual(self.gw.aprs_filter, '')
@mock.patch('ogn.gateway.client.socket')
def test_connect(self, mock_socket):
self.gw = ognGateway(aprs_user='testuser', aprs_filter='')
self.gw.connect()
self.gw.sock.send.assert_called_once_with('user testuser pass -1 vers {} {}\n'.format(APRS_APP_NAME, APRS_APP_VER).encode('ascii'))
self.gw.sock.makefile.asser_called_once_with('rw')
@mock.patch('ogn.gateway.client.socket')
def test_disconnect(self, mock_socket):
self.gw = ognGateway(aprs_user='testuser', aprs_filter='')
self.gw.connect()
self.gw.disconnect()
self.gw.sock.shutdown.assert_called_once_with(0)
self.gw.sock.close.assert_called_once_with()