Commit 692090af authored by Yury's avatar Yury

tests: move to pytest, increase coverage

parent 806f70e4
Pipeline #330 passed with stages
in 5 minutes and 1 second
......@@ -5,4 +5,5 @@ __pycache__
.idea
.coverage
/.tox/
*.egg-info
\ No newline at end of file
*.egg-info
/htmlcov/
stages:
- unittests
- systemtest
- pypi_build
python3.6:
stage: unittests
tags:
- docker
image: python:3.6
script:
- pip3 install -r requirements.txt coverage
- coverage run --source mdocument -m unittest discover -s tests -p "*_test.py"
python3.7:
stage: unittests
tags:
- docker
image: python:3.7
script:
- pip3 install -r requirements.txt coverage
- coverage run --source mdocument -m unittest discover -s tests -p "*_test.py"
python3.8:
stage: unittests
tags:
- docker
image: python:3.8
script:
- pip3 install -r requirements.txt coverage
- coverage run --source mdocument -m unittest discover -s tests -p "*_test.py"
python.latest:
stage: unittests
tags:
- docker
image: python:latest
script:
- pip3 install -r requirements.txt coverage
- coverage run --source mdocument -m unittest discover -s tests -p "*_test.py"
- coverage report -m
mongo-latest:
stage: systemtest
tags:
......@@ -54,9 +16,10 @@ mongo-latest:
- apt install -y mongodb-org
- mkdir -p /data/db
- screen -dmS mongoService mongod
- pip install pytest pytest-asyncio pytest-cov
script:
- python3 -m pip install -r requirements.txt
- python3 -m unittest discover -s tests -p "*_systest.py"
- python -m pip install -r requirements.txt
- pytest --cov-report term --cov=mdocument tests --disable-pytest-warnings
build:
stage: pypi_build
......
from .document import Document, DocumentException, \
DocumentDoesntExist, MetaDocument, ClientNotFound
from .connection import DatabaseClient
import urllib.parse
from motor.motor_asyncio import AsyncIOMotorClient
class DatabaseClient:
def __init__(self, uri: str = None, replica_set: list = None, host: str = None,
username: str = None, password: str = None, auth_database: str = "admin"):
if uri:
self.client = AsyncIOMotorClient(uri)
else:
if replica_set:
host = ",".join(replica_set)
if not username or not password:
uri = f"mongodb://{host}"
else:
username = urllib.parse.quote_plus(username)
password = urllib.parse.quote_plus(password)
uri = f"mongodb://{username}:{password}@{host}/{auth_database}"
self.client = AsyncIOMotorClient(uri)
async def create(self, document):
await self.client[document._database_][document._collection_].insert_one(
document.__dict__
)
document._shadow_copy_ = document.__dict__.copy()
async def update(self, document):
await self.client[document._database_][document._collection_].update_one(
document._shadow_copy_,
{"$set": document.__dict__}
)
async def delete(self, document):
await self.client[document._database_][document._collection_].delete_one(
document._shadow_copy_
)
\ No newline at end of file
......@@ -262,17 +262,6 @@ class Document(metaclass=MetaDocument):
await cls.collection.insert_one(kwargs)
return cls(**kwargs)
async def _delete_by_prop(self, relations):
for prop, delete_info in relations.items():
property_name = prop.fget.__name__
try:
for doc in await getattr(self, property_name):
await doc.delete()
except DocumentDoesntExist:
continue
async def _delete_related(self):
"""Deletes related documents or pops field values."""
......
import pytest
from mdocument.document_array import DocumentArray
def test___getitem__():
array1 = DocumentArray([1, 2, {"test": "yes"}])
assert array1[0] == 1
assert array1[1] == 2
assert array1[2] == {"test": "yes"}
with pytest.raises(IndexError):
assert array1[3] == 5
This diff is collapsed.
......@@ -2,16 +2,16 @@
envlist = unittest, pylint, coverage
[testenv]
deps = -rrequirements.txt
deps = pytest-asyncio
[testenv:unittest]
commands = python3 -m unittest discover -s tests -p "*_test.py"
commands = pytest tests --disable-pytest-warnings
[testenv:pylint]
deps = pylint
commands = pylint mdocument
[testenv:coverage]
deps = coverage
commands = coverage run --source mdocument -m unittest discover -s tests -p "*_test.py"
coverage report -m
\ No newline at end of file
deps = pytest-asyncio
pytest-cov
commands = pytest --cov-report term --cov=mdocument tests --disable-pytest-warnings
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment