Skip to content

Commit

Permalink
[Integration] [fake integration] Added webhooks to fake integration (#…
Browse files Browse the repository at this point in the history
…1250)

# Description

What - added webhook route

Why - load tests for realtime 

How -

## Type of change

Please leave one option from the following and delete the rest:

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] New Integration (non-breaking change which adds a new integration)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Non-breaking change (fix of existing functionality that will not
change current behavior)
- [ ] Documentation (added/updated documentation)

<h4> All tests should be run against the port production
environment(using a testing org). </h4>

### Core testing checklist

- [ ] Integration able to create all default resources from scratch
- [ ] Resync finishes successfully
- [ ] Resync able to create entities
- [ ] Resync able to update entities
- [ ] Resync able to detect and delete entities
- [ ] Scheduled resync able to abort existing resync and start a new one
- [ ] Tested with at least 2 integrations from scratch
- [ ] Tested with Kafka and Polling event listeners
- [ ] Tested deletion of entities that don't pass the selector


### Integration testing checklist

- [ ] Integration able to create all default resources from scratch
- [ ] Resync able to create entities
- [ ] Resync able to update entities
- [ ] Resync able to detect and delete entities
- [ ] Resync finishes successfully
- [ ] If new resource kind is added or updated in the integration, add
example raw data, mapping and expected result to the `examples` folder
in the integration directory.
- [ ] If resource kind is updated, run the integration with the example
data and check if the expected result is achieved
- [ ] If new resource kind is added or updated, validate that
live-events for that resource are working as expected
- [ ] Docs PR link [here](#)

### Preflight checklist

- [ ] Handled rate limiting
- [ ] Handled pagination
- [ ] Implemented the code in async
- [ ] Support Multi account

## Screenshots

Include screenshots from your environment showing how the resources of
the integration will look.

## API Documentation

Provide links to the API documentation used for this integration.
  • Loading branch information
matan84 authored Dec 18, 2024
1 parent 7c20230 commit 195849a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
8 changes: 8 additions & 0 deletions integrations/fake-integration/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- towncrier release notes start -->

## 0.1.27-dev (2024-12-18)


### Improvements

- Added webhook route to the fake integration


## 0.1.26-dev (2024-12-15)


Expand Down
6 changes: 6 additions & 0 deletions integrations/fake-integration/fake_org_data/fake_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ async def get_fake_persons() -> AsyncGenerator[List[Dict[Any, Any]], None]:
yield current_result


async def get_random_person_from_batch() -> Dict[Any, Any]:
async for persons_batch in get_fake_persons():
return persons_batch[0]
return {}


async def get_departments() -> AsyncGenerator[List[Dict[Any, Any]], None]:
single_department_run = ocean.integration_config.get(
FakeIntegrationConfigKeys.SINGLE_PERF_RUN, False
Expand Down
17 changes: 16 additions & 1 deletion integrations/fake-integration/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from typing import Any

from fastapi import Request
from port_ocean.context.ocean import ocean
from loguru import logger

from fake_org_data.fake_client import get_fake_persons, get_departments
from fake_org_data.fake_client import (
get_fake_persons,
get_departments,
get_random_person_from_batch,
)
from port_ocean.core.ocean_types import ASYNC_GENERATOR_RESYNC_TYPE
from fake_org_data.fake_router import initialize_fake_routes

Expand All @@ -23,6 +30,14 @@ async def resync_persons(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE:
initialize_fake_routes()


@ocean.router.post("/webhook")
async def webhook_handler(request: Request) -> dict[str, Any]:
logger.info("Received a webhook!")
person = await get_random_person_from_batch()
await ocean.register_raw("fake-person", [person])
return {"ok": True}


@ocean.on_start()
async def on_start() -> None:
print("Starting fake integration!")
2 changes: 1 addition & 1 deletion integrations/fake-integration/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fake-integration"
version = "0.1.26-dev"
version = "0.1.27-dev"
description = "A useless fake integration that helps us test the Ocean Core"
authors = ["Erik Zaadi <[email protected]>"]

Expand Down

0 comments on commit 195849a

Please sign in to comment.