def _import_asset(asset, parent_collection=None, asset_type='survey'): survey_dict = _csv_to_dict(asset.body) obj = { 'name': asset.name, 'date_created': asset.date_created, 'date_modified': asset.date_modified, 'asset_type': asset_type, 'owner': user, } if parent_collection is not None: obj['parent'] = parent_collection del obj['name'] new_asset = Asset(**obj) _set_auto_field_update(Asset, "date_created", False) _set_auto_field_update(Asset, "date_modified", False) new_asset.content = survey_dict new_asset.date_created = obj['date_created'] new_asset.date_modified = obj['date_modified'] new_asset.save() _set_auto_field_update(Asset, "date_created", True) _set_auto_field_update(Asset, "date_modified", True) # Note on the old draft the uid of the new asset asset.kpi_asset_uid = new_asset.uid asset.save() return new_asset
def _create_cloned_asset(self): asset = Asset() asset.owner = self.asset.owner asset.content = self.asset.content asset.save() asset.deploy(backend='mock', active=True) asset.save() return asset
def test_export_uid_filter(self): assert self.user.username == 'someuser' def _create_export_task(asset): export_task = ExportTask() export_task.user = self.user export_task.data = { 'source': reverse('asset-detail', args=[asset.uid]), 'type': 'csv' } messages = defaultdict(list) export_task._run_task(messages) return export_task matching_export = _create_export_task(self.asset) # Create a clone and generate an export from it excluded_asset = Asset() excluded_asset.owner = self.asset.owner excluded_asset.content = self.asset.content excluded_asset.save() excluded_asset.deploy(backend='mock', active=True) excluded_asset.save() excluded_export = _create_export_task(excluded_asset) # Retrieve all the exports unfiltered self.client.login(username='******', password='******') list_url = reverse(self._get_endpoint('exporttask-list')) response = self.client.get(list_url) assert response.status_code == status.HTTP_200_OK assert response.json()['count'] == 2 # Retrieve the exports filtered by a single asset uid filter_url = f'{list_url}?q=source:{self.asset.uid}' response = self.client.get(filter_url) assert response.status_code == status.HTTP_200_OK response_dict = response.json() assert response_dict['count'] == 1 assert self.asset.uid in response_dict['results'][0]['data']['source']