Exemple #1
0
    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 Server")[0]
        rhic = RHIC.objects.filter(
            uuid="8d401b5e-2fa5-4cb6-be64-5f57386fda86")[0]
        results_dicts = Product_Def.get_product_match(p, rhic, start, end,
                                                      contract_num,
                                                      environment)
        self.assertTrue('> ' in results_dicts[0]['facts'], ' > 8GB found')

        rhel02 = TestData.create_entry(RHEL, memhigh=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_product_match(p, rhic, start, end,
                                                      contract_num,
                                                      environment)
        self.assertEqual(len(results_dicts), 2)
Exemple #2
0
    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, memhigh=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():
            print(key)
            p = Product.objects.filter(name=key)[0]
            print(p.name)

            rhic = RHIC.objects.filter(uuid=value[1])[0]
            print(rhic.uuid)
            print(rhic.contract)
            results_dicts = Product_Def.get_product_match(
                p, rhic, start, end, rhic.contract, "us-east-1")
            self.assertEqual(len(results_dicts), 1)
Exemple #3
0
    def test_rhel_data_range_results(self):
        contract_num = "3116649"
        environment = "us-east-1"
        search_date_start = datetime.now() - timedelta(days=11)
        search_date_end = datetime.now()

        delta = timedelta(days=10)
        rhel = TestData.create_entry(RHEL,
                                     memhigh=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 Server")[0]
        rhic = RHIC.objects.filter(
            uuid="8d401b5e-2fa5-4cb6-be64-5f57386fda86")[0]
        results_dicts = Product_Def.get_product_match(p, rhic,
                                                      search_date_start,
                                                      search_date_end,
                                                      contract_num,
                                                      environment)
        #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)
Exemple #4
0
    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 Server")[0]
        rhic = RHIC.objects.filter(uuid="8d401b5e-2fa5-4cb6-be64-5f57386fda86")[0]
        results_dicts = Product_Def.get_product_match(p, rhic, start, end, contract_num, environment)
        self.assertTrue("> " in results_dicts[0]["facts"], " > 8GB found")

        rhel02 = TestData.create_entry(RHEL, memhigh=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_product_match(p, rhic, start, end, contract_num, environment)
        self.assertEqual(len(results_dicts), 2)
Exemple #5
0
    def test_rhel_basic_results(self):

        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 Server")[0]
        rhic = RHIC.objects.filter(uuid="8d401b5e-2fa5-4cb6-be64-5f57386fda86")[0]
        results_dicts = Product_Def.get_product_match(p, rhic, start, end, contract_num, environment)
        self.assertEqual(len(results_dicts), 1)

        # test result not found if name does not match
        test_object = Product.objects.filter(name="RHEL Server")[0]
        test_object.name = "fail"
        results_dicts = Product_Def.get_product_match(test_object, rhic, start, end, contract_num, environment)
        self.assertFalse(results_dicts, "no results returned")

        # test result not found where rhic uuid does not match
        test_object = RHIC.objects.filter(uuid="8d401b5e-2fa5-4cb6-be64-5f57386fda86")[0]
        test_object.uuid = "1234"
        results_dicts = Product_Def.get_product_match(p, test_object, start, end, contract_num, environment)
        self.assertFalse(results_dicts, "no results returned")

        # test no results are found if usage date is not in range
        test_object = datetime.now()
        results_dicts = Product_Def.get_product_match(p, rhic, test_object, end, contract_num, environment)
        self.assertFalse(results_dicts, "no results returned")

        test_object = start
        results_dicts = Product_Def.get_product_match(p, rhic, start, test_object, contract_num, environment)
        self.assertFalse(results_dicts, "no results returned")

        # test if contract number is not a match
        test_object = "1234"
        results_dicts = Product_Def.get_product_match(p, rhic, start, end, test_object, environment)
        self.assertFalse(results_dicts, "no results returned")

        # test if environment is not a match
        test_object = "env_hell"
        results_dicts = Product_Def.get_product_match(p, rhic, start, end, contract_num, test_object)
        self.assertFalse(results_dicts, "no results returned")
Exemple #6
0
    def test_rhel_data_range_results(self):
        contract_num = "3116649"
        environment = "us-east-1"
        search_date_start = datetime.now() - timedelta(days=11)
        search_date_end = datetime.now()

        delta = timedelta(days=10)
        rhel = TestData.create_entry(RHEL, memhigh=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 Server")[0]
        rhic = RHIC.objects.filter(uuid="8d401b5e-2fa5-4cb6-be64-5f57386fda86")[0]
        results_dicts = Product_Def.get_product_match(
            p, rhic, search_date_start, search_date_end, contract_num, environment
        )
        # 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)
Exemple #7
0
    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, memhigh=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():
            print(key)
            p = Product.objects.filter(name=key)[0]
            print(p.name)

            rhic = RHIC.objects.filter(uuid=value[1])[0]
            print(rhic.uuid)
            print(rhic.contract)
            results_dicts = Product_Def.get_product_match(p, rhic, start, end, rhic.contract, "us-east-1")
            self.assertEqual(len(results_dicts), 1)
Exemple #8
0
    def test_rhel_basic_results(self):

        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 Server")[0]
        rhic = RHIC.objects.filter(
            uuid="8d401b5e-2fa5-4cb6-be64-5f57386fda86")[0]
        results_dicts = Product_Def.get_product_match(p, rhic, start, end,
                                                      contract_num,
                                                      environment)
        self.assertEqual(len(results_dicts), 1)

        #test result not found if name does not match
        test_object = Product.objects.filter(name="RHEL Server")[0]
        test_object.name = "fail"
        results_dicts = Product_Def.get_product_match(test_object, rhic, start,
                                                      end, contract_num,
                                                      environment)
        self.assertFalse(results_dicts, 'no results returned')

        # test result not found where rhic uuid does not match
        test_object = RHIC.objects.filter(
            uuid="8d401b5e-2fa5-4cb6-be64-5f57386fda86")[0]
        test_object.uuid = "1234"
        results_dicts = Product_Def.get_product_match(p, test_object, start,
                                                      end, contract_num,
                                                      environment)
        self.assertFalse(results_dicts, 'no results returned')

        # test no results are found if usage date is not in range
        test_object = datetime.now()
        results_dicts = Product_Def.get_product_match(p, rhic, test_object,
                                                      end, contract_num,
                                                      environment)
        self.assertFalse(results_dicts, 'no results returned')

        test_object = start
        results_dicts = Product_Def.get_product_match(p, rhic, start,
                                                      test_object,
                                                      contract_num,
                                                      environment)
        self.assertFalse(results_dicts, 'no results returned')

        #test if contract number is not a match
        test_object = "1234"
        results_dicts = Product_Def.get_product_match(p, rhic, start, end,
                                                      test_object, environment)
        self.assertFalse(results_dicts, 'no results returned')

        #test if environment is not a match
        test_object = "env_hell"
        results_dicts = Product_Def.get_product_match(p, rhic, start, end,
                                                      contract_num,
                                                      test_object)
        self.assertFalse(results_dicts, 'no results returned')