-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example created and tests with unittest created
- Loading branch information
1 parent
decfc9d
commit f0b49ed
Showing
2 changed files
with
45 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |