# Path: bots/botslib.py
# class Uri(object):
#     ''' generate uri from parts/components
#         - different forms of uri (eg with/without password)
#         - general layout like 'scheme://user:pass@hostname:80/path/filename?query=argument#fragment'
#         - checks: 1. what is required; 2. all parameters need to be valid
#         Notes:
#         - no filename: path ends with '/'
#         Usage: uri = Uri(scheme='http',username='hje',password='password',hostname='test.com',port='80', path='')
#         Usage: uri = Uri(scheme='http',hostname='test.com',port='80', path='test')
#     '''
#     def __init__(self, **kw):
#         self._uri = dict(scheme='',username='',password='',hostname='',port='', path='', filename='',query={},fragment='')
#         self.update(**kw)
#     def update( self, **kw):
#         self._uri.update(**kw)
#     def uri(self, **kw):
#         self.update(**kw)
#         return self.__str__()
#     def __str__(self):
#         scheme   = self._uri['scheme'] + ':' if self._uri['scheme'] else ''
#         password = ':' + self._uri['password'] if self._uri['password'] else ''
#         userinfo = self._uri['username'] + password + '@' if self._uri['username'] else ''
#         port     = ':' + unicode(self._uri['port']) if self._uri['port'] else ''
#         fullhost = self._uri['hostname'] + port if self._uri['hostname'] else ''
#         authority = '//' + userinfo + fullhost if fullhost else ''
#         if self._uri['path'] or self._uri['filename']:
#             terug = os.path.join(authority,self._uri['path'],self._uri['filename'])
#         else:
#             terug = authority
#         return scheme + terug


import unittest
from bots.botslib import Uri

'''no plugin
'''

class TestTranslate(unittest.TestCase):
    def setUp(self):
        pass

    def testcombinations(self):
        self.assertEqual('scheme://username:password@hostname:80/path1/path2/filename',str(Uri(scheme='scheme',username='username',password='password',hostname='hostname',port=80,path='path1/path2',filename= 'filename',query={'query':'argument'},fragment='fragment')),'basis')
        self.assertEqual('scheme://username:password@hostname:80/path1/path2/filename',str(Uri(scheme='scheme',username='username',password='password',hostname='hostname',port=80,path='path1/path2',filename= 'filename')),'basis')
        
        self.assertEqual('scheme:/path1/path2/filename',str(Uri(scheme='scheme',path='/path1/path2',filename='filename')),'')
        self.assertEqual('scheme:path1/path2/filename',str(Uri(scheme='scheme',path='path1/path2',filename='filename')),'')
        self.assertEqual('path1/path2/filename',str(Uri(path='path1/path2',filename='filename')),'')
        self.assertEqual('path1/path2/',str(Uri(path='path1/path2')),'')
        self.assertEqual('filename',str(Uri(filename='filename')),'')
        self.assertEqual('scheme:path1/path2/',str(Uri(scheme='scheme',path='path1/path2')),'')
        self.assertEqual('scheme:filename',str(Uri(scheme='scheme',filename='filename')),'')

        self.assertEqual('scheme://username:password@hostname:80/path1/path2/',str(Uri(scheme='scheme',username='username',password='password',hostname='hostname',port=80,path='path1/path2')),'basis')
        self.assertEqual('scheme://username:password@hostname:80/filename',str(Uri(scheme='scheme',username='username',password='password',hostname='hostname',port=80,filename= 'filename')),'basis')

# Path: bots/botslib.py
# class Uri(object):
#     ''' generate uri from parts/components
#         - different forms of uri (eg with/without password)
#         - general layout like 'scheme://user:pass@hostname:80/path/filename?query=argument#fragment'
#         - checks: 1. what is required; 2. all parameters need to be valid
#         Notes:
#         - no filename: path ends with '/'
#         Usage: uri = Uri(scheme='http',username='hje',password='password',hostname='test.com',port='80', path='')
#         Usage: uri = Uri(scheme='http',hostname='test.com',port='80', path='test')
#     '''
#     def __init__(self, **kw):
#         self._uri = dict(scheme='',username='',password='',hostname='',port='', path='', filename='',query={},fragment='')
#         self.update(**kw)
#     def update( self, **kw):
#         self._uri.update(**kw)
#     def uri(self, **kw):
#         self.update(**kw)
#         return self.__str__()
#     def __str__(self):
#         scheme   = self._uri['scheme'] + ':' if self._uri['scheme'] else ''
#         password = ':' + self._uri['password'] if self._uri['password'] else ''
#         userinfo = self._uri['username'] + password + '@' if self._uri['username'] else ''
#         port     = ':' + unicode(self._uri['port']) if self._uri['port'] else ''
#         fullhost = self._uri['hostname'] + port if self._uri['hostname'] else ''
#         authority = '//' + userinfo + fullhost if fullhost else ''
#         if self._uri['path'] or self._uri['filename']:
#             terug = os.path.join(authority,self._uri['path'],self._uri['filename'])
#         else:
#             terug = authority
#         return scheme + terug


# Path: uniturl.py
import unittest
from bots.botslib import Uri


'''no plugin
'''

class TestTranslate(unittest.TestCase):
    def setUp(self):
        pass

    def testcombinations(self):
        self.assertEqual('scheme://username:password@hostname:80/path1/path2/filename',str(Uri(scheme='scheme',username='username',password='password',hostname='hostname',port=80,path='path1/path2',filename= 'filename',query={'query':'argument'},fragment='fragment')),'basis')
        self.assertEqual('scheme://username:password@hostname:80/path1/path2/filename',str(Uri(scheme='scheme',username='username',password='password',hostname='hostname',port=80,path='path1/path2',filename= 'filename')),'basis')
        
        self.assertEqual('scheme:/path1/path2/filename',str(Uri(scheme='scheme',path='/path1/path2',filename='filename')),'')
        self.assertEqual('scheme:path1/path2/filename',str(Uri(scheme='scheme',path='path1/path2',filename='filename')),'')
        self.assertEqual('path1/path2/filename',str(Uri(path='path1/path2',filename='filename')),'')
        self.assertEqual('path1/path2/',str(Uri(path='path1/path2')),'')
        self.assertEqual('filename',str(Uri(filename='filename')),'')
        self.assertEqual('scheme:path1/path2/',str(Uri(scheme='scheme',path='path1/path2')),'')
        self.assertEqual('scheme:filename',str(Uri(scheme='scheme',filename='filename')),'')

        self.assertEqual('scheme://username:password@hostname:80/path1/path2/',str(Uri(scheme='scheme',username='username',password='password',hostname='hostname',port=80,path='path1/path2')),'basis')
        self.assertEqual('scheme://username:password@hostname:80/filename',str(Uri(scheme='scheme',username='username',password='password',hostname='hostname',port=80,filename= 'filename')),'basis')

        self.assertEqual('scheme://username:password@hostname:80',str(Uri(scheme='scheme',username='username',password='password',hostname='hostname',port=80)),'bas')