Skip to content

Commit

Permalink
Updated tests for schema/
Browse files Browse the repository at this point in the history
  • Loading branch information
lk-geimfari committed Sep 20, 2017
1 parent 4d7ec05 commit ce31ff5
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 42 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</p>
</a>

**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)
Expand All @@ -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:
Expand Down
25 changes: 12 additions & 13 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------

Expand Down Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions tests/data_fixtures/invalid_schema.json
Original file line number Diff line number Diff line change
@@ -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"
}
15 changes: 15 additions & 0 deletions tests/data_fixtures/schema.json
Original file line number Diff line number Diff line change
@@ -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"
}
95 changes: 68 additions & 27 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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()

0 comments on commit ce31ff5

Please sign in to comment.