From ce31ff54f489fc31acedfb46bb417cef168d837f Mon Sep 17 00:00:00 2001 From: Likid Geimfari Date: Wed, 20 Sep 2017 05:55:11 +0300 Subject: [PATCH] Updated tests for schema/ --- README.md | 4 +- docs/index.rst | 25 ++++--- tests/data_fixtures/invalid_schema.json | 11 +++ tests/data_fixtures/schema.json | 15 ++++ tests/test_schema.py | 95 ++++++++++++++++++------- 5 files changed, 108 insertions(+), 42 deletions(-) create mode 100644 tests/data_fixtures/invalid_schema.json create mode 100644 tests/data_fixtures/schema.json diff --git a/README.md b/README.md index b91d1c7a8..64a44e1c5 100755 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

-**Mimesis** is a fast and easy to use library for Python, which helps generate mock data for a variety of purposes (see "[Data providers](https://github.com/lk-geimfari/mimesis#data-providers)") in a variety of languages (see "[Locales](https://github.com/lk-geimfari/mimesis#locales)"). This data can be particularly useful during software development and testing. The library was written with the use of tools from the standard Python library, and therefore, it does not have any side dependencies. +**Mimesis** is a fast and easy to use library for Python programming language, which helps generate mock (dummy) data for a variety of purposes (see "[Data providers](#data-providers)") in a variety of languages (see "[Locales](#locales)"). This data can be particularly useful during software development and testing. The library was written with the use of tools from the standard Python library, and therefore, it does not have any side dependencies. [![Build Status](https://travis-ci.org/lk-geimfari/mimesis.svg?branch=master)](https://travis-ci.org/lk-geimfari/mimesis) [![Build status on Windows](https://ci.appveyor.com/api/projects/status/chj8huslvn6vde18?svg=true)](https://ci.appveyor.com/project/lk-geimfari/mimesis) @@ -24,7 +24,7 @@ See [here](https://gist.github.com/lk-geimfari/461ce92fd32379d7b73c9e12164a9154) performance with other libraries. ## Documentation -Mimesis is very simple to use, and the below examples should help you get started. Complete documentation for Mimesis is available [here](http://mimesis.readthedocs.io/). +Mimesis is very simple to use, and the below examples should help you get started. Complete documentation for Mimesis is available on [Read the Docs](http://mimesis.readthedocs.io/). ## Installation To install mimesis, simply: diff --git a/docs/index.rst b/docs/index.rst index 5587f1e88..c24270810 100755 --- a/docs/index.rst +++ b/docs/index.rst @@ -36,19 +36,6 @@ libraries. .. _faster: http://i.imgur.com/pCo6yPA.png -Best Practice -------------- -We strongly recommend to read articles which published below. There we are speak about -best practices and a number of most useful features of the library. - -.. toctree:: - :maxdepth: 3 - - part_1 - part_2 - - - Installation ------------ @@ -221,6 +208,18 @@ and Ukrainian: 'Veronika Denisova' +Best Practice +------------- +We strongly recommend to read articles which published below. There we are speak about +best practices and a number of most useful features of the library. + +.. toctree:: + :maxdepth: 3 + + part_1 + part_2 + + Related Libraries ----------------- - `mimesis-lab`_ - An extra open-source solutions using Mimesis library. diff --git a/tests/data_fixtures/invalid_schema.json b/tests/data_fixtures/invalid_schema.json new file mode 100644 index 000000000..819dc50fa --- /dev/null +++ b/tests/data_fixtures/invalid_schema.json @@ -0,0 +1,11 @@ +{ + "id": "cryptographic.uuid", + "name": "text.word", + "owner": { + "email": "personal.email", + "token": "cryptographic.token", + "creator": "personal.full_name" + }, + "site": , + "version": "development.version" +} diff --git a/tests/data_fixtures/schema.json b/tests/data_fixtures/schema.json new file mode 100644 index 000000000..bcc6021fd --- /dev/null +++ b/tests/data_fixtures/schema.json @@ -0,0 +1,15 @@ +{ + "id": "cryptographic.uuid", + "name": "text.word", + "owner": { + "email": "personal.email", + "token": "cryptographic.token", + "creator": "personal.full_name" + }, + "site": [ + { + "home_page": "internet.home_page" + } + ], + "version": "development.version" +} diff --git a/tests/test_schema.py b/tests/test_schema.py index 7b7e857fe..4b38b0bfc 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -1,25 +1,53 @@ +from os.path import ( + abspath, + dirname, + join, +) + import pytest +from mimesis import settings +from mimesis.exceptions import UndefinedSchema from mimesis.schema import Schema +PATH = abspath(join(dirname(__file__), 'data_fixtures')) + + +@pytest.fixture(params=settings.LIST_OF_LOCALES) +def schema(request): + return Schema(request.param) + @pytest.fixture -def schema(): - return Schema() - - -def test_valid_schema(schema): - valid_schema = { - 'id': 'cryptographic.uuid', - 'name': 'text.word', - 'version': 'development.version', - 'owner': { - 'email': 'personal.email', - 'token': 'cryptographic.token', - 'creator': 'personal.full_name', - }, - } +def valid_schema(): + return dict( + id='cryptographic.uuid', + name='text.word', + version='development.version', + owner=dict( + email='personal.email', + token='cryptographic.token', + creator='personal.full_name'), + sites=[{'home_page': 'internet.home_page'}], + ) + +@pytest.fixture +def invalid_schema(): + return dict( + id='none.none', + name='text.none', + version='development.none', + owner=dict( + email='personal.none', + token='cryptographic.none', + creator='personal.none', + ), + sites=[{'home_page': 'internet.home_page'}], + ) + + +def test_valid_schema(schema, valid_schema): result = schema.load(schema=valid_schema).create(iterations=1) assert isinstance(result, dict) # check type_to decorator @@ -29,17 +57,30 @@ def test_valid_schema(schema): assert len(result_2) == 10 -def test_invalid_schema(schema): - invalid_schema = { - 'id': 'none.none', - 'name': 'text.none', - 'version': 'development.none', - 'owner': { - 'email': 'personal.none', - 'token': 'cryptographic.none', - 'creator': 'personal.none', - }, - } - +def test_invalid_schema(schema, invalid_schema): with pytest.raises(AttributeError): schema.load(schema=invalid_schema).create() + + +def test_load_schema_by_path(schema): + valid_path = PATH + '/schema.json' + result = schema.load(path=valid_path) + assert isinstance(result.schema, dict) + + +def test_load_invalid_schema(schema): + invalid_json_file = PATH + '/invalid_schema.json' + with pytest.raises(ValueError): + schema.load(path=invalid_json_file) + + +def test_load_schema_by_invalid_path(schema): + invalid_path = PATH + '/schema.j' + + with pytest.raises(FileNotFoundError): + schema.load(path=invalid_path) + + +def test_undefined_schema(schema): + with pytest.raises(UndefinedSchema): + schema.create()