# Path: libre/apps/origins/models.py
# class OriginPath(Origin, ContainerOrigin):
#     origin_type = _('disk path')
# 
#     path = models.TextField(blank=True, null=True, verbose_name=_('path to file'), help_text=_('Location to a file in the filesystem.'))
# 
#     def get_binary_iterator(self):
#         """
#         Generator to read a file piece by piece.
#         """
#         CHUNK_SIZE = 1024
#         file_object = open(self.path)
# 
#         while True:
#             data = file_object.read(CHUNK_SIZE)
#             if not data:
#                 break
#             yield data
# 
#         file_object.close()
# 
#     @property
#     def identifier(self):
#         return self.path
# 
#     class Meta:
#         verbose_name = _('disk path origin')
#         verbose_name_plural = _('disk path origins')
# 
# class OriginURLFile(OriginURL, ContainerOrigin):
#     origin_type = _('URL file')
# 
#     class Meta:
#         verbose_name = _('URL file origin')
#         verbose_name_plural = _('URL file origins')


import os
from django.conf import settings
from django.test import TestCase
from .models import OriginPath, OriginURLFile
from __future__ import absolute_import




TEST_FIXED_WIDTH_FILE = 'prmunnet.txt'


def temp_path_status(path):
    if not os.path.exists(path):
        return 'File does not exist'
    if not os.path.isfile(path):
        return 'Not a file'
    if not os.access(path, os.R_OK):
        return 'File is not readable'
    return 'File exists'


class URLFileTestCase(TestCase):
    def setUp(self):

# Path: libre/apps/origins/models.py
# class OriginPath(Origin, ContainerOrigin):
#     origin_type = _('disk path')
# 
#     path = models.TextField(blank=True, null=True, verbose_name=_('path to file'), help_text=_('Location to a file in the filesystem.'))
# 
#     def get_binary_iterator(self):
#         """
#         Generator to read a file piece by piece.
#         """
#         CHUNK_SIZE = 1024
#         file_object = open(self.path)
# 
#         while True:
#             data = file_object.read(CHUNK_SIZE)
#             if not data:
#                 break
#             yield data
# 
#         file_object.close()
# 
#     @property
#     def identifier(self):
#         return self.path
# 
#     class Meta:
#         verbose_name = _('disk path origin')
#         verbose_name_plural = _('disk path origins')
# 
# class OriginURLFile(OriginURL, ContainerOrigin):
#     origin_type = _('URL file')
# 
#     class Meta:
#         verbose_name = _('URL file origin')
#         verbose_name_plural = _('URL file origins')


# Path: libre/apps/origins/tests.py
import os
from django.conf import settings
from django.test import TestCase
from .models import OriginPath, OriginURLFile

from __future__ import absolute_import




TEST_FIXED_WIDTH_FILE = 'prmunnet.txt'


def temp_path_status(path):
    if not os.path.exists(path):
        return 'File does not exist'
    if not os.path.isfile(path):
        return 'Not a file'
    if not os.access(path, os.R_OK):
        return 'File is not readable'
    return 'File exists'


class URLFileTestCase(TestCase):
    def setUp(self):

        self.origin_url = OriginURLFile.objects.create(label='test origin', url='http://www.census.gov/population/estimates/puerto-rico/prmunnet.txt')