# Path: td_biblio/factories.py
# class FuzzyPages(BaseFuzzyAttribute):
#     """Random pages numbers separated by double-hyphens"""
# 
#     def __init__(self, low, high=None, **kwargs):
#         if high is None:
#             high = low
#             low = 1
# 
#         self.low = low
#         self.high = high
# 
#         super(FuzzyPages, self).__init__(**kwargs)
# 
#     def fuzz(self):
#         start = random.randint(self.low, self.high)
#         end = random.randint(start, self.high)
#         return "%d--%d" % (start, end)
# 
# class EntryFactory(DjangoModelFactory):
# 
#     type = factory.fuzzy.FuzzyChoice(ENTRY_TYPES_RAW_CHOICES)
#     title = factory.Sequence(lambda n: "Entry title %s" % n)
#     journal = factory.SubFactory(JournalFactory)
#     publication_date = factory.fuzzy.FuzzyDate(datetime.date(1942, 1, 1))
#     volume = factory.fuzzy.FuzzyInteger(1, 10)
#     number = factory.fuzzy.FuzzyInteger(1, 50)
#     pages = FuzzyPages(1, 2000)
# 
#     class Meta:
#         model = models.Entry


import pytest
from django.test import TestCase
from ..factories import FuzzyPages, EntryFactory
# -*- coding: utf-8 -*-
"""
TailorDev Bibliography

Test factories.
"""



@pytest.mark.django_db
class FuzzyPagesTestCase(TestCase):
    def test_simple_call(self):
        """Test the Fuzzy pages attribute implicit call"""

        entry = EntryFactory()
        self.assertNotEqual(len(entry.pages), 0)

    def test_only_max_page(self):
        """Test the Fuzzy pages attribute explicit call"""

        entry = EntryFactory(pages=FuzzyPages(1, 10))
        page_min, page_max = map(int, entry.pages.split("--"))
        self.assertNotEqual(len(entry.pages), 0)
        self.assertLessEqual(page_min, 10)
        self.assertGreaterEqual(page_min, 1)
        self.assertLessEqual(page_max, 10)
        self.assertGreaterEqual(page_max, 1)


# Path: td_biblio/factories.py
# class FuzzyPages(BaseFuzzyAttribute):
#     """Random pages numbers separated by double-hyphens"""
# 
#     def __init__(self, low, high=None, **kwargs):
#         if high is None:
#             high = low
#             low = 1
# 
#         self.low = low
#         self.high = high
# 
#         super(FuzzyPages, self).__init__(**kwargs)
# 
#     def fuzz(self):
#         start = random.randint(self.low, self.high)
#         end = random.randint(start, self.high)
#         return "%d--%d" % (start, end)
# 
# class EntryFactory(DjangoModelFactory):
# 
#     type = factory.fuzzy.FuzzyChoice(ENTRY_TYPES_RAW_CHOICES)
#     title = factory.Sequence(lambda n: "Entry title %s" % n)
#     journal = factory.SubFactory(JournalFactory)
#     publication_date = factory.fuzzy.FuzzyDate(datetime.date(1942, 1, 1))
#     volume = factory.fuzzy.FuzzyInteger(1, 10)
#     number = factory.fuzzy.FuzzyInteger(1, 50)
#     pages = FuzzyPages(1, 2000)
# 
#     class Meta:
#         model = models.Entry


# Path: td_biblio/tests/test_factories.py
import pytest
from django.test import TestCase
from ..factories import FuzzyPages, EntryFactory

# -*- coding: utf-8 -*-
"""
TailorDev Bibliography

Test factories.
"""



@pytest.mark.django_db
class FuzzyPagesTestCase(TestCase):
    def test_simple_call(self):
        """Test the Fuzzy pages attribute implicit call"""

        entry = EntryFactory()
        self.assertNotEqual(len(entry.pages), 0)

    def test_only_max_page(self):
        """Test the Fuzzy pages attribute explicit call"""

        entry = EntryFactory(pages=FuzzyPages(1, 10))
        page_min, page_max = map(int, entry.pages.split("--"))
        self.assertNotEqual(len(entry.pages), 0)
        self.assertLessEqual(page_min, 10)
        self.assertGreaterEqual(page_min, 1)
        self.assertLessEqual(page_max, 10)
        self.assertGreaterEqual(page_max, 1)


        entry = EntryFactory(pages=FuzzyPages(10))