Skip to content

Commit

Permalink
example created and tests with unittest created
Browse files Browse the repository at this point in the history
  • Loading branch information
Omicron166 committed Mar 6, 2022
1 parent decfc9d commit f0b49ed
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
18 changes: 18 additions & 0 deletions clients/python/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#Before running this script, run python -m http.server in the server folder

from lns import Client #The actual client
from lns import IncompatibleServer, NameNotFound #Errors raised by the client

try:
resolver = Client('http://localhost:8000')
except IncompatibleServer:
#The server is not compatible with yout client
pass

print(resolver.resolve('template'))
#Expected output: dns.google.com

try:
print(resolver.resolve('Paraguay'))
except NameNotFound: #When a name can't be resolved, the client raise this exception
print('The regsitry does not exists')
41 changes: 27 additions & 14 deletions clients/python/test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
#Before running this script, run python -m http.server in the server folder
import unittest
from lns import Client, IncompatibleServer, NameNotFound

from lns import Client #The actual client
from lns import IncompatibleServer, NameNotFound #Errors raised by the client
class LNSTest(unittest.TestCase):
def test_lns_server_connection(self):
#Test connection to server
try: Client('https://omicronlns.glitch.me')
except: self.failureException()

try:
resolver = Client('http://localhost:8000')
except IncompatibleServer:
#The server is not compatible with yout client
pass
#test exception raise
with self.assertRaises(IncompatibleServer):
Client('google.com')

def test_lns_resolver(self):
#test the resolver system
lns = Client('https://omicronlns.glitch.me')
self.assertEqual(lns.resolve('template'), 'dns.google.com')

print(resolver.resolve('template'))
#Expected output: dns.google.com
def test_lns_dig(self):
#test the dig system
lns = Client('https://omicronlns.glitch.me')
self.assertEqual(lns.dig('template'), {
"recorder": "Omicron166",
"record": {
"link": "dns.google.com",
"txt": "dns like txt record"
}
})

try:
print(resolver.resolve('Paraguay'))
except NameNotFound: #When a name can't be resolved, the client raise this exception
print('The regsitry does not exists')
if __name__ == '__main__':
unittest.main()

0 comments on commit f0b49ed

Please sign in to comment.