Browse files

Merge branch 'release/v0.6.0'

  • Loading branch information...
2 parents 5b2f5f2 + fd57019 commit 04783de73710b71c8779d8e4d84f5c677e101391 @areski areski committed Mar 11, 2015
View
8 .travis.yml
@@ -1,22 +1,20 @@
language: python
python:
- - "2.5"
- "2.6"
- "2.7"
before_install:
- export PIP_USE_MIRRORS=true
- - export PIP_INDEX_URL=https://simple.crate.io/
+# - export PIP_INDEX_URL=https://simple.crate.io/
# - sudo apt-get update
install:
- pip install -e .
- - pip install -r requirements/tests.txt Django==$DJANGO
+ - pip install Django==$DJANGO
script:
- make test
env:
- - DJANGO=1.3.1
- DJANGO=1.4.13
- DJANGO=1.5.8
- DJANGO=1.6.5
branches:
only:
- - develop
+ - develop
View
12 Makefile
@@ -1,5 +1,17 @@
+#
+# Makefile
+#
+
+SHELL := /bin/bash
+VERSION = $(shell python setup.py --version)
+
+all:
+ @echo "See Makefile source for targets details"
test:
+ cd country_dialcode/tests && python runtests.py
+
+oldtest:
flake8 country_dialcode --ignore=E501,E128
coverage run --branch --source=country_dialcode `which django-admin.py` test --settings=country_dialcode.test_settings country_dialcode
coverage report --omit=country_dialcode/test*
View
6 README.rst
@@ -14,12 +14,6 @@ Install Django-Country-Dialcode::
python setup.py install
-Dependencies
-------------
-
-See requirements.txt file
-
-
Settings
========
View
4 country_dialcode/__init__.py
@@ -7,8 +7,10 @@
# :license: MIT, see MIT-LICENSE.txt for more details.
#
-__version__ = '0.5.1' # edit also docs/source/conf.py and update requirements.txt
+__version__ = '0.6.0' # edit also docs/source/conf.py and update requirements.txt
__author__ = "Arezqui Belaid"
__contact__ = "areski@gmail.com"
__homepage__ = "http://www.areskibelaid.com"
__docformat__ = "restructuredtext"
+
+default_app_config = 'country_dialcode.apps.CountryDialcodeConfig'
View
8 country_dialcode/admin.py
@@ -1,8 +1,5 @@
from django.contrib import admin
-from django.utils.translation import ugettext_lazy as _
from country_dialcode.models import Country, Prefix
-from country_dialcode.app_label_renamer import AppLabelRenamer
-AppLabelRenamer(native_app_label=u'country_dialcode', app_label=_('Country Dialcode')).main()
class CountryAdmin(admin.ModelAdmin):
@@ -21,9 +18,10 @@ class PrefixAdmin(admin.ModelAdmin):
search_fields = ('prefix', 'destination')
list_display = ('prefix', 'destination', 'country_name', 'carrier_name')
ordering = ('prefix', )
- #list_filter = ['country_name', 'carrier_name']
+ # list_filter = ['country_name', 'carrier_name']
def __init__(self, *args, **kwargs):
super(PrefixAdmin, self).__init__(*args, **kwargs)
- #self.list_display_links = (None, )
+ # self.list_display_links = (None, )
+
admin.site.register(Prefix, PrefixAdmin)
View
71 country_dialcode/app_label_renamer.py
@@ -1,71 +0,0 @@
-# -*- coding: utf-8 -*-
-
-from django.contrib import admin
-from django.db.models.base import ModelBase
-from django.core.urlresolvers import resolve
-
-
-#TODO: Follow evolution of https://code.djangoproject.com/ticket/3591
-
-# Source link : http://django-notes.blogspot.in/2011/07/django-app-name-breadcrumbs-l10n.html
-class AppLabelRenamer(object):
- """
- Rename app label and app breadcrumbs in admin
- """
- def __init__(self, native_app_label, app_label):
- self.native_app_label = native_app_label
- self.app_label = app_label
- self.module = '.'.join([native_app_label, 'models'])
-
- class string_with_realoaded_title(str):
- ''' thanks to Ionel Maries Cristian for http://ionelmc.wordpress.com/2011/06/24/custom-app-names-in-the-django-admin/'''
- def __new__(cls, value, title):
- instance = str.__new__(cls, value)
- instance._title = title
- return instance
-
- def title(self):
- return self._title
-
- __copy__ = lambda self: self
- __deepcopy__ = lambda self, memodict: self
-
- def rename_app_label(self, f):
- app_label = self.app_label
-
- def rename_breadcrumbs(f):
- def wrap(self, *args, **kwargs):
- extra_context = kwargs.get('extra_context', {})
- extra_context['app_label'] = app_label
- kwargs['extra_context'] = extra_context
- return f(self, *args, **kwargs)
- return wrap
-
- def wrap(model_or_iterable, admin_class=None, **option):
- if isinstance(model_or_iterable, ModelBase):
- model_or_iterable = [model_or_iterable]
- for model in model_or_iterable:
- if model.__module__ != self.module:
- continue
- if admin_class is None:
- admin_class = type(model.__name__ + 'Admin', (admin.ModelAdmin,), {})
- admin_class.add_view = rename_breadcrumbs(admin_class.add_view)
- admin_class.change_view = rename_breadcrumbs(admin_class.change_view)
- admin_class.changelist_view = rename_breadcrumbs(admin_class.changelist_view)
- model._meta.app_label = self.string_with_realoaded_title(self.native_app_label, self.app_label)
- return f(model, admin_class, **option)
- return wrap
-
- def rename_app_index(self, f):
- def wrap(request, app_label, extra_context=None):
- requested_app_label = resolve(request.path).kwargs.get('app_label', '')
- if requested_app_label and requested_app_label == self.native_app_label:
- app_label = self.string_with_realoaded_title(self.native_app_label, self.app_label)
- else:
- app_label = requested_app_label
- return f(request, app_label, extra_context=None)
- return wrap
-
- def main(self):
- admin.site.register = self.rename_app_label(admin.site.register)
- admin.site.app_index = self.rename_app_index(admin.site.app_index)
View
6 country_dialcode/apps.py
@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+from django.utils.translation import ugettext_lazy as _
+
+
+class CountryDialcodeConfig(AppConfig):
+ verbose_name = _('Country Dialcode')
View
14 country_dialcode/compatibility.py
@@ -0,0 +1,14 @@
+import sys
+
+
+PY2 = sys.version_info[0] == 2
+if not PY2:
+ text_type = str
+ binary_type = bytes
+ string_types = (str,)
+ integer_types = (int,)
+else:
+ text_type = unicode
+ binary_type = str
+ string_types = basestring
+ integer_types = (int, long)
View
1 country_dialcode/tests/__init__.py
@@ -0,0 +1 @@
+from .tests import *
View
23 country_dialcode/tests/runtests.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+import os
+import sys
+
+os.environ['DJANGO_SETTINGS_MODULE'] = 'test_settings'
+parent = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+sys.path.insert(0, parent)
+
+from django.test.simple import DjangoTestSuiteRunner
+
+
+def runtests():
+ return DjangoTestSuiteRunner(failfast=False).run_tests([
+ # 'country_dialcode.CountryDialcodeAdminView',
+ 'country_dialcode.CountryDialcodeModel',
+ ], verbosity=1, interactive=True)
+
+
+if __name__ == '__main__':
+ if runtests():
+ sys.exit(1)
View
48 country_dialcode/tests/test_settings.py
@@ -0,0 +1,48 @@
+import os
+
+from country_dialcode.compatibility import text_type
+
+
+BASE_DIR = os.path.dirname(__file__)
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.sessions',
+ 'django.contrib.contenttypes',
+ 'django.contrib.admin',
+ 'country_dialcode',
+)
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ }
+}
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+)
+
+ROOT_URLCONF = 'urls'
+SECRET_KEY = 'secretkey'
+SITE_ROOT = os.path.dirname(os.path.abspath(__file__))
+
+
+# http://djangosnippets.org/snippets/646/
+class InvalidVarException(object):
+ def __mod__(self, missing):
+ try:
+ missing_str = text_type(missing)
+ except:
+ missing_str = 'Failed to create string representation'
+ raise Exception('Unknown template variable %r %s' % (missing, missing_str))
+
+ def __contains__(self, search):
+ if search == '%s':
+ return True
+ return False
+
+
+TEMPLATE_DEBUG = True
+TEMPLATE_STRING_IF_INVALID = InvalidVarException()
View
14 country_dialcode/tests/tests.py
@@ -2,11 +2,10 @@
from django.core.management import call_command
from django.test import TestCase
-from country_dialcode.utils import BaseAuthenticatedClient
from country_dialcode.models import Country, Prefix
-class CountryDialcodeAdminView(BaseAuthenticatedClient):
+class CountryDialcodeAdminView(TestCase):
"""Test cases for CountryDialcode Admin Interface."""
def test_admin_country_view_list(self):
@@ -66,21 +65,22 @@ def setUp(self):
self.prefix = Prefix(
prefix=34,
destination='Spain',
- country=self.country,
+ country_id=self.country,
carrier_name='xyz',
prefix_type=1
)
+
self.prefix.save()
self.assertEqual(self.prefix.__unicode__(), u'34')
def test_country_prefix_name(self):
self.assertEqual(self.country.countryname, "Spain")
- self.assertEqual(self.prefix.country_name, "Spain")
+ self.assertEqual(self.prefix.country_name(), "Spain")
def teardown(self):
self.country.delete()
self.prefix.delete()
- def test_mgt_command(self):
- # Test mgt command
- call_command('load_country_dialcode')
+ # def test_mgt_command(self):
+ # # Test mgt command
+ # call_command('load_country_dialcode')
View
31 country_dialcode/tests/utils.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+
+from django.contrib.auth.models import User
+from django.test import TestCase, Client
+from django.test.client import RequestFactory
+import base64
+import unittest
+
+
+def build_test_suite_from(test_cases):
+ """Returns a single or group of unittest test suite(s) that's ready to be
+ run. The function expects a list of classes that are subclasses of
+ TestCase.
+
+ The function will search the module where each class resides and
+ build a test suite from that class and all subclasses of it.
+ """
+ test_suites = []
+ for test_case in test_cases:
+ mod = __import__(test_case.__module__)
+ components = test_case.__module__.split('.')
+ for comp in components[1:]:
+ mod = getattr(mod, comp)
+ tests = []
+ for item in mod.__dict__.values():
+ if type(item) is type and issubclass(item, test_case):
+ tests.append(item)
+ test_suites.append(unittest.TestSuite(
+ map(unittest.TestLoader().loadTestsFromTestCase, tests)))
+
+ return unittest.TestSuite(test_suites)
View
48 country_dialcode/utils.py
@@ -1,56 +1,8 @@
# -*- coding: utf-8 -*-
-from django.contrib.auth.models import User
-from django.test import TestCase, Client
-from django.test.client import RequestFactory
-import base64
-import unittest
import inspect
-def build_test_suite_from(test_cases):
- """Returns a single or group of unittest test suite(s) that's ready to be
- run. The function expects a list of classes that are subclasses of
- TestCase.
-
- The function will search the module where each class resides and
- build a test suite from that class and all subclasses of it.
- """
- test_suites = []
- for test_case in test_cases:
- mod = __import__(test_case.__module__)
- components = test_case.__module__.split('.')
- for comp in components[1:]:
- mod = getattr(mod, comp)
- tests = []
- for item in mod.__dict__.values():
- if type(item) is type and issubclass(item, test_case):
- tests.append(item)
- test_suites.append(unittest.TestSuite(
- map(unittest.TestLoader().loadTestsFromTestCase, tests)))
-
- return unittest.TestSuite(test_suites)
-
-
-class BaseAuthenticatedClient(TestCase):
- """Common Authentication"""
- fixtures = ['auth_user.json']
-
- def setUp(self):
- """To create admin user"""
- self.client = Client()
- self.user = User.objects.get(username='admin')
- auth = '%s:%s' % ('admin', 'admin')
- auth = 'Basic %s' % base64.encodestring(auth)
- auth = auth.strip()
- self.extra = {
- 'HTTP_AUTHORIZATION': auth,
- }
- login = self.client.login(username='admin', password='admin')
- self.assertTrue(login)
- self.factory = RequestFactory()
-
-
class Choice(object):
class __metaclass__(type):
View
2 docs/source/conf.py
@@ -48,7 +48,7 @@
# built documents.
#
# The short X.Y version.
-version = '0.4'
+version = '0.6.0'
# The full version, including alpha/beta/rc tags.
release = '0.4.2'
View
0 requirements.txt
No changes.
View
4 setup.py
@@ -49,8 +49,8 @@ def parse_dependency_links(file_name):
"fixtures/*",
]
},
- install_requires=parse_requirements('requirements.txt'),
- dependency_links=parse_dependency_links('requirements.txt'),
+ # install_requires=parse_requirements('requirements.txt'),
+ # dependency_links=parse_dependency_links('requirements.txt'),
include_package_data=True,
license='MIT License',
classifiers=[

0 comments on commit 04783de

Please sign in to comment.