Exemple #1
0
    def get(self, report_id):
        """Retrieve report by ID

        Args:
            report_id (str): Full report ID

        Returns:
            Report: Corresponding Report instance
        """
        return Report(
            self._app,
            self._swimlane.request('get',
                                   "reports/{0}".format(report_id)).json())
Exemple #2
0
    def list(self):
        """Retrieve all reports for parent app

        Returns:
            :class:`list` of :class:`~swimlane.core.resources.report.Report`: List of all returned reports
        """
        raw_reports = self._swimlane.request(
            'get', "reports?appId={}".format(self._app.id)).json()
        # Ignore StatsReports for now
        return [
            Report(self._app, raw_report) for raw_report in raw_reports
            if raw_report['$type'] == Report._type
        ]
Exemple #3
0
    def build(self, name):
        """Build a new Report for the App designated by app_id

        Args:
            name (str): New Report name

        Returns:
            Report: Newly created local Report instance
        """
        #pylint: disable=protected-access
        created = pendulum.now().to_rfc3339_string()
        user_model = self._swimlane.user.get_usergroup_selection()

        return Report(
            self._app, {
                "$type": Report._type,
                "groupBys": [],
                "aggregates": [],
                "applicationIds": [self._app.id],
                "columns": list(self._app._fields_by_id.keys()),
                "sorts": {
                    "$type":
                    "System.Collections.Generic.Dictionary`2"
                    "[[System.String, mscorlib],"
                    "[Core.Models.Search.SortTypes, Core]], mscorlib",
                },
                "filters": [],
                "pageSize": Report._page_size,
                "offset": 0,
                "defaultSearchReport": False,
                "allowed": [],
                "permissions": {
                    "$type": "Core.Models.Security.PermissionMatrix, Core"
                },
                "createdDate": created,
                "modifiedDate": created,
                "createdByUser": user_model,
                "modifiedByUser": user_model,
                "id": None,
                "name": name,
                "disabled": False,
                "keywords": ""
            })
 def test_find(self, mock_client):
     Report.find('123')
     mock_client.get.assert_called_once_with('reports/123')
 def test_find_all(self, mock_client):
     Report.find_all()
     mock_client.get.assert_called_with('reports/all')
     Report.find_all('123')
     mock_client.get.assert_called_with('reports/all?appId=123')
 def test_new_for(self):
     report = Report.new_for('123', '456', 'New Report')
     self.assertIsInstance(report, Report)
 def test_update(self, mock_client):
     report = Report(MOCK_REPORT)
     report.update()
     mock_client.put.assert_called_once_with(report, 'reports')
 def test_insert(self, mock_client):
     report = Report(MOCK_REPORT)
     report.insert()
     mock_client.post.assert_called_once_with(report, 'reports')
Exemple #9
0
 def test_find(self, mock_client):
     Report.find('123')
     mock_client.get.assert_called_once_with('reports/123')
Exemple #10
0
 def test_find_all(self, mock_client):
     Report.find_all()
     mock_client.get.assert_called_with('reports')
     Report.find_all('123')
     mock_client.get.assert_called_with('reports?appId=123')
Exemple #11
0
 def test_new_for(self, mock_user):
     mock_user.find.return_value = MOCK_USER
     report = Report.new_for('123', '456', 'New Report')
     self.assertIsInstance(report, Report)
Exemple #12
0
 def test_update(self, mock_client):
     report = Report(MOCK_REPORT)
     report.update()
     mock_client.put.assert_called_once_with(report, 'reports')
Exemple #13
0
 def test_insert(self, mock_client):
     report = Report(MOCK_REPORT)
     report.insert()
     mock_client.post.assert_called_once_with(report, 'reports')
Exemple #14
0
 def test_init(self):
     report = Report(MOCK_REPORT)
     for key, value in MOCK_REPORT.items():
         self.assertEqual(getattr(report, key), value)
Exemple #15
0
 def test_new_for(self):
     report = Report.new_for('123', '456', 'New Report')
     self.assertIsInstance(report, Report)