def test_generic_config_RHEL_JBOSS_same_rhic(self): ReportData.drop_collection() # create 1 RHEL, 2 JBoss entry_high = TestData.create_entry(RHEL, mem_high=True) entry_high.save(safe=True) entry_high = TestData.create_entry(JBoss, socket=5) entry_high.save(safe=True) entry_low = TestData.create_entry(JBoss, socket=4 ) entry_low.save(safe=True) delta=timedelta(days=1) start = datetime.now() - delta end = datetime.now() + delta environment = "us-east-1" lookup = ReportData.objects.all() self.assertEqual(len(lookup), 3) #test for RHEL Match rhic = RHIC.objects.filter(uuid=products_dict[RHEL][1])[0] p = Product.objects.filter(name=RHEL, sla=rhic.sla, support_level=rhic.support_level)[0] results_dicts = Product_Def.get_count(p, rhic, start, end, rhic.contract, environment, report_biz_rules) self.assertEqual(len(results_dicts), 1) #test for JBoss match rhic = RHIC.objects.filter(uuid=products_dict[JBoss][1])[0] p = Product.objects.filter(name=JBoss, sla=rhic.sla, support_level=rhic.support_level)[0] results_dicts = Product_Def.get_count(p, rhic, start, end, rhic.contract, environment, report_biz_rules) results_dicts = Product_Def.get_count(p, rhic, start, end, rhic.contract, environment, report_biz_rules) self.assertEqual(len(results_dicts), 2)
def test_RHEL_Host_negative(self): ReportData.drop_collection() entry_high = TestData.create_entry(UNLIMITED, socket=3) entry_high.save(safe=True) entry_low = TestData.create_entry(UNLIMITED, socket=3, mem_high=True ) entry_low.save(safe=True) self.check_product_result(1, 1)
def test_JBoss_vcpu_negative(self): ReportData.drop_collection() entry_high = TestData.create_entry(JBoss, socket=5) entry_high.save(safe=True) entry_low = TestData.create_entry(JBoss, socket=5, mem_high=True ) entry_low.save(safe=True) self.check_product_result(1, 1)
def test_OpenShift_Gear_negative(self): ReportData.drop_collection() entry_high = TestData.create_entry(GEAR, cpu=2, mem_high=True) entry_high.save(safe=True) entry_low = TestData.create_entry(GEAR, cpu=3, mem_high=True) entry_low.save(safe=True) self.check_product_result(1, 1)
def test_RHEL_memory_negative(self): ReportData.drop_collection() entry_high = TestData.create_entry(RHEL, mem_high=True) entry_high.save(safe=True) entry_low = TestData.create_entry(RHEL, mem_high=True, socket=12) entry_low.save(safe=True) self.check_product_result(1, 1)
def test_hours_per_consumer(self): ReportData.drop_collection() count = 0 for key, value in products_dict.items(): count += 1 entry = TestData.create_entry(key, mem_high=True) entry.save(safe=True) lookup = len(ReportData.objects.all()) self.assertEqual(lookup, count) end = datetime.now() delta=timedelta(days=1) start = datetime.now() - delta list_of_rhics = RHIC.objects.all() results = hours_per_consumer(start, end, list_of_rhics ) # right now products_dict RHEL and JBoss are sharing a RHIC so.. -1 on length self.assertEqual(len(results), (len(products_dict) -1 ), "correct number of results returned") results_product_list = [] for r in results: self.assertEqual(r[0]['nau'], '1', "number of checkins is accurate") results_product_list.append(r[0]['product_name']) intersect = set(results_product_list).intersection(products_dict.keys()) self.assertEqual(len(intersect), (len(products_dict) -1), "number of products returned in results is accurate")
def test_generic_config_RHEL(self): ReportData.drop_collection() entry_high = TestData.create_entry(RHEL, mem_high=True) entry_high.save(safe=True) delta=timedelta(days=1) start = datetime.now() - delta end = datetime.now() + delta contract_num = "3116649" environment = "us-east-1" lookup = ReportData.objects.all() self.assertEqual(len(lookup), 1) #test perfect match p = Product.objects.filter(name=RHEL)[0] #print(products_dict[RHEL][1]) rhic = RHIC.objects.filter(uuid=products_dict[RHEL][1])[0] results_dicts = Product_Def.get_count(p, rhic, start, end, contract_num, environment, report_biz_rules) self.assertEqual(len(results_dicts), 1)
def test_find_each_product(self): ReportData.drop_collection() count = 0 for key, value in products_dict.items(): count += 1 entry = TestData.create_entry(key, mem_high=True) entry.save(safe=True) lookup = len(ReportData.objects.all()) self.assertEqual(lookup, count) end = datetime.now() delta=timedelta(days=1) start = datetime.now() - delta for key, value in products_dict.items(): rhic = RHIC.objects.filter(uuid=value[1])[0] p = Product.objects.filter(name=key, sla=rhic.sla, support_level=rhic.support_level)[0] results_dicts = Product_Def.get_count(p, rhic, start, end, rhic.contract, "us-east-1", report_biz_rules) self.assertEqual(len(results_dicts), 1)
def test_rhel_data_range_results_60day(self): contract_num = "3116649" environment = "us-east-1" search_date_start = datetime.now() - timedelta(days=60) search_date_end = datetime.now() delta = timedelta(days=10) rhel = TestData.create_entry(RHEL, mem_high=True, date=(datetime.now() - delta)) rhel.save() lookup = ReportData.objects.all() self.assertEqual(len(lookup), 2) #test that there are now two objects in the database p = Product.objects.filter(name=RHEL)[0] rhic = RHIC.objects.filter(uuid=products_dict[RHEL][1])[0] results_dicts = Product_Def.get_count(p, rhic, search_date_start, search_date_end, contract_num, environment, report_biz_rules) #lenth of list should be one per product self.assertEqual(len(results_dicts), 1) #dictionary should contain the count of checkins self.assertEqual(results_dicts[0]['count'], 2)
def test_rhel_memory_results(self): contract_num = "3116649" environment = "us-east-1" end = datetime.now() delta=timedelta(days=1) start = datetime.now() - delta p = Product.objects.filter(name=RHEL)[0] rhic = RHIC.objects.filter(uuid=products_dict[RHEL][1])[0] results_dicts = Product_Def.get_count(p, rhic, start, end, contract_num, environment, report_biz_rules) self.assertTrue('> ' in results_dicts[0]['facts'], ' > 8GB found') rhel02 = TestData.create_entry(RHEL, mem_high=False) rhel02.save() end = datetime.now() #verify two items in db lookup = ReportData.objects.all() self.assertEqual(len(lookup), 2) #RHEL w/ > 8GB and < 8GB memory are considered two different products #The result dict should have two items in the list (2 products, 1 count each) results_dicts = Product_Def.get_count(p, rhic, start, end, contract_num, environment, report_biz_rules) self.assertEqual(len(results_dicts), 2)
def setUp(self): super(ReportTestCase, self).setUp() self.drop_collections() rhel_product = TestData.create_products() rhel_entry = TestData.create_entry(RHEL, mem_high=True) rhel_entry.save()