Skip to content

Commit

Permalink
Fix tests for Django 1.4 (#1)
Browse files Browse the repository at this point in the history
Fix tests for Django 1.4
  • Loading branch information
gvangool authored Aug 31, 2019
2 parents 72050f8 + f3d8adc commit 2fe44a3
Show file tree
Hide file tree
Showing 16 changed files with 314 additions and 15 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI

on: [push]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python: [ '2.7' ]
name: Python ${{ matrix.python }} tests
steps:
- uses: actions/checkout@master
- name: Setup python
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python }}
architecture: x64
- name: Running tox
run: |
python -m pip install tox
tox -e $(tox -ls | grep py$(echo ${{ matrix.python }} | sed 's/\.//') | sed ':1;N;s/\n/,/;t1')
21 changes: 21 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
stages:
- build
- test

before_script:
- pip install tox

build:
image: python:2.7
stage: build
script:
- python setup.py sdist bdist_wheel --universal
- echo "What's in the package?"
- tar -tvf dist/django-flickr-*tar.gz
- unzip -l dist/django_flickr-*whl

test-py27:
image: python:2.7
stage: test
script:
- tox -e $(tox -ls | grep py27 | sed -e 'N;s/\n/,/')
Empty file added example/__init__.py
Empty file.
118 changes: 118 additions & 0 deletions example/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Django settings for example project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', '[email protected]'),
)

MANAGERS = ADMINS

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': ':memory:', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}

# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.4/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = '3$q5+il@s_@%7@rc*brr^&v^rc*0c_f+gecwq+la+a9n-c$l!5'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'example.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'example.wsgi.application'

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'flickr',
'taggit',
'taggit_templatetags',
)

17 changes: 17 additions & 0 deletions example/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'example.views.home', name='home'),
# url(r'^example/', include('example.foo.urls')),

# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
)
28 changes: 28 additions & 0 deletions example/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
WSGI config for example project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.
Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.
"""
import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
4 changes: 2 additions & 2 deletions flickr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION = (0, 3, 5)
DEV_STATUS = '3 - Alpha'
VERSION = (0, 3, 6)
DEV_STATUS = '4 - Beta'
6 changes: 3 additions & 3 deletions flickr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _prepare_data(self, photo, flickr_user, info=None, exif=None, geo=None, **kw
'title': info_bunch.title._content,
'description': info_bunch.description._content,
'date_posted': ts_to_dt(info_bunch.dates.posted, flickr_user.tzoffset),
'date_taken': '%s%s' % (info_bunch.dates.taken, flickr_user.tzoffset),
'date_taken': '%s%s' % (info_bunch.dates.taken, flickr_user.tzoffset or ""),
'date_taken_granularity': info_bunch.dates.takengranularity,
'date_updated': ts_to_dt(info_bunch.dates.lastupdate, flickr_user.tzoffset),
'tags': info_bunch.tags.tag,
Expand Down Expand Up @@ -177,7 +177,7 @@ def _prepare_data(self, photo, flickr_user, info=None, exif=None, geo=None, **kw
'license': photo_bunch.license,
}
if photo_info['date_taken']:
photo_info['date_taken'] = '%s%s' % (photo_info['date_taken'], flickr_user.tzoffset)
photo_info['date_taken'] = '%s%s' % (photo_info['date_taken'], flickr_user.tzoffset or "")

photo_data.update(photo_info)

Expand Down Expand Up @@ -692,7 +692,7 @@ def _prepare_data(self, info, flickr_user, parent=None):
return data

def create_obj(self, info, parent=None, flickr_user=None, **kwargs):
data = self._prepare_data(info, parent, flickr_user)
data = self._prepare_data(info, parent=parent, flickr_user=flickr_user)
sets_data = cols_data = None
if 'sets' in data.keys():
sets_data = data.pop('sets')
Expand Down
2 changes: 1 addition & 1 deletion flickr/templatetags/flickr_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def flickr_photo(photo, size='medium', flickr_link=False):
if not photo:
return {}
if size == 'large' and photo.date_posted <= datetime.datetime(2010, 05, 25):
if size == 'large' and photo.date_posted.date() <= datetime.date(2010, 05, 25):
if photo.user.ispro:
size = 'ori'
else:
Expand Down
53 changes: 50 additions & 3 deletions flickr/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
from bunch import bunchify
from datetime import datetime
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.template.base import TemplateDoesNotExist
from django.test import TestCase
from django.test.client import Client
from django.test.utils import override_settings
from flickr.flickr_spec import FLICKR_PHOTO_SIZES
from flickr.models import FlickrUser, Photo, PhotoSet, Collection
from flickr.tests_data import json_user, json_sizes, json_exif, json_geo, json_info, \
Expand Down Expand Up @@ -38,6 +41,7 @@ def test_user(self):
self.assertEqual(fu.iconfarm, json_user['person']['iconfarm'])
self.assertEqual(fu.path_alias, json_user['person']['path_alias'])
self.assertEqual(fu.profileurl, json_user['person']['profileurl']['_content'].replace('\\/', '/'))
self.assertEqual(fu.tzoffset, json_user['person']['timezone']['offset'])

def test_photo_create(self):
json_info = json_photos_extras['photos']['photo'][0]
Expand Down Expand Up @@ -73,7 +77,7 @@ def test_photo_update(self):
new_title = 'whoa that is a new title here'
json_info['title'] = new_title
self.assertNotEqual(photo.title, json_info['title'])
Photo.objects.update_from_json(flickr_id=photo.flickr_id, photo=json_info, sizes=json_sizes, exif=json_exif)
Photo.objects.update_from_json(self.flickr_user, flickr_id=photo.flickr_id, photo=json_info, sizes=json_sizes, exif=json_exif)
obj = Photo.objects.get(flickr_id=photo.flickr_id)
self.assertEqual(obj.title, new_title)

Expand Down Expand Up @@ -124,7 +128,7 @@ def test_dynamic_sizes(self):
for size in size_bunch:
self.assertEqual(unslash(size.source), getattr(photo, FLICKR_PHOTO_SIZES[size.label]['label']).source)
self.assertEqual(unslash(size.url), getattr(photo, FLICKR_PHOTO_SIZES[size.label]['label']).url)
Photo.objects.update_from_json(flickr_id=photo.flickr_id, photo=json_info_photo, info=json_info, sizes=json_sizes, exif=json_exif)
Photo.objects.update_from_json(self.flickr_user, flickr_id=photo.flickr_id, photo=json_info_photo, info=json_info, sizes=json_sizes, exif=json_exif)
photo = Photo.objects.get(flickr_id=photo.flickr_id)
self.assertEqual(photo.square_source, photo.square.source)
self.assertEqual(photo.thumb_source, photo.thumb.source)
Expand All @@ -146,10 +150,53 @@ def test_dynamic_sizes_dbhits(self):
for size in size_bunch:
self.assertEqual(unslash(size.source), getattr(photo, FLICKR_PHOTO_SIZES[size.label]['label']).source)
self.assertEqual(unslash(size.url), getattr(photo, FLICKR_PHOTO_SIZES[size.label]['label']).url)
Photo.objects.update_from_json(flickr_id=photo.flickr_id, photo=json_info, sizes=json_sizes, exif=json_exif)
Photo.objects.update_from_json(self.flickr_user, flickr_id=photo.flickr_id, photo=json_info, sizes=json_sizes, exif=json_exif)
photo = Photo.objects.get(flickr_id=photo.flickr_id)
with self.assertNumQueries(1):
size_bunch = bunchify(json_sizes['sizes']['size'])
for size in size_bunch:
self.assertEqual(unslash(size.source), getattr(photo, FLICKR_PHOTO_SIZES[size.label]['label']).source)
self.assertEqual(unslash(size.url), getattr(photo, FLICKR_PHOTO_SIZES[size.label]['label']).url)

@override_settings(ROOT_URLCONF='flickr.urls')
def test_views_index(self):
response = self.client.get(reverse('flickr_index'))
self.assertEquals(response.status_code, 200)
self.assertTrue("flickr/index.html" in [tmpl.name for tmpl in response.templates])

@override_settings(ROOT_URLCONF='flickr.urls')
def test_views_photo_invalid(self):
with self.assertRaises(TemplateDoesNotExist) as exc_info:
self.client.get(reverse('flickr_photo', kwargs={'flickr_id': 99999}))
self.assertEquals(str(exc_info.exception), "404.html")
with self.assertRaises(ValueError) as exc_info:
self.client.get(reverse('flickr_photo', kwargs={'flickr_id': "random"}))

@override_settings(ROOT_URLCONF='flickr.urls')
def test_views_photo(self):
json_info = json_photos_extras['photos']['photo'][0]
FlickrUser.objects.update_from_json(self.flickr_user.id, json_user)
flickr_user = FlickrUser.objects.get(flickr_id=json_user['person']['id'])
photo = Photo.objects.create_from_json(flickr_user=flickr_user, photo=json_info, sizes=None, exif=json_exif)

response = self.client.get(reverse('flickr_photo', kwargs={'flickr_id': photo.flickr_id}))
self.assertEquals(response.status_code, 200)
self.assertTrue("flickr/photo_page.html" in [tmpl.name for tmpl in response.templates])
self.assertTrue(photo.title in response.content)

@override_settings(ROOT_URLCONF='flickr.urls')
def test_views_photoset(self):
json_info = json_photos_extras['photos']['photo'][0]
photo = Photo.objects.create_from_json(flickr_user=self.flickr_user, photo=json_info, sizes=json_sizes, exif=json_exif)
photoset = PhotoSet.objects.create_from_json(flickr_user=self.flickr_user, info=json_set_info['photoset'], photos=json_set_photos)

response = self.client.get(reverse('flickr_photoset', kwargs={'flickr_id': photoset.flickr_id}))
self.assertEquals(response.status_code, 200)
self.assertTrue("flickr/index.html" in [tmpl.name for tmpl in response.templates])
self.assertTrue(photoset.title in response.content)
self.assertTrue(photo.description in response.content)

def test_imports(self):
import flickr.admin
import flickr.management.commands.flickr_download
import flickr.management.commands.flickr_sync
3 changes: 2 additions & 1 deletion flickr/tests_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
"username": { "_content": "zalew" },
"realname": { "_content": "jakub zalewski" },
"mbox_sha1sum": { "_content": "xxxxxxxx" },
"location": { "_content": "" },
"location": { "_content": "Belgium" },
"timezone": { "timezone_id": "Europe/Brussels", "offset": "+01:00", "label": "Brussels, Copenhagen, Madrid, Paris"},
"photosurl": { "_content": "http:\/\/www.flickr.com\/photos\/zalew\/" },
"profileurl": { "_content": "http:\/\/www.flickr.com\/people\/zalew\/" },
"mobileurl": { "_content": "http:\/\/m.flickr.com\/photostream.gne?id=2306806" },
Expand Down
2 changes: 2 additions & 0 deletions flickr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


def ts_to_dt(timestamp, offset=''):
if offset is None:
offset = ""
return '%s%s' % (datetime.fromtimestamp(int(timestamp)).strftime('%Y-%m-%d %H:%M:%S'), offset)


Expand Down
10 changes: 5 additions & 5 deletions req.pip
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
django>=1.4
bunch
django-taggit
django-taggit-templatetags
oauth2
django>=1.4,<1.5
bunch==1.0.1
django-taggit==0.9.3
django-taggit-templatetags==0.4.6.dev0
oauth2==1.5.211
4 changes: 4 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pytest<4
pytest-cov
django-test-plus==1.0.15
pytest-django<3.0
13 changes: 13 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[coverage:run]
source = flickr

[coverage:report]
omit =
*/migrations/*

[tool:pytest]
DJANGO_SETTINGS_MODULE = example.settings
django_find_project = false
python_paths = .
python_files = tests.py test_*.py *_tests.py
norecursedirs = build dist docs *.egg-info htmlcov
Loading

0 comments on commit 2fe44a3

Please sign in to comment.