Commits

Artur Barseghyan  committed 7cd8ab5 Draft

added tests

  • Participants
  • Parent commits a5111e0
  • Tags 0.7

Comments (0)

Files changed (11)

 You could, for example, use this app to solve the problems with displaying of a mixed content (assets loaded
 from HTTP and HTTPS sources).
 
+Prerequisites
+===================================
+- Django 1.5.+
+- Python 2.6.8+, 2.7.+, 3.3.+
+
 Installation
 =======================================
 1. Install eximagination
 
     $ pip install -e hg+http://bitbucket.org/barseghyanartur/eximagination@stable#egg=eximagination
 
+Latest stable version from github:
+
+    $ pip install -e git+https://github.com/barseghyanartur/eximagination/@stable#egg=eximagination
+
 2. Add 'eximagination' to `INSTALLED_APPS`
 
 >>> INSTALLED_APPS = (
 
 In both cases there are two additional context variables added:
 
-    `ei_width` - Width of the image
+    ``ei_width`` - Width of the image
 
-    `ei_height` - Height of the image
+    ``ei_height`` - Height of the image
 
 License
 =======================================

File docs/conf.py

 # built documents.
 #
 # The short X.Y version.
-version = '0.6'
+version = '0.7'
 # The full version, including alpha/beta/rc tags.
-release = '0.6'
+release = '0.7'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.

File example/example/settings.py

     'django.contrib.messages',
     'django.contrib.staticfiles',
 
-    'sorl.thumbnail', # thumbnail generator
-
     'eximagination',
 )
 

File example/example/templates/eximagination/test.html

 <h1>Tests</h1>
 <h2>Test 1</h2>
 <p>
-    <img src="{{ MEDIA_URL }}{% eximaginate 'http://www.google.com/intl/en/images/logo.gif' %}" alt="test 1 image" />
+    <img src="{{ MEDIA_URL }}{% eximaginate 'http://www.google.com/intl/en/images/logo.gif' %}" alt="test 1 image" id="image1"/>
 </p>
 
 <h2>Test 2</h2>
 <p>
     {% eximaginate 'http://www.google.com/intl/en/images/logo.gif' as original %}
-    <img src="{{ original }}" alt="test 2 image"/>
-    {#<img src="{% thumbnail original 100x100 %}" alt="test 2 image"/>#}
+    <img src="{{ MEDIA_URL }}{{ original }}" alt="test 2 image" id="image2"/>
+    {#<img src="{% thumbnail original 100x100 %}" alt="test 2 image" id="image2"/>#}
 </p>
 <p><small>Original image width: {{ ei_width }}</small></p>
 <p><small>Original image height: {{ ei_height }}</small></p>
-{% endblock content %}
+{% endblock content %}

File example/requirements.txt

 Django==1.5.4
-Pillow==2.1.0
-django-debug-toolbar==0.9.4
+Pillow==2.2.1
+selenium==2.35.0
+six==1.4.1
+tox==1.6.1
+
 #-e hg+http://bitbucket.org/barseghyanartur/eximagination@stable#egg=eximagination
         "Development Status :: 4 - Beta",
         "Environment :: Web Environment",
         "Intended Audience :: Developers",
-        'Operating System :: OS Independent',
+        "Operating System :: OS Independent",
     ],
     keywords = 'eximagination, django, external images, app, python',
     author = 'Artur Barseghyan',

File src/eximagination/__init__.py

+__title__ = 'eximagination.__init__'
+__version__ = '0.7'
+__build__ = 0x000007
+__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
+__all__ = ('obtain_image',)
+
+from eximagination.utils import obtain_image

File src/eximagination/models.py

Empty file added.

File src/eximagination/tests.py

 
 import unittest
 import os
+
 PROJECT_DIR = lambda base : os.path.join(os.path.dirname(__file__), base).replace('\\','/')
 
-from eximagination.utils import obtain_image
+from eximagination import obtain_image
 
 PRINT_INFO = True
 
 
 class EximaginationUtilsTest(unittest.TestCase):
     """
-    Tests of ``simple_timer.Timer`` class.
+    Tests of ``eximagination.utils.obtain_image`` function.
     """
     def setUp(self):
         self.image_url = 'http://www.google.com/intl/en/images/logo.gif'
 
         return res
 
+# Skipping from non-Django tests.
+if os.environ.get("DJANGO_SETTINGS_MODULE", None):
+    from django.test import LiveServerTestCase
+
+    from selenium.webdriver.firefox.webdriver import WebDriver
+
+    class EximaginationTemplatetagsTest(LiveServerTestCase): #unittest.TestCase
+        """
+        Tests of ``exinagination.templatetags.eximaginate`` module.
+        """
+        @classmethod
+        def setUpClass(cls):
+            cls.selenium = WebDriver()
+            super(EximaginationTemplatetagsTest, cls).setUpClass()
+
+        @classmethod
+        def tearDownClass(cls):
+            cls.selenium.quit()
+            super(EximaginationTemplatetagsTest, cls).tearDownClass()
+
+        @print_info
+        def test_templatetags(self):
+            """
+            Test template tags.
+            """
+            workflow = []
+
+            self.selenium.get(self.live_server_url)
+
+            img1 = self.selenium.find_element_by_id("image1")
+            self.assertTrue(img1.get_attribute('src').endswith('gif'))
+            workflow.append(img1.get_attribute('src'))
+
+            img2 = self.selenium.find_element_by_id("image2")
+            self.assertTrue(img2.get_attribute('src').endswith('gif'))
+            workflow.append(img2.get_attribute('src'))
+
+            return workflow
+
 
 if __name__ == "__main__":
     # Tests

File src/eximagination/utils.py

 import time
 from PIL import Image
 
-from six import PY2, PY3
 from six.moves.urllib.request import build_opener
-from six import StringIO
-#try:
-#    import StringIO
-#except ImportError as e:
-#    from cStringIO import StringIO
+from six import BytesIO as StringIO
 
 def obtain_image(image_source='', save_to='', media_url='', force_update=False, expiration_interval=None, debug=False):
     """
         # Loading into PIL image in order to check if image is a proper image as well as to detect its' extention.
         # This is probably the best way to validate the image and get its' extention, since PIL Image throws an
         # exception when trying to load not a proper image.
-        #try:
         im = Image.open(StringIO(external_image))
-        #except Exception as e:
-        #    import pdb; pdb.set_trace()
 
         # This is our filename
-        filename = hashlib.md5(image_source).hexdigest() + '.' + im.format.lower()
+        filename = hashlib.md5(image_source.encode('utf-8')).hexdigest() + '.' + im.format.lower()
 
         # If filename already exists - returning the filename
         filename_full_path = os.path.join(save_to, filename)
+# Core tests
 ./uninstall.sh
 reset
 ./install.sh
 reset
-python src/eximagination/tests.py
+python src/eximagination/tests.py
+
+# Django tests
+pip install -r example/requirements.txt
+python example/example/manage.py test eximagination