From f0b49ed3a0556a3372157cac4741685fb425551f Mon Sep 17 00:00:00 2001 From: Omicron166 <64985125+Omicron166@users.noreply.github.com> Date: Sun, 6 Mar 2022 10:56:46 +0100 Subject: [PATCH] example created and tests with unittest created --- clients/python/example.py | 18 +++++++++++++++++ clients/python/test.py | 41 ++++++++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 clients/python/example.py diff --git a/clients/python/example.py b/clients/python/example.py new file mode 100644 index 0000000..df9ec9b --- /dev/null +++ b/clients/python/example.py @@ -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') diff --git a/clients/python/test.py b/clients/python/test.py index df9ec9b..1523489 100644 --- a/clients/python/test.py +++ b/clients/python/test.py @@ -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() \ No newline at end of file