This repository has been archived by the owner on Aug 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Bump version to 2.11 * Start refactoring SQLAlchemy usage for 1.4/2.0 Start refactoring the code in the datastore to follow SQLAlchemy 2.0 syntax. Something is up with equality checking, hence __repr__ in test Co-authored-by: Mattias Springare <[email protected]> * Add mypy config to gradually roll out types Add mypy config to gradually roll out types in the code base. The configured tox environment will not run unless explicitly specified (with tox -e types). The mypy config will ignore all files that have not been opted in, allowing a gradual roll out through the codebase. * Add types, update __repr__ and improve docs for data_store and models Add types for data_store and model, as part of an effort to gradually roll out types in the code base. Related to #56. Change import structure for sqlalchemy and only import the top level package, to make the code easier to read and understand where e.g., "Column" comes from. Improve the docstrings by attempting to have a first line summary and additional description in follow lines. Types were removed from the docstring as they are part of the function signature. The docstring is written in 120 character lines, given that the codebase is using them, but it would be easier to read in terminal usage if they were 80 char lines. Update the __repr__ method of models to print only the relevant files (and remove a bunch of unnecessary code). * Improve tests, especially around data store Re-define test utils as pytest fixtures for easier usage. Generalise pytest fixtures used for the data store and chain the fixtures so that the initialised data store-fixture depends on the data store-fixture etc. This will make it easier to do test-related changes in the objects. The fixtures can be improved further, there seems to be no clear consensus if the tests should create/load it's own data or if they should use the pre-populated fixtures. The current state is working, but the tests would be easier to read if they relied more on fixtures. Add docstrings to the data store tests, explaining what the tests do. Clean up some test code by removing duplicate tests, splitting some tests that do many things and remove unnecessary assert statements (e.g., first checking if the object is not None, then if it is a datetime instance. Only the datetime instance check is needed as it will then not be None). Co-authored-by: Mattias Springare <[email protected]>
- Loading branch information
1 parent
6a16187
commit 6610cd4
Showing
10 changed files
with
554 additions
and
486 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
# Install the package itself in dev mode | ||
-e . | ||
|
||
tox==3.24.1 | ||
|
||
# Formatters and linters | ||
black==21.7b0 | ||
pylint==2.9.6 | ||
isort==5.8.0 | ||
|
||
# Testing | ||
pytest==6.2.4 | ||
pytest-cov==2.12.0 | ||
pytest-freezegun==0.4.2 | ||
tox==3.24.1 | ||
pylint==2.9.6 | ||
isort==5.8.0 | ||
|
||
# Types | ||
mypy==0.910 | ||
sqlalchemy-stubs==0.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
|
||
setuptools.setup( | ||
name="comet-core", | ||
version="2.10.0", | ||
version="2.11.0", | ||
url="https://github.com/spotify/comet-core", | ||
author="Spotify Platform Security", | ||
author_email="[email protected]", | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,29 +13,75 @@ | |
# limitations under the License. | ||
|
||
"""Global test fixtures""" | ||
import os | ||
from datetime import datetime | ||
from typing import List | ||
|
||
import pytest | ||
|
||
from comet_core import Comet | ||
from comet_core.app import EventContainer | ||
from comet_core.data_store import DataStore | ||
from comet_core.model import EventRecord | ||
|
||
# pylint: disable=redefined-outer-name | ||
|
||
|
||
@pytest.fixture | ||
def app(): | ||
def app() -> Comet: | ||
"""Returns a Comet app.""" | ||
yield Comet() | ||
|
||
|
||
@pytest.fixture | ||
def test_db(): | ||
def messages() -> List[EventContainer]: | ||
"""Get all test messages and their filenames as an iterator. | ||
Returns: | ||
EventContainer: some test event | ||
""" | ||
event = EventContainer("test", {}) | ||
event.set_owner("[email protected]") | ||
event.set_fingerprint("test") | ||
return [event] | ||
|
||
|
||
@pytest.fixture | ||
def data_store() -> DataStore: | ||
"""Creates a SQLite backed datastore.""" | ||
return DataStore("sqlite://") | ||
|
||
|
||
@pytest.fixture | ||
def test_db(messages, data_store) -> DataStore: | ||
"""Setup a test database fixture | ||
Yields: | ||
DataStore: a sqlite backed datastore with all test data | ||
""" | ||
from comet_core.data_store import DataStore | ||
from tests.utils import get_all_test_messages | ||
|
||
data_store = DataStore("sqlite://") | ||
for event in get_all_test_messages(parsed=True): | ||
for event in messages: | ||
data_store.add_record(event.get_record()) | ||
|
||
yield data_store | ||
|
||
|
||
@pytest.fixture | ||
def data_store_with_test_events(data_store) -> DataStore: | ||
"""Creates a populated data store.""" | ||
one = EventRecord(received_at=datetime(2018, 7, 7, 9, 0, 0), source_type="datastoretest", owner="a", data={}) | ||
one.fingerprint = "f1" | ||
two = EventRecord(received_at=datetime(2018, 7, 7, 9, 30, 0), source_type="datastoretest", owner="a", data={}) | ||
two.fingerprint = "f2" | ||
three = EventRecord( | ||
received_at=datetime(2018, 7, 7, 9, 0, 0), | ||
source_type="datastoretest2", # Note that this is another source type! | ||
owner="b", | ||
data={}, | ||
) | ||
three.fingerprint = "f3" | ||
|
||
data_store.add_record(one) | ||
data_store.add_record(two) | ||
data_store.add_record(three) | ||
|
||
yield data_store |
Oops, something went wrong.