Ejemplo n.º 1
0
def period_avail(period, days, hours, minutes):
    plist = ('daily', 'weekly', 'monthly', 'yearly')
    av = Availability(days, hours, minutes)
    if period in plist and isinstance(period, str):
        return json.dumps(av.service(period=period, out_dict=True))
    else:
        return json.dumps({"error":"period not properly set, must be of : "
                            + str(plist)})
Ejemplo n.º 2
0
class TestAvailabilityClass(unittest.TestCase):
    def setUp(self):
        self.avail = Availability(0, 0, 0)
        self.avail_x = Availability(0, 5, 15)

    def test_100(self):
        avail_dict_100_res = {
            "monthly": 100.0,
            "yearly": 100.0,
            "daily": 100.0,
            "weekly": 100.0
        }
        avail_100_res = (100.0, 100.0, 100.0, 100.0)
        self.assertEqual(self.avail.service(out_dict=True), avail_dict_100_res)
        self.assertEqual(self.avail.service(), avail_100_res)

    def test_daily_100(self):
        avail_daily = {"daily": 100.0}
        avail_daily_t = (100.0)
        self.assertEqual(self.avail.service(period='daily', out_dict=True),
                         avail_daily)
        self.assertEqual(self.avail.service(period='daily'), avail_daily_t)

    def test_weekly_100(self):
        avail_weekly = {"weekly": 100.0}
        avail_weekly_t = (100.0)
        self.assertEqual(self.avail.service(period='weekly', out_dict=True),
                         avail_weekly)
        self.assertEqual(self.avail.service(period='weekly'), avail_weekly_t)

    def test_monthly_100(self):
        avail_monthly = {"monthly": 100.0}
        avail_monthly_t = (100.0)
        self.assertEqual(self.avail.service(period='monthly', out_dict=True),
                         avail_monthly)
        self.assertEqual(self.avail.service(period='monthly'), avail_monthly_t)

    def test_yearly_100(self):
        avail_yearly = {"yearly": 100.0}
        avail_yearly_t = (100.0)
        self.assertEqual(self.avail.service(period='yearly', out_dict=True),
                         avail_yearly)
        self.assertEqual(self.avail.service(period='yearly'), avail_yearly_t)
Ejemplo n.º 3
0
def avail(days, hours, minutes):
    av = Availability(days, hours, minutes)
    return json.dumps(av.service(out_dict=True))
Ejemplo n.º 4
0
down_reg = re.compile(r'^(\d+)d(\d+)h(\d+)m$')
format_match = False

print('Enter downtime')
print('Use format XdYhZm')
print('\tWhere X is number of day, Y number of Hours and Z number of minutes')
print('\tWith X,Y,Z are integer and 0 as minimum or none value')
while not format_match:
    downtime = str(input('>'))
    if down_reg.match(downtime):
        format_match = True
    else:
        print('Format entered not compatible !')

downtime_match = down_reg.search(downtime)
#print(type(downtime_match.group(1)))
down = Availability(int(downtime_match.group(1)), int(downtime_match.group(2)),
                    int(downtime_match.group(3)))

daily = down.service(period='daily')
print(daily)
weekly = down.service(period='weekly')
print(weekly)
monthly = down.service(period='monthly', out_dict=True)
print(monthly)
fullsla = down.service(out_dict=True)
print(json.dumps(fullsla))
#err_test = down.period_uptime(-32)
#err_test = down.period_uptime('fail')
#err_test = down.period_uptime(5.43)