(self)
| 219 | assert res.json["results"][0]["id"] == mapping_id |
| 220 | |
| 221 | def test_mappings_trigger(self): |
| 222 | table = self.create_table_entity(self.col, entity_id="foo") |
| 223 | mapping = self.create_mapping(self.col, table=table, role=self.role) |
| 224 | |
| 225 | # There are no entities before running the mapping |
| 226 | entities_url = "/api/2/entities" |
| 227 | entities_query_string = { |
| 228 | "filter:collection_id": self.col.id, |
| 229 | "filter:schemata": "Person", |
| 230 | } |
| 231 | |
| 232 | res = self.client.get( |
| 233 | entities_url, |
| 234 | query_string=entities_query_string, |
| 235 | headers=self.headers, |
| 236 | ) |
| 237 | assert res.json["total"] == 0 |
| 238 | |
| 239 | # Mapping and collection IDs have to match |
| 240 | trigger_url = ( |
| 241 | f"/api/2/collections/{self.col_other.id}/mappings/{mapping.id}/trigger" |
| 242 | ) |
| 243 | res = self.client.post(trigger_url, headers=self.headers_other) |
| 244 | assert res.status_code == 404 |
| 245 | |
| 246 | # Trigger the mapping to generate entities |
| 247 | trigger_url = f"/api/2/collections/{self.col.id}/mappings/{mapping.id}/trigger" |
| 248 | |
| 249 | # Only users with access to the collection can trigger mappings |
| 250 | res = self.client.post(trigger_url, headers=self.headers_other) |
| 251 | assert res.status_code == 403 |
| 252 | |
| 253 | # Read access is not enough to trigger a mapping |
| 254 | res = self.client.post(trigger_url, headers=self.headers_read) |
| 255 | assert res.status_code == 403 |
| 256 | |
| 257 | res = self.client.post(trigger_url, headers=self.headers) |
| 258 | assert res.status_code == 202 |
| 259 | |
| 260 | view_url = f"/api/2/collections/{self.col.id}/mappings/{mapping.id}" |
| 261 | res = self.client.get(view_url, headers=self.headers) |
| 262 | assert res.json["last_run_status"] == "successful" |
| 263 | assert "last_run_err_msg" not in res.json |
| 264 | |
| 265 | # 14 entities have been generated after triggering the mapping |
| 266 | res = self.client.get( |
| 267 | entities_url, |
| 268 | query_string=entities_query_string, |
| 269 | headers=self.headers, |
| 270 | ) |
| 271 | assert len(res.json["results"]) == 14 |
| 272 | assert res.json["results"][0]["schema"] == "Person" |
| 273 | assert res.json["results"][0]["properties"]["proof"][0]["id"] == table.id |
| 274 | |
| 275 | def test_mappings_flush(self): |
| 276 | table = self.create_table_entity(collection=self.col, entity_id="foo") |
nothing calls this directly
no test coverage detected