Exemple #1
0
    def test_import_override_dashboard_slice_reset_ownership(self):
        admin_user = security_manager.find_user(username="******")
        self.assertTrue(admin_user)
        gamma_user = security_manager.find_user(username="******")
        self.assertTrue(gamma_user)
        g.user = gamma_user

        dash_with_1_slice = self._create_dashboard_for_import(id_=10300)

        imported_dash_id = import_dashboard(dash_with_1_slice)
        imported_dash = self.get_dash(imported_dash_id)
        self.assertEqual(imported_dash.created_by, gamma_user)
        self.assertEqual(imported_dash.changed_by, gamma_user)
        self.assertEqual(imported_dash.owners, [gamma_user])

        imported_slc = imported_dash.slices[0]
        self.assertEqual(imported_slc.created_by, gamma_user)
        self.assertEqual(imported_slc.changed_by, gamma_user)
        self.assertEqual(imported_slc.owners, [gamma_user])

        # re-import with another user shouldn't change the permissions
        g.user = admin_user

        dash_with_1_slice = self._create_dashboard_for_import(id_=10300)

        imported_dash_id = import_dashboard(dash_with_1_slice)
        imported_dash = self.get_dash(imported_dash_id)
        self.assertEqual(imported_dash.created_by, gamma_user)
        self.assertEqual(imported_dash.changed_by, gamma_user)
        self.assertEqual(imported_dash.owners, [gamma_user])

        imported_slc = imported_dash.slices[0]
        self.assertEqual(imported_slc.created_by, gamma_user)
        self.assertEqual(imported_slc.changed_by, gamma_user)
        self.assertEqual(imported_slc.owners, [gamma_user])
Exemple #2
0
    def test_import_override_dashboard_2_slices(self):
        e_slc = self.create_slice("e_slc", id=10009, table_name="energy_usage")
        b_slc = self.create_slice("b_slc", id=10010, table_name="birth_names")
        dash_to_import = self.create_dashboard("override_dashboard",
                                               slcs=[e_slc, b_slc],
                                               id=10004)
        imported_dash_id_1 = import_dashboard(dash_to_import, import_time=1992)

        # create new instances of the slices
        e_slc = self.create_slice("e_slc", id=10009, table_name="energy_usage")
        b_slc = self.create_slice("b_slc", id=10010, table_name="birth_names")
        c_slc = self.create_slice("c_slc", id=10011, table_name="birth_names")
        dash_to_import_override = self.create_dashboard(
            "override_dashboard_new", slcs=[e_slc, b_slc, c_slc], id=10004)
        imported_dash_id_2 = import_dashboard(dash_to_import_override,
                                              import_time=1992)

        # override doesn't change the id
        self.assertEqual(imported_dash_id_1, imported_dash_id_2)
        expected_dash = self.create_dashboard("override_dashboard_new",
                                              slcs=[e_slc, b_slc, c_slc],
                                              id=10004)
        make_transient(expected_dash)
        imported_dash = self.get_dash(imported_dash_id_2)
        self.assert_dash_equals(expected_dash,
                                imported_dash,
                                check_position=False,
                                check_slugs=False)
        self.assertEqual(
            {
                "remote_id": 10004,
                "import_time": 1992
            },
            json.loads(imported_dash.json_metadata),
        )
Exemple #3
0
 def test_import_empty_dashboard(self):
     empty_dash = self.create_dashboard("empty_dashboard", id=10001)
     imported_dash_id = import_dashboard(empty_dash, import_time=1989)
     imported_dash = self.get_dash(imported_dash_id)
     self.assert_dash_equals(empty_dash,
                             imported_dash,
                             check_position=False)
Exemple #4
0
    def test_import_dashboard_2_slices(self):
        e_slc = self.create_slice("e_slc", id=10007, table_name="energy_usage")
        b_slc = self.create_slice("b_slc", id=10008, table_name="birth_names")
        dash_with_2_slices = self.create_dashboard("dash_with_2_slices",
                                                   slcs=[e_slc, b_slc],
                                                   id=10003)
        dash_with_2_slices.json_metadata = json.dumps({
            "remote_id": 10003,
            "expanded_slices": {
                "{}".format(e_slc.id): True,
                "{}".format(b_slc.id): False,
            },
            # mocked filter_scope metadata
            "filter_scopes": {
                str(e_slc.id): {
                    "region": {
                        "scope": ["ROOT_ID"],
                        "immune": [b_slc.id]
                    }
                }
            },
        })

        imported_dash_id = import_dashboard(dash_with_2_slices,
                                            import_time=1991)
        imported_dash = self.get_dash(imported_dash_id)

        expected_dash = self.create_dashboard("dash_with_2_slices",
                                              slcs=[e_slc, b_slc],
                                              id=10003)
        make_transient(expected_dash)
        self.assert_dash_equals(imported_dash,
                                expected_dash,
                                check_position=False,
                                check_slugs=False)
        i_e_slc = self.get_slice_by_name("e_slc")
        i_b_slc = self.get_slice_by_name("b_slc")
        expected_json_metadata = {
            "remote_id": 10003,
            "import_time": 1991,
            "filter_scopes": {
                str(i_e_slc.id): {
                    "region": {
                        "scope": ["ROOT_ID"],
                        "immune": [i_b_slc.id]
                    }
                }
            },
            "expanded_slices": {
                "{}".format(i_e_slc.id): True,
                "{}".format(i_b_slc.id): False,
            },
        }
        self.assertEqual(expected_json_metadata,
                         json.loads(imported_dash.json_metadata))
    def test_import_dashboard_1_slice(self):
        slc = self.create_slice("health_slc",
                                id=10006,
                                schema=get_example_default_schema())
        dash_with_1_slice = self.create_dashboard("dash_with_1_slice",
                                                  slcs=[slc],
                                                  id=10002)
        dash_with_1_slice.position_json = """
            {{"DASHBOARD_VERSION_KEY": "v2",
              "DASHBOARD_CHART_TYPE-{0}": {{
                "type": "CHART",
                "id": {0},
                "children": [],
                "meta": {{
                  "width": 4,
                  "height": 50,
                  "chartId": {0}
                }}
              }}
            }}
        """.format(slc.id)
        imported_dash_id = import_dashboard(dash_with_1_slice,
                                            import_time=1990)
        imported_dash = self.get_dash(imported_dash_id)

        expected_dash = self.create_dashboard("dash_with_1_slice",
                                              slcs=[slc],
                                              id=10002)
        make_transient(expected_dash)
        self.assert_dash_equals(expected_dash,
                                imported_dash,
                                check_position=False,
                                check_slugs=False)
        self.assertEqual(
            {
                "remote_id": 10002,
                "import_time": 1990
            },
            json.loads(imported_dash.json_metadata),
        )

        expected_position = dash_with_1_slice.position
        # new slice id (auto-incremental) assigned on insert
        # id from json is used only for updating position with new id
        meta = expected_position["DASHBOARD_CHART_TYPE-10006"]["meta"]
        meta["chartId"] = imported_dash.slices[0].id
        self.assertEqual(expected_position, imported_dash.position)
Exemple #6
0
    def test_import_new_dashboard_slice_reset_ownership(self):
        admin_user = security_manager.find_user(username="******")
        self.assertTrue(admin_user)
        gamma_user = security_manager.find_user(username="******")
        self.assertTrue(gamma_user)
        g.user = gamma_user

        dash_with_1_slice = self._create_dashboard_for_import(id_=10200)
        # set another user as an owner of importing dashboard
        dash_with_1_slice.created_by = admin_user
        dash_with_1_slice.changed_by = admin_user
        dash_with_1_slice.owners = [admin_user]

        imported_dash_id = import_dashboard(dash_with_1_slice)
        imported_dash = self.get_dash(imported_dash_id)
        self.assertEqual(imported_dash.created_by, gamma_user)
        self.assertEqual(imported_dash.changed_by, gamma_user)
        self.assertEqual(imported_dash.owners, [gamma_user])

        imported_slc = imported_dash.slices[0]
        self.assertEqual(imported_slc.created_by, gamma_user)
        self.assertEqual(imported_slc.changed_by, gamma_user)
        self.assertEqual(imported_slc.owners, [gamma_user])