Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Oct 13, 2014
1 parent 68e56fd commit 3e187eb
Show file tree
Hide file tree
Showing 21 changed files with 192 additions and 28 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Release history
=====================================
0.6
-------------------------------------
2014-10-12

- Django 1.7 support.

0.5
-------------------------------------
2013-09-09

- Python 3 support.

0.1
-------------------------------------
2013-02-04

- Initial.
3 changes: 2 additions & 1 deletion CREDITS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Bug reporters
~~~~~~~~~~~~~~~~~~~~~~
The following people contributed to the project by reportings bugs.

- Raitis Stengrevics: Reported an issue of a hard-coded HTTP protocol in ``qartez.RelAlternateHreflangSitemap``.
- Raitis Stengrevics: Reported an issue of a hard-coded HTTP protocol in
``qartez.RelAlternateHreflangSitemap``.
4 changes: 3 additions & 1 deletion builddocs.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
./uninstall.sh
./install.sh
sphinx-build -n -a -b html docs builddocs
sphinx-build -n -a -b html docs builddocs
cd builddocs && zip -r ../builddocs.zip . -x ".*" && cd ..
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import random

from six import print_, PY2, PY3
from six import print_, PY3
from six.moves import range

PY2 = not PY3

if PY2:
from string import translate, maketrans, punctuation
else:
Expand Down
2 changes: 1 addition & 1 deletion example/example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
PROJECT_DIR('templates')
PROJECT_DIR('templates'),
)

#FIXTURE_DIRS = (
Expand Down
7 changes: 7 additions & 0 deletions example/freeze.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Django==1.5.2
Pillow==2.1.0
argparse==1.2.1
django-qartez==0.5
radar==0.2
six==1.4.1
wsgiref==0.1.2
16 changes: 7 additions & 9 deletions example/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
Django==1.5.1
Pillow==2.0.0
argparse==1.2.1
django-debug-toolbar==0.9.4
django-qartez==0.3
ipdb==0.7
ipython==0.13.2
qartez==0.3
wsgiref==0.1.2
Django>=1.5,<1.8
Pillow
argparse
django-debug-toolbar
ipdb
ipython
wsgiref
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
template_dir = "src/qartez/templates/qartez"
templates = [os.path.join(template_dir, f) for f in os.listdir(template_dir)]

version = '0.5'
version = '0.6'

setup(
name = 'django-qartez',
Expand Down
7 changes: 4 additions & 3 deletions src/qartez/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
__title__ = 'qartez.__init__'
__version__ = '0.5'
__build__ = 0x000005
__version__ = '0.6'
__build__ = 0x000006
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__all__ = ('ImagesSitemap', 'StaticSitemap', 'RelAlternateHreflangSitemap',)

import datetime

from six import PY2, PY3
from six import PY3

from django.contrib.sitemaps import Sitemap, GenericSitemap
from django.core.urlresolvers import reverse_lazy
Expand All @@ -17,6 +17,7 @@
from qartez.constants import REL_ALTERNATE_HREFLANG_SITEMAP_TEMPLATE
from qartez.settings import PREPEND_LOC_URL_WITH_SITE_URL, PREPEND_IMAGE_LOC_URL_WITH_SITE_URL

PY2 = not PY3

class ImagesSitemap(GenericSitemap):
"""
Expand Down
2 changes: 0 additions & 2 deletions src/qartez/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
__title__ = 'qartez'
__version__ = '0.5'
__build__ = 0x000005
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__all__ = ('get_setting',)

Expand Down
2 changes: 0 additions & 2 deletions src/qartez/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
__title__ = 'qartez'
__version__ = '0.5'
__build__ = 0x000005
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__all__ = ('REL_ALTERNATE_HREFLANG_SITEMAP_TEMPLATE',)

Expand Down
2 changes: 0 additions & 2 deletions src/qartez/defaults.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
__title__ = 'qartez'
__version__ = '0.5'
__build__ = 0x000005
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__all__ = ('PREPEND_LOC_URL_WITH_SITE_URL', 'PREPEND_IMAGE_LOC_URL_WITH_SITE_URL', 'CHANGEFREQ', 'DEBUG')

Expand Down
Empty file added src/qartez/models.py
Empty file.
2 changes: 0 additions & 2 deletions src/qartez/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
``CHANGEFREQ``: Valid changefreq values according to the specs http://www.sitemaps.org/protocol.html
"""
__title__ = 'qartez'
__version__ = '0.5'
__build__ = 0x000005
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__all__ = ('PREPEND_LOC_URL_WITH_SITE_URL', 'PREPEND_IMAGE_LOC_URL_WITH_SITE_URL', 'CHANGEFREQ', 'DEBUG')

Expand Down
11 changes: 11 additions & 0 deletions src/qartez/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
__title__ = 'qartez.tests'
__author__ = 'Artur Barseghyan'
__copyright__ = 'Copyright (c) 2013-2014 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'

import unittest

from qartez.tests.test_sitemaps import *

if __name__ == '__main__':
unittest.main()
30 changes: 30 additions & 0 deletions src/qartez/tests/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import print_function

__title__ = 'qartez.tests.base'
__author__ = 'Artur Barseghyan'
__copyright__ = 'Copyright (c) 2013-2014 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'

PRINT_INFO = True

def print_info(func):
"""
Prints some useful info.
"""
if not PRINT_INFO:
return func

def inner(self, *args, **kwargs):
result = func(self, *args, **kwargs)

print('\n\n%s' % func.__name__)
print('============================')
if func.__doc__:
print('""" %s """' % func.__doc__.strip())
print('----------------------------')
if result is not None:
print(result)
print('\n++++++++++++++++++++++++++++')

return result
return inner
98 changes: 98 additions & 0 deletions src/qartez/tests/test_sitemaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
__title__ = 'qartez.tests.test_sitemaps'
__author__ = 'Artur Barseghyan'
__copyright__ = 'Copyright (c) 2013-2014 Artur Barseghyan'
__license__ = 'GPL 2.0/LGPL 2.1'

import unittest
import os

# Skipping from non-Django tests.
if os.environ.get("DJANGO_SETTINGS_MODULE", None):
from django.test import Client

from qartez.tests.base import print_info

class QartezTest(unittest.TestCase):
"""
Testing sitemaps.
"""
def setUp(self):
# Testing the URLs
self.urls = {
'sitemap of sitemaps': '/sitemap.xml',
'normal sitemap': '/sitemap-foo-items.xml',
'images sitemap': '/sitemap-foo-images.xml',
'static sitemap': '/sitemap-foo-static.xml',
'alternative hreflang sitemap': '/sitemap-foo-items-alternate-hreflang.xml',
}

@print_info
def test_all_sitemaps(self):
"""
Test the all sitemaps.
"""
flow = []
## Testing view with signed URL
client = Client()
for description, url in self.urls.items():
response = client.get(url, {})
self.assertTrue(response.status_code in (200, 201, 202))
flow.append(
'Response status code for {0} is {1}'.format(
description, response.status_code
)
)

return flow

@print_info
def test_01_alternative_hreflang_sitemap(self):
"""
Test alternate hreflang sitemap.
"""
flow = []
c = Client()
response = c.get('/sitemap-foo-items-alternate-hreflang.xml', {})
self.assertTrue('hreflang="en-us"' in response.content)
self.assertTrue('rel="alternate"' in response.content)
self.assertTrue('hreflang="en-us"' in response.content)

@print_info
def test_02_static_sitemap(self):
"""
Test static sitemap.
"""
flow = []
c = Client()
response = c.get('/sitemap-foo-static.xml', {})
self.assertTrue('http://example.com/foo/contact/' in response.content)

@print_info
def test_03_images_sitemap(self):
"""
Test images sitemap.
"""
flow = []
c = Client()
response = c.get('/sitemap-foo-images.xml', {})
self.assertTrue('http://www.google.com/schemas/sitemap-image/1.1' in response.content)
self.assertTrue('<image:title>' in response.content)
self.assertTrue('<image:loc>' in response.content)
self.assertTrue('<image:image>' in response.content)

@print_info
def test_04_sitemap_of_sitemaps(self):
"""
Test sitemap of sitemaps.
"""
flow = []
c = Client()
response = c.get('/sitemap.xml', {})
self.assertTrue('<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' in response.content)
self.assertTrue('https://example.com/sitemap-foo-items-alternate-hreflang.xml' in response.content)
self.assertTrue('http://example.com/sitemap-foo-items.xml' in response.content)


if __name__ == "__main__":
# Tests
unittest.main()
2 changes: 0 additions & 2 deletions src/qartez/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
__title__ = 'qartez.views'
__version__ = '0.5'
__build__ = 0x000005
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
__all__ = ('render_images_sitemap',)

Expand Down
4 changes: 4 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
reset
./uninstall.sh
./install.sh
python example/example/manage.py test qartez --traceback -v 3
3 changes: 2 additions & 1 deletion uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pip uninstall django-qartez -y
rm build -rf
rm dist -rf
rm example/static -rf
rm src/django_qartez.egg-info -rf
rm src/django_qartez.egg-info -rf
rm builddocs.zip

0 comments on commit 3e187eb

Please sign in to comment.