Esempio n. 1
0
def rand_switch(**kwargs):
    ret = cli_lic.PublicApi().switch_list_get(**kwargs)
    if not len(ret.payload.items):
        return None
    assert (ret.success and len(ret.payload.items))
    it = random.choice(ret.payload.items)
    return (it.switch_uuid, it, ret.payload.items)
Esempio n. 2
0
def rand_package_lrn(**kwargs):
    ret = cli_lic.PublicApi().package_lrn_list_get(**kwargs)
    assert (ret.success and len(ret.payload.items))
    it = random.choice(ret.payload.items)
    return (it.package_lrn_uuid, it, ret.payload.items)
Esempio n. 3
0
    def test_package_switch_post(self):
        """
        Test case for package_switch_post


        """
        auth()
        # if not rand_switch():
        #     self.test_switch_post()
        data = dict(package_name='switch_{}'.format(dig(10)),
                    cps=random.randint(10, 1000),
                    switch_port=random.randint(1000, 65535),
                    type=random.choice(
                        ['switch pay per port', 'switch pay per minute']),
                    minute_count=random.randint(10, 1000),
                    amount=random.randint(10, 1000),
                    enabled=True,
                    expire_date=str(datetime.now(UTC) + timedelta(days=30)))
        ret = self.api.package_switch_post(body=data)
        assert (ret.success)
        self.package_switch.append(ret.object_uuid)
        return

        f = open('api_lic/test/data/switch_port_pricing.csv', 'rt')
        r = csv.DictReader(f, fieldnames=['type', 'port', 'price'])
        for i in r:
            print(i)
            ret = cli_lic.PublicApi().package_switch_list_get(
                switch_port=int(i['port']),
                type='switch pay per port',
                sub_type=i['type'])
            if ret.payload.items:
                print('---')
                continue
            data = dict(package_name='switch_port_{port}_{type}'.format_map(i),
                        switch_port=int(i['port']),
                        type='switch pay per port',
                        sub_type=i['type'],
                        amount=float(i['price']),
                        enabled=True)
            ret = self.api.package_switch_post(body=data)
        f.close()

        f = open('api_lic/test/data/switch_minute_pricing.csv', 'rt')
        r = csv.DictReader(f, fieldnames=['type', 'minute', 'rate', 'price'])
        for i in r:
            print(i)
            ret = cli_lic.PublicApi().package_switch_list_get(
                minute_count=int(i['minute']),
                type='switch pay per minute',
                sub_type=i['type'])
            if ret.payload.items:
                print('---')
                continue
            data = dict(
                package_name='switch_minute_{minute}_{type}'.format_map(i),
                minute_count=int(i['minute']),
                type='switch pay per minute',
                sub_type=i['type'],
                amount=float(i['price']),
                enabled=True)
            ret = self.api.package_switch_post(body=data)
        f.close()
        pass