class TestExplorationController(BaseTransactionalControllerTest):
    """
    Unit tests ParameterExplorationController
    """

    # def transactional_setup_method(self):
    #     """
    #     Sets up the environment for testing;
    #     creates a datatype group and a Parameter Exploration Controller
    #     """
    #     self.init()
    #     self.dt_group = DatatypesFactory().create_datatype_group()
    #     self.controller = ParameterExplorationController()

    def transactional_teardown_method(self):
        """ Cleans the testing environment """
        self.cleanup()

    def test_draw_discrete_exploration(self, datatype_group_factory,
                                       define_attributes):
        """
        Test that Discrete PSE is getting launched and correct fields are prepared.
        """
        self.dt_group = datatype_group_factory()
        self.controller = ParameterExplorationController()
        result = self.controller.draw_discrete_exploration(
            self.dt_group.gid, 'burst', None, None)
        assert result['available_metrics'] == list(
            define_attributes['DATATYPE_MEASURE_METRIC'])
        assert result['color_metric'] == list(
            define_attributes['DATATYPE_MEASURE_METRIC'])[0]
        assert result['size_metric'] is None
        assert define_attributes['RANGE_1'][1] == json.loads(
            result['labels_x'])
        assert define_attributes['RANGE_2'][1] == json.loads(
            result['labels_y'])
        data = json.loads(result['d3_data'])
        assert len(data) == len(define_attributes['RANGE_1'][1])
        for row in data.values():
            assert len(row) == len(define_attributes['RANGE_2'][1])
            for entry in row.values():
                assert entry['dataType'] == 'Datatype2'
                for key in ['Gid', 'color_weight', 'operationId', 'tooltip']:
                    assert key in entry

    def test_draw_isocline_exploration(self, datatype_group_factory,
                                       define_attributes):
        """
        Test that isocline PSE gets launched.
        """
        self.dt_group = datatype_group_factory()
        self.controller = ParameterExplorationController()
        result = self.controller.draw_isocline_exploration(self.dt_group.gid)
        assert isinstance(result['canvasName'], str)
        assert isinstance(result['xAxisName'], str)
        assert isinstance(result['url_base'], str)
        assert list(define_attributes['DATATYPE_MEASURE_METRIC']
                    ) == result['available_metrics']
class ExplorationControllerTest(BaseTransactionalControllerTest):
    """
    Unit tests ParameterExplorationController
    """
    def setUp(self):
        """
        Sets up the environment for testing;
        creates a datatype group and a Parameter Exploration Controller
        """
        self.init()
        self.dt_group = DatatypesFactory().create_datatype_group()
        self.controller = ParameterExplorationController()

    def tearDown(self):
        """ Cleans the testing environment """
        self.cleanup()

    def test_draw_discrete_exploration(self):
        """
        Test that Discrete PSE is getting launched and correct fields are prepared.
        """
        result = self.controller.draw_discrete_exploration(
            self.dt_group.gid, 'burst', None, None)
        self.assertTrue(result['available_metrics'] ==
                        DatatypesFactory.DATATYPE_MEASURE_METRIC.keys())
        self.assertEqual(result['color_metric'],
                         DatatypesFactory.DATATYPE_MEASURE_METRIC.keys()[0])
        self.assertEqual(result['size_metric'], None)
        self.assertEqual(DatatypesFactory.RANGE_1[1],
                         json.loads(result['labels_x']))
        self.assertEqual(DatatypesFactory.RANGE_2[1],
                         json.loads(result['labels_y']))
        data = json.loads(result['d3_data'])
        self.assertEqual(len(data), len(DatatypesFactory.RANGE_1[1]))
        for row in data.values():
            self.assertEqual(len(row), len(DatatypesFactory.RANGE_2[1]))
            for entry in row.values():
                self.assertEqual(entry['dataType'], 'Datatype2')
                for key in ['Gid', 'color_weight', 'operationId', 'tooltip']:
                    self.assertTrue(key in entry)

    def test_draw_isocline_exploration(self):
        """
        Test that isocline PSE gets launched.
        """
        result = self.controller.draw_isocline_exploration(
            self.dt_group.gid, 500, 600)
        self.assertTrue(DatatypesFactory.DATATYPE_MEASURE_METRIC.keys()[0] in
                        result['figureNumbers'])
        self.assertTrue(result['isAdapter'])
        self.assertEqual(DatatypesFactory.DATATYPE_MEASURE_METRIC,
                         result['metrics'])
        self.assertTrue(result['showFullToolbar'])
class ExplorationControllerTest(BaseTransactionalControllerTest):
    """
    Unit tests ParameterExplorationController
    """

    def setUp(self):
        """
        Sets up the environment for testing;
        creates a datatype group and a Parameter Exploration Controller
        """
        self.init()
        self.dt_group = DatatypesFactory().create_datatype_group()
        self.controller = ParameterExplorationController()


    def tearDown(self):
        """ Cleans the testing environment """
        self.cleanup()


    def test_draw_discrete_exploration(self):
        """
        Test that Discrete PSE is getting launched and correct fields are prepared.
        """
        result = self.controller.draw_discrete_exploration(self.dt_group.gid, 'burst', None, None)
        self.assertTrue(result['available_metrics'] == DatatypesFactory.DATATYPE_MEASURE_METRIC.keys())
        self.assertEqual(result['color_metric'], DatatypesFactory.DATATYPE_MEASURE_METRIC.keys()[0])
        self.assertEqual(result['size_metric'], None)
        self.assertEqual(DatatypesFactory.RANGE_1[1], json.loads(result['labels_x']))
        self.assertEqual(DatatypesFactory.RANGE_2[1], json.loads(result['labels_y']))
        data = json.loads(result['d3_data'])
        self.assertEqual(len(data), len(DatatypesFactory.RANGE_1[1]))
        for row in data.values():
            self.assertEqual(len(row), len(DatatypesFactory.RANGE_2[1]))
            for entry in row.values():
                self.assertEqual(entry['dataType'], 'Datatype2')
                for key in ['Gid', 'color_weight', 'operationId', 'tooltip']:
                    self.assertTrue(key in entry)


    def test_draw_isocline_exploration(self):
        """
        Test that isocline PSE gets launched.
        """
        result = self.controller.draw_isocline_exploration(self.dt_group.gid)
        self.assertTrue(isinstance(result['canvasName'], (str, unicode)))
        self.assertTrue(isinstance(result['xAxisName'], (str, unicode)))
        self.assertTrue(isinstance(result['url_base'], (str, unicode)))
        self.assertEqual(DatatypesFactory.DATATYPE_MEASURE_METRIC.keys(), result['available_metrics'])
Example #4
0
class TestExplorationController(BaseTransactionalControllerTest):
    """
    Unit tests ParameterExplorationController
    """
    def transactional_setup_method(self):
        self.clean_database()
        self.init()

    def transactional_teardown_method(self):
        """ Cleans the testing environment """
        self.cleanup()

    def test_draw_discrete_exploration(self, datatype_group_factory):
        """
        Test that Discrete PSE is getting launched and correct fields are prepared.
        """
        self.dt_group, _ = datatype_group_factory()
        self.controller = ParameterExplorationController()
        result = self.controller.draw_discrete_exploration(
            self.dt_group.gid, 'burst', 'v', 'v')
        assert result['available_metrics'] == ["v"]
        assert result['color_metric'] == "v"
        assert result['size_metric'] == "v"
        assert [1, 3, 5] == json.loads(result['labels_x'])
        assert [0.1, 0.4] == json.loads(result['labels_y'])
        data = json.loads(result['d3_data'])
        assert len(data) == 3
        for row in data.values():
            assert len(row) == 2
            for entry in row.values():
                assert entry['dataType'] == 'TimeSeriesIndex'
                for key in ['Gid', 'color_weight', 'operationId', 'tooltip']:
                    assert key in entry

    def test_draw_isocline_exploration(self, datatype_group_factory):
        """
        Test that isocline PSE gets launched.
        """
        self.dt_group, _ = datatype_group_factory()
        self.controller = ParameterExplorationController()
        result = self.controller.draw_isocline_exploration(self.dt_group.gid)
        assert isinstance(result['canvasName'], str)
        assert isinstance(result['xAxisName'], str)
        assert isinstance(result['url_base'], str)
        assert result['available_metrics'] == ['v']