# Path: blitzdb/backends/file/index.py
# class NonUnique(BaseException):
#     """Index uniqueness constraint violated"""
#     pass
# 
# Path: tests/helpers/movie_data.py
# class Actor(Document):
# 
#     name = CharField(indexed = True)
#     gross_income_m = FloatField(indexed = True)
#     salary_amount = FloatField(indexed = True,key = 'salary.amount')
#     salary_currency = CharField(indexed = True,key = 'salary.currency')
#     appearances = IntegerField(indexed = True)
#     birth_year = IntegerField(indexed = True)
#     favorite_food = ManyToManyField('Food')
#     is_funny = BooleanField(indexed = True)
#     movies = ManyToManyField('Movie',backref = 'actors')


import pytest
from blitzdb.backends.file import NonUnique
from ..helpers.movie_data import Actor
from __future__ import absolute_import





def test_nonunique_file_backend_index(file_backend):
    file_backend.create_index(Actor, fields={'yob': 1})
    actor1 = Actor({'yob': 1})
    file_backend.save(actor1)
    actor2 = Actor({'yob': 1})
    file_backend.save(actor2)
    file_backend.commit()
    assert actor1.pk != actor2.pk


def test_unique_file_backend_index(file_backend):
    file_backend.create_index(Actor, fields={'num_films': 1}, unique=True)
    actor1 = Actor({'num_films': 1})
    file_backend.save(actor1)
    actor2 = Actor({'num_films': 1})
    file_backend.save(actor2)


# Path: blitzdb/backends/file/index.py
# class NonUnique(BaseException):
#     """Index uniqueness constraint violated"""
#     pass
# 
# Path: tests/helpers/movie_data.py
# class Actor(Document):
# 
#     name = CharField(indexed = True)
#     gross_income_m = FloatField(indexed = True)
#     salary_amount = FloatField(indexed = True,key = 'salary.amount')
#     salary_currency = CharField(indexed = True,key = 'salary.currency')
#     appearances = IntegerField(indexed = True)
#     birth_year = IntegerField(indexed = True)
#     favorite_food = ManyToManyField('Food')
#     is_funny = BooleanField(indexed = True)
#     movies = ManyToManyField('Movie',backref = 'actors')


# Path: tests/file/test_unique_index.py
import pytest
from blitzdb.backends.file import NonUnique
from ..helpers.movie_data import Actor

from __future__ import absolute_import





def test_nonunique_file_backend_index(file_backend):
    file_backend.create_index(Actor, fields={'yob': 1})
    actor1 = Actor({'yob': 1})
    file_backend.save(actor1)
    actor2 = Actor({'yob': 1})
    file_backend.save(actor2)
    file_backend.commit()
    assert actor1.pk != actor2.pk


def test_unique_file_backend_index(file_backend):
    file_backend.create_index(Actor, fields={'num_films': 1}, unique=True)
    actor1 = Actor({'num_films': 1})
    file_backend.save(actor1)
    actor2 = Actor({'num_films': 1})
    file_backend.save(actor2)


    with pytest.raises(NonUnique):