Exemple #1
0
 def test_upload_IPList_fails_and_raisesException(self, mock_open):
     """
     Invalid format of IP List file
     """
     cfg = ("blah")
     mock_open.return_value = io.StringIO(u'{}'.format(cfg))
     iplist = IPList('smcpython-iplist')
     with self.assertRaises(CreateElementFailed):
         iplist.upload(filename='iplist.zip')
Exemple #2
0
    def test_IPList_createWithJson(self):
        if session.api_version >= 6.1:
            try:
                iplist = IPList('smcpython-iplist')
                iplist.delete()
            except ElementNotFound:
                pass

            ips = ['1.1.1.1', '2.2.2.2']
            ip = IPList.create(name='smcpython-iplist', iplist=ips)
            self.assertTrue(ip.href.startswith('http'))
def create_iplist(name):
    """
    Create an empty IPList as name

    :param str name: name of IPList
    :return: href of list location
    """
    iplist = IPList.create(name=name)
    return iplist
Exemple #4
0
def create_iplist(name):
    """
    Create an empty IPList as name
    
    :param str name: name of IPList
    :return: :py:class:`smc.api.web.SMCResult`
    """
    iplist = IPList.create(name=name)
    return iplist
Exemple #5
0
def create_iplist(name):
    """
    Create an empty IPList as name

    :param str name: name of IPList
    :return: href of list location
    """
    iplist = IPList.create(name=name)
    return iplist
def create_iplist_with_data(name, iplist):
    """
    Create an IPList with initial list contents.

    :param str name: name of IPList
    :param list iplist: list of IPList IP's, networks, etc
    :return: href of list location
    """
    iplist = IPList.create(name=name, iplist=iplist)
    return iplist
Exemple #7
0
def create_iplist_with_data(name, iplist):
    """
    Create an IPList with initial list contents.
    
    :param str name: name of IPList
    :param list iplist: list of IPList IP's, networks, etc
    :return: :py:class:`smc.api.web.SMCResult`
    """
    iplist = IPList.create(name=name, iplist=iplist)
    return iplist
Exemple #8
0
def create_iplist_with_data(name, iplist):
    """
    Create an IPList with initial list contents.

    :param str name: name of IPList
    :param list iplist: list of IPList IP's, networks, etc
    :return: href of list location
    """
    iplist = IPList.create(name=name, iplist=iplist)
    return iplist
Exemple #9
0
    def test_upload_IPList_as_txt(self, mock_open):
        if session.api_version >= 6.1:
            cfg = ("1.1.1.1\n2.2.2.2")
            mock_open.return_value = io.StringIO(u'{}'.format(cfg))
            iplist = None
            location = list(
                Search('ip_list').objects.filter('smcpython-iplist'))
            if location:
                iplist = location[0]
            else:
                iplist = IPList.create(name='smcpython-iplist')
                self.assertTrue(iplist.href.startswith('http'))

            result = iplist.upload(filename='iplist.txt', as_type='txt')
            self.assertIsNone(result)
            iplist.delete()
Exemple #10
0
    def test_upload_IPList_as_zip(self):
        if session.api_version >= 6.1:

            #zf = zipfile.ZipFile(io.BytesIO(), "a", zipfile.ZIP_DEFLATED, False)
            # Write the file to the in-memory zip
            #zf.writestr('ip_addresses', '1.1.1.1\n2.2.2.2\n3.3.3.3')
            # print(zf)

            #mock_open.return_value = ('iplist.zip', zf)
            iplist = None
            location = list(
                Search('ip_list').objects.filter('smcpython-iplist'))
            if location:
                iplist = location[0]
            else:
                iplist = IPList.create(name='smcpython-iplist')
                self.assertTrue(iplist.href.startswith('http'))

            result = iplist.upload(filename='iplist.zip')
            self.assertIsNone(result)