# Path: example/servers/models.py
# class Server(models.Model):
#     PRODUCTION = 'PROD'
#     DEVELOPMENT = 'DEV'
#     USE_CHOICES = ((PRODUCTION, 'Prod'),
#                    (DEVELOPMENT, 'Dev'))
#     name = models.CharField(max_length=20, unique=True)
#     notes = models.TextField()
#     virtual = models.BooleanField()
#     ip_address = models.GenericIPAddressField()
#     created = models.DateTimeField()
#     online_date = models.DateField()
#     operating_system = models.ForeignKey(OperatingSystem, related_name='servers', on_delete=models.CASCADE)
#     server_id = models.CharField(max_length=6)
#     use = models.CharField(max_length=4, choices=USE_CHOICES, default=DEVELOPMENT)
#     comments = models.TextField(null=True, blank=True)
# 
# Path: example/servers/tests/factories.py
# class ServerFactory(DjangoModelFactory):
#     class Meta:
#         model = Server
# 
#     name = LazyAttribute(lambda x: faker.text(max_nb_chars=20))
#     notes = LazyAttribute(lambda x: faker.paragraph(nb_sentences=3, variable_nb_sentences=True))
#     virtual = Iterator([True, False])
#     ip_address = LazyAttribute(lambda o: faker.ipv4(network=False))
#     created = LazyAttribute(lambda x: faker.date_time_between(start_date="-1y", end_date="now",
#                                                            tzinfo=timezone(settings.TIME_ZONE)))
#     online_date = LazyAttribute(lambda x: faker.date_time_between(start_date="-1y", end_date="now",
#                                                            tzinfo=timezone(settings.TIME_ZONE)))
#     operating_system = SubFactory(OperatingSystemFactory)
#     server_id = LazyAttribute(lambda x: FuzzyText(length=6, chars=string.digits).fuzz())
#     use = Iterator(Server.USE_CHOICES, getter=lambda x: x[0])
#     comments = LazyAttribute(lambda x: faker.paragraph(nb_sentences=3, variable_nb_sentences=True))
# 
# Path: example/servers/models.py
# class OperatingSystem(models.Model):
#     name = models.CharField(max_length=20)
#     version = models.CharField(max_length=5)
#     licenses_available = models.IntegerField()
#     cost = models.DecimalField(decimal_places=2, max_digits=7)
# 
#     class Meta:
#         unique_together = ('name', 'version')
# 
# Path: example/servers/tests/factories.py
# class OperatingSystemFactory(DjangoModelFactory):
#     class Meta:
#         model = OperatingSystem
# 
#     name = LazyAttribute(lambda x: faker.text(max_nb_chars=20))
#     version = LazyAttribute(lambda x: faker.text(max_nb_chars=5))
#     licenses_available = LazyAttribute(lambda o: randint(1, 100))
#     cost = LazyAttribute(lambda x: faker.pydecimal(left_digits=5, right_digits=2, positive=True))


from example.servers.models import Server
from ..factories import ServerFactory
from django.forms.models import model_to_dict
from django.test import TestCase
from django.conf import settings
from example.servers.models import OperatingSystem
from ..factories import OperatingSystemFactory
from django.db import IntegrityError

class TestCaseOperatingSystem(TestCase):

    def test_create(self):
        """
        Test the creation of a OperatingSystem model using a factory
        """
        operatingsystem = OperatingSystemFactory.create()
        self.assertEqual(1, OperatingSystem.objects.count())

    def test_create_batch(self):
        """
        Test the creation of 5 OperatingSystem models using a factory
        """
        operatingsystems = OperatingSystemFactory.create_batch(5)

# Path: example/servers/models.py
# class Server(models.Model):
#     PRODUCTION = 'PROD'
#     DEVELOPMENT = 'DEV'
#     USE_CHOICES = ((PRODUCTION, 'Prod'),
#                    (DEVELOPMENT, 'Dev'))
#     name = models.CharField(max_length=20, unique=True)
#     notes = models.TextField()
#     virtual = models.BooleanField()
#     ip_address = models.GenericIPAddressField()
#     created = models.DateTimeField()
#     online_date = models.DateField()
#     operating_system = models.ForeignKey(OperatingSystem, related_name='servers', on_delete=models.CASCADE)
#     server_id = models.CharField(max_length=6)
#     use = models.CharField(max_length=4, choices=USE_CHOICES, default=DEVELOPMENT)
#     comments = models.TextField(null=True, blank=True)
# 
# Path: example/servers/tests/factories.py
# class ServerFactory(DjangoModelFactory):
#     class Meta:
#         model = Server
# 
#     name = LazyAttribute(lambda x: faker.text(max_nb_chars=20))
#     notes = LazyAttribute(lambda x: faker.paragraph(nb_sentences=3, variable_nb_sentences=True))
#     virtual = Iterator([True, False])
#     ip_address = LazyAttribute(lambda o: faker.ipv4(network=False))
#     created = LazyAttribute(lambda x: faker.date_time_between(start_date="-1y", end_date="now",
#                                                            tzinfo=timezone(settings.TIME_ZONE)))
#     online_date = LazyAttribute(lambda x: faker.date_time_between(start_date="-1y", end_date="now",
#                                                            tzinfo=timezone(settings.TIME_ZONE)))
#     operating_system = SubFactory(OperatingSystemFactory)
#     server_id = LazyAttribute(lambda x: FuzzyText(length=6, chars=string.digits).fuzz())
#     use = Iterator(Server.USE_CHOICES, getter=lambda x: x[0])
#     comments = LazyAttribute(lambda x: faker.paragraph(nb_sentences=3, variable_nb_sentences=True))
# 
# Path: example/servers/models.py
# class OperatingSystem(models.Model):
#     name = models.CharField(max_length=20)
#     version = models.CharField(max_length=5)
#     licenses_available = models.IntegerField()
#     cost = models.DecimalField(decimal_places=2, max_digits=7)
# 
#     class Meta:
#         unique_together = ('name', 'version')
# 
# Path: example/servers/tests/factories.py
# class OperatingSystemFactory(DjangoModelFactory):
#     class Meta:
#         model = OperatingSystem
# 
#     name = LazyAttribute(lambda x: faker.text(max_nb_chars=20))
#     version = LazyAttribute(lambda x: faker.text(max_nb_chars=5))
#     licenses_available = LazyAttribute(lambda o: randint(1, 100))
#     cost = LazyAttribute(lambda x: faker.pydecimal(left_digits=5, right_digits=2, positive=True))


# Path: example/servers/tests/unit/test_models.py
from example.servers.models import Server
from ..factories import ServerFactory
from django.forms.models import model_to_dict
from django.test import TestCase
from django.conf import settings
from example.servers.models import OperatingSystem
from ..factories import OperatingSystemFactory
from django.db import IntegrityError


class TestCaseOperatingSystem(TestCase):

    def test_create(self):
        """
        Test the creation of a OperatingSystem model using a factory
        """
        operatingsystem = OperatingSystemFactory.create()
        self.assertEqual(1, OperatingSystem.objects.count())

    def test_create_batch(self):
        """
        Test the creation of 5 OperatingSystem models using a factory
        """
        operatingsystems = OperatingSystemFactory.create_batch(5)

        self.assertEqual(5, OperatingSystem.objects.count())