Skip to content

Commit

Permalink
Add kinto-changes, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-boris committed Nov 4, 2021
1 parent 554a8e3 commit c9fce25
Show file tree
Hide file tree
Showing 6 changed files with 635 additions and 228 deletions.
19 changes: 10 additions & 9 deletions kinto_http/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,16 @@ async def get_monitor_changes(self, bust_cache=False, **kwargs) -> List[Dict]:
kwargs["_expected"] = random_cache_bust
return await self.get_records(bucket="monitor", collection="changes", **kwargs)

@retry_timeout
async def get_changeset(self, bucket, collection, **kwargs) -> List[Dict]:
endpoint = f"/buckets/{bucket}/collections/{collection}/changeset"
kwargs.setdefault("_expected", random.randint(999999000000, 999999999999))
loop = asyncio.get_event_loop()
body, _ = await loop.run_in_executor(
None, lambda: self._client.session.request("get", endpoint, params=kwargs)
)
return body
# TODO: get proper tests written for this
# @retry_timeout
# async def get_changeset(self, bucket, collection, **kwargs) -> List[Dict]:
# endpoint = f"/buckets/{bucket}/collections/{collection}/changeset"
# kwargs.setdefault("_expected", random.randint(999999000000, 999999999999))
# loop = asyncio.get_event_loop()
# body, _ = await loop.run_in_executor(
# None, lambda: self._client.session.request("get", endpoint, params=kwargs)
# )
# return body

def __repr__(self):
if self._collection_name:
Expand Down
1 change: 1 addition & 0 deletions kinto_http/tests/config/kinto.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ kinto.paginate_by = 5

kinto.includes = kinto.plugins.flush
kinto.plugins.accounts
kinto_changes

multiauth.policies = account
multiauth.policy.account.use = kinto.plugins.accounts.AccountsPolicy
Expand Down
44 changes: 44 additions & 0 deletions kinto_http/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from typing import Tuple
from unittest.mock import MagicMock
from urllib.parse import urljoin

import pytest
import requests
from pytest_mock.plugin import MockerFixture

from kinto_http.aio import AsyncClient as Client

from .support import mock_response
from .test_functional_async import DEFAULT_AUTH, SERVER_URL, create_user


@pytest.fixture
def async_client_setup(mocker: MockerFixture) -> Tuple[Client, MagicMock]:
session = mocker.MagicMock()
mock_response(session)
client = Client(session=session, bucket="mybucket")
return client, session


@pytest.fixture
def record_setup(mocker: MockerFixture) -> Tuple[Client, MagicMock]:
session = mocker.MagicMock()
session.request.return_value = (mocker.sentinel.response, mocker.sentinel.count)
client = Client(session=session, bucket="mybucket", collection="mycollection")
return client, session


@pytest.fixture
def functional_setup():
# Setup
# Create user and return client
client = Client(server_url=SERVER_URL, auth=DEFAULT_AUTH)
create_user(SERVER_URL, DEFAULT_AUTH)

yield client

# Teardown
# Delete all the created objects
flush_url = urljoin(SERVER_URL, "/__flush__")
resp = requests.post(flush_url)
resp.raise_for_status()
Loading

0 comments on commit c9fce25

Please sign in to comment.