示例#1
0
    def test_calculate_display_size_correct_results_sanity(self):
        """
            test if the numerator is greater then denominator (if the subgroup is greater then containing group)
        """
        scene_tool_box = PngcnSceneKpis(self.ProjectConnector_mock,
                                        self.common_mock, 16588190,
                                        self.data_provider_mock)
        mock_df_products_size = self.mock_object('_get_display_size_of_product_in_scene',
                                                 path='Projects.PNGCN_PROD.SceneKpis.KPISceneToolBox.PngcnSceneKpis')

        # test that we write the correct results to DB
        data_scif = [{u'scene_id': 16588190, u'item_id': 123, u'manufacturer_fk': 4, u'rlv_sos_sc': 1, u'status': 1},
                     {u'scene_id': 16588190, u'item_id': 125,
                      u'manufacturer_fk': 3, u'rlv_sos_sc': 1, u'status': 1},
                     {u'scene_id': 16588190, u'item_id': 136, u'manufacturer_fk': 3, u'rlv_sos_sc': 1, u'status': 1}]
        scene_tool_box.scif = pd.DataFrame(data_scif)
        data_df_products_size = [{'item_id': 123, 'scene_id': 16588190, 'product_size': 1.245},
                                 {'item_id': 124, 'scene_id': 16588190, 'product_size': 0.285},
                                 {'item_id': 125, 'scene_id': 16588190, 'product_size': 1.225},
                                 {'item_id': 126, 'scene_id': 16588190, 'product_size': 0.232},
                                 {'item_id': 136, 'scene_id': 16588190, 'product_size': 0}]
        mock_df_products_size.return_value = pd.DataFrame(data_df_products_size)
        scene_tool_box.common.write_to_db_result = MagicMock()
        scene_tool_box.calculate_display_size()
        kpi_results = scene_tool_box.common.write_to_db_result.mock_calls[0][2]
        if kpi_results:
            numerator = kpi_results['numerator_result']
            denominator = kpi_results['denominator_result']
            # test if the numerator is greater then denominator (if the subgroup is greater then containing group)
            self.assertGreaterEqual(denominator, numerator,
                                    'the numerator cant be greater then denominator')
示例#2
0
 def test_calculate_display_size_correct_results_type(self):
     """
         test that the type of the numerator and denominator is float
     """
     scene_tool_box = PngcnSceneKpis(self.ProjectConnector_mock,
                                     self.common_mock, 16588190,
                                     self.data_provider_mock)
     mock_df_products_size = self.mock_object('_get_display_size_of_product_in_scene',
                                              path='Projects.PNGCN_PROD.SceneKpis.KPISceneToolBox.PngcnSceneKpis')
     # test that we don't return any thing when the used df is empty
     mock_df_products_size.return_value = pd.DataFrame(
         [{'item_id': 2, 'scene_id': 3, 'product_size': 0.25}])
     # test that we write the correct results to DB
     data_scif = [{u'scene_id': 16588190, u'item_id': 123, u'manufacturer_fk': 4, u'rlv_sos_sc': 1, u'status': 1},
                  {u'scene_id': 16588190, u'item_id': 125,
                   u'manufacturer_fk': 3, u'rlv_sos_sc': 1, u'status': 1},
                  {u'scene_id': 16588190, u'item_id': 136, u'manufacturer_fk': 3, u'rlv_sos_sc': 1, u'status': 1}]
     scene_tool_box.scif = pd.DataFrame(data_scif)
     data_df_products_size = [{'item_id': 123, 'scene_id': 16588190, 'product_size': 1.245},
                              {'item_id': 124, 'scene_id': 16588190, 'product_size': 0.285},
                              {'item_id': 125, 'scene_id': 16588190, 'product_size': 1.225},
                              {'item_id': 126, 'scene_id': 16588190, 'product_size': 0.232},
                              {'item_id': 136, 'scene_id': 16588190, 'product_size': 0}]
     mock_df_products_size.return_value = pd.DataFrame(data_df_products_size)
     scene_tool_box.common.write_to_db_result = MagicMock()
     scene_tool_box.calculate_display_size()
     kpi_results = scene_tool_box.common.write_to_db_result.mock_calls[0][2]
     if kpi_results:
         numerator = kpi_results['numerator_result']
         denominator = kpi_results['denominator_result']
         # test that the type of the numerator and denominator is float
         self.assertIsInstance(denominator, float)
         self.assertIsInstance(numerator, float)
示例#3
0
    def test_calculate_display_size_correct_results_length(self):
        """
            test result length
        """
        scene_tool_box = PngcnSceneKpis(self.ProjectConnector_mock,
                                        self.common_mock, 16588190,
                                        self.data_provider_mock)
        mock_df_products_size = self.mock_object('_get_display_size_of_product_in_scene',
                                                 path='Projects.PNGCN_PROD.SceneKpis.KPISceneToolBox.PngcnSceneKpis')

        # test that we don't return any thing when the used df is empty
        mock_df_products_size.return_value = pd.DataFrame(
            [{'item_id': 2, 'scene_id': 3, 'product_size': 0.25}])

        # test that we write the correct results to DB
        data_scif = [{u'scene_id': 16588190, u'item_id': 123, u'manufacturer_fk': 4, u'rlv_sos_sc': 1, u'status': 1},
                     {u'scene_id': 16588190, u'item_id': 125,
                      u'manufacturer_fk': 3, u'rlv_sos_sc': 1, u'status': 1},
                     {u'scene_id': 16588190, u'item_id': 136, u'manufacturer_fk': 3, u'rlv_sos_sc': 1, u'status': 1}]
        scene_tool_box.scif = pd.DataFrame(data_scif)
        data_df_products_size = [{'item_id': 123, 'scene_id': 16588190, 'product_size': 1.245},
                                 {'item_id': 124, 'scene_id': 16588190, 'product_size': 0.285},
                                 {'item_id': 125, 'scene_id': 16588190, 'product_size': 1.225},
                                 {'item_id': 126, 'scene_id': 16588190, 'product_size': 0.232},
                                 {'item_id': 136, 'scene_id': 16588190, 'product_size': 0}]
        mock_df_products_size.return_value = pd.DataFrame(data_df_products_size)
        scene_tool_box.common.write_to_db_result = MagicMock()
        # scene_tool_box.png_manufacturer_fk = 4
        scene_tool_box.calculate_display_size()
        kpi_results = scene_tool_box.common.write_to_db_result.mock_calls[0][2]
        if kpi_results:
            # test that we write 8 fields to DB
            self.assertEqual(len(kpi_results), 8, 'expects to write 8 parameters to db')
示例#4
0
 def test_calculate_display_size_empty_df(self):
     """
         test that we don't return any thing when the used df is empty
     """
     scene_tool_box = PngcnSceneKpis(self.ProjectConnector_mock,
                                     self.common_mock, 16588190,
                                     self.data_provider_mock)
     scene_tool_box.mock_df_products_size = \
         self.mock_object('_get_display_size_of_product_in_scene',
                          path='Projects.PNGCN_PROD.SceneKpis.KPISceneToolBox.PngcnSceneKpis')
     # test that we don't return any thing when the used df is empty
     scene_tool_box.mock_df_products_size.return_value = pd.DataFrame({})
     result = scene_tool_box.calculate_display_size()
     expected_result = None
     self.assertEqual(expected_result, result)