# Path: downloads/models.py
# class OS(ContentManageable, NameSlugModel):
#     """ OS for Python release """
# 
#     class Meta:
#         verbose_name = 'Operating System'
#         verbose_name_plural = 'Operating Systems'
#         ordering = ('name', )
# 
#     def __str__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         return reverse('download:download_os_list', kwargs={'os_slug': self.slug})
# 
# class Release(ContentManageable, NameSlugModel):
#     """
#     A particular version release.  Name field should be version number for
#     example: 3.3.4 or 2.7.6
#     """
#     PYTHON1 = 1
#     PYTHON2 = 2
#     PYTHON3 = 3
#     PYTHON_VERSION_CHOICES = (
#         (PYTHON3, 'Python 3.x.x'),
#         (PYTHON2, 'Python 2.x.x'),
#         (PYTHON1, 'Python 1.x.x'),
#     )
#     version = models.IntegerField(default=PYTHON3, choices=PYTHON_VERSION_CHOICES)
#     is_latest = models.BooleanField(
#         verbose_name='Is this the latest release?',
#         default=False,
#         db_index=True,
#         help_text="Set this if this should be considered the latest release "
#                   "for the major version. Previous 'latest' versions will "
#                   "automatically have this flag turned off.",
#     )
#     is_published = models.BooleanField(
#         verbose_name='Is Published?',
#         default=False,
#         db_index=True,
#         help_text="Whether or not this should be considered a released/published version",
#     )
#     pre_release = models.BooleanField(
#         verbose_name='Pre-release',
#         default=False,
#         db_index=True,
#         help_text="Boolean to denote pre-release/beta/RC versions",
#     )
#     show_on_download_page = models.BooleanField(
#         default=True,
#         db_index=True,
#         help_text="Whether or not to show this release on the main /downloads/ page",
#     )
#     release_date = models.DateTimeField(default=timezone.now)
#     release_page = models.ForeignKey(
#         Page,
#         related_name='release',
#         blank=True,
#         null=True,
#         on_delete=models.CASCADE,
#     )
#     release_notes_url = models.URLField('Release Notes URL', blank=True)
# 
#     content = MarkupField(default_markup_type=DEFAULT_MARKUP_TYPE, default='')
# 
#     objects = ReleaseManager()
# 
#     class Meta:
#         verbose_name = 'Release'
#         verbose_name_plural = 'Releases'
#         ordering = ('name', )
#         get_latest_by = 'release_date'
# 
#     def __str__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         if not self.content.raw and self.release_page:
#             return self.release_page.get_absolute_url()
#         else:
#             return reverse('download:download_release_detail', kwargs={'release_slug': self.slug})
# 
#     def download_file_for_os(self, os_slug):
#         """ Given an OS slug return the appropriate download file """
#         try:
#             file = self.files.get(os__slug=os_slug, download_button=True)
#         except ReleaseFile.DoesNotExist:
#             file = None
# 
#         return file
# 
#     def files_for_os(self, os_slug):
#         """ Return all files for this release for a given OS """
#         files = self.files.filter(os__slug=os_slug).order_by('-name')
#         return files
# 
#     def get_version(self):
#         version = re.match(r'Python\s([\d.]+)', self.name)
#         if version is not None:
#             return version.group(1)
#         return None
# 
#     def is_version_at_least(self, min_version_tuple):
#         v1 = []
#         for b in self.get_version().split('.'):
#             try:
#                 v1.append(int(b))
#             except ValueError:
#                 break
#         # If v1 (us) is shorter than v2 (the comparand), it will always fail.
#         # Add zeros for the comparison.
#         while len(min_version_tuple) > len(v1):
#             v1.append(0)
#         return tuple(v1) >= min_version_tuple
# 
#     @property
#     def is_version_at_least_3_5(self):
#         return self.is_version_at_least((3, 5))
# 
#     @property
#     def is_version_at_least_3_9(self):
#         return self.is_version_at_least((3, 9))
# 
# class ReleaseFile(ContentManageable, NameSlugModel):
#     """
#     Individual files in a release.  If a specific OS/release combo has multiple
#     versions for example Windows and MacOS 32 vs 64 bit each file needs to be
#     added separately
#     """
#     os = models.ForeignKey(
#         OS,
#         related_name='releases',
#         verbose_name='OS',
#         on_delete=models.CASCADE,
#     )
#     release = models.ForeignKey(Release, related_name='files', on_delete=models.CASCADE)
#     description = models.TextField(blank=True)
#     is_source = models.BooleanField('Is Source Distribution', default=False)
#     url = models.URLField('URL', unique=True, db_index=True, help_text="Download URL")
#     gpg_signature_file = models.URLField(
#         'GPG SIG URL',
#         blank=True,
#         help_text="GPG Signature URL"
#     )
#     md5_sum = models.CharField('MD5 Sum', max_length=200, blank=True)
#     filesize = models.IntegerField(default=0)
#     download_button = models.BooleanField(default=False, help_text="Use for the supernav download button for this OS")
# 
#     class Meta:
#         verbose_name = 'Release File'
#         verbose_name_plural = 'Release Files'
#         ordering = ('-release__is_published', 'release__name', 'os__name', 'name')


import datetime
from django.test import TestCase
from django.utils import timezone
from pages.models import Page
from ..models import OS, Release, ReleaseFile




class DownloadMixin:

    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.windows, _ = OS.objects.get_or_create(name='Windows')
        cls.osx, _ = OS.objects.get_or_create(name='macOS')

# Path: downloads/models.py
# class OS(ContentManageable, NameSlugModel):
#     """ OS for Python release """
# 
#     class Meta:
#         verbose_name = 'Operating System'
#         verbose_name_plural = 'Operating Systems'
#         ordering = ('name', )
# 
#     def __str__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         return reverse('download:download_os_list', kwargs={'os_slug': self.slug})
# 
# class Release(ContentManageable, NameSlugModel):
#     """
#     A particular version release.  Name field should be version number for
#     example: 3.3.4 or 2.7.6
#     """
#     PYTHON1 = 1
#     PYTHON2 = 2
#     PYTHON3 = 3
#     PYTHON_VERSION_CHOICES = (
#         (PYTHON3, 'Python 3.x.x'),
#         (PYTHON2, 'Python 2.x.x'),
#         (PYTHON1, 'Python 1.x.x'),
#     )
#     version = models.IntegerField(default=PYTHON3, choices=PYTHON_VERSION_CHOICES)
#     is_latest = models.BooleanField(
#         verbose_name='Is this the latest release?',
#         default=False,
#         db_index=True,
#         help_text="Set this if this should be considered the latest release "
#                   "for the major version. Previous 'latest' versions will "
#                   "automatically have this flag turned off.",
#     )
#     is_published = models.BooleanField(
#         verbose_name='Is Published?',
#         default=False,
#         db_index=True,
#         help_text="Whether or not this should be considered a released/published version",
#     )
#     pre_release = models.BooleanField(
#         verbose_name='Pre-release',
#         default=False,
#         db_index=True,
#         help_text="Boolean to denote pre-release/beta/RC versions",
#     )
#     show_on_download_page = models.BooleanField(
#         default=True,
#         db_index=True,
#         help_text="Whether or not to show this release on the main /downloads/ page",
#     )
#     release_date = models.DateTimeField(default=timezone.now)
#     release_page = models.ForeignKey(
#         Page,
#         related_name='release',
#         blank=True,
#         null=True,
#         on_delete=models.CASCADE,
#     )
#     release_notes_url = models.URLField('Release Notes URL', blank=True)
# 
#     content = MarkupField(default_markup_type=DEFAULT_MARKUP_TYPE, default='')
# 
#     objects = ReleaseManager()
# 
#     class Meta:
#         verbose_name = 'Release'
#         verbose_name_plural = 'Releases'
#         ordering = ('name', )
#         get_latest_by = 'release_date'
# 
#     def __str__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         if not self.content.raw and self.release_page:
#             return self.release_page.get_absolute_url()
#         else:
#             return reverse('download:download_release_detail', kwargs={'release_slug': self.slug})
# 
#     def download_file_for_os(self, os_slug):
#         """ Given an OS slug return the appropriate download file """
#         try:
#             file = self.files.get(os__slug=os_slug, download_button=True)
#         except ReleaseFile.DoesNotExist:
#             file = None
# 
#         return file
# 
#     def files_for_os(self, os_slug):
#         """ Return all files for this release for a given OS """
#         files = self.files.filter(os__slug=os_slug).order_by('-name')
#         return files
# 
#     def get_version(self):
#         version = re.match(r'Python\s([\d.]+)', self.name)
#         if version is not None:
#             return version.group(1)
#         return None
# 
#     def is_version_at_least(self, min_version_tuple):
#         v1 = []
#         for b in self.get_version().split('.'):
#             try:
#                 v1.append(int(b))
#             except ValueError:
#                 break
#         # If v1 (us) is shorter than v2 (the comparand), it will always fail.
#         # Add zeros for the comparison.
#         while len(min_version_tuple) > len(v1):
#             v1.append(0)
#         return tuple(v1) >= min_version_tuple
# 
#     @property
#     def is_version_at_least_3_5(self):
#         return self.is_version_at_least((3, 5))
# 
#     @property
#     def is_version_at_least_3_9(self):
#         return self.is_version_at_least((3, 9))
# 
# class ReleaseFile(ContentManageable, NameSlugModel):
#     """
#     Individual files in a release.  If a specific OS/release combo has multiple
#     versions for example Windows and MacOS 32 vs 64 bit each file needs to be
#     added separately
#     """
#     os = models.ForeignKey(
#         OS,
#         related_name='releases',
#         verbose_name='OS',
#         on_delete=models.CASCADE,
#     )
#     release = models.ForeignKey(Release, related_name='files', on_delete=models.CASCADE)
#     description = models.TextField(blank=True)
#     is_source = models.BooleanField('Is Source Distribution', default=False)
#     url = models.URLField('URL', unique=True, db_index=True, help_text="Download URL")
#     gpg_signature_file = models.URLField(
#         'GPG SIG URL',
#         blank=True,
#         help_text="GPG Signature URL"
#     )
#     md5_sum = models.CharField('MD5 Sum', max_length=200, blank=True)
#     filesize = models.IntegerField(default=0)
#     download_button = models.BooleanField(default=False, help_text="Use for the supernav download button for this OS")
# 
#     class Meta:
#         verbose_name = 'Release File'
#         verbose_name_plural = 'Release Files'
#         ordering = ('-release__is_published', 'release__name', 'os__name', 'name')


# Path: downloads/tests/base.py
import datetime
from django.test import TestCase
from django.utils import timezone
from pages.models import Page
from ..models import OS, Release, ReleaseFile





class DownloadMixin:

    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.windows, _ = OS.objects.get_or_create(name='Windows')
        cls.osx, _ = OS.objects.get_or_create(name='macOS')

        cls.linux, _ = OS.objects.get_or_create(name='Linux')