Permalink
Browse files

added testcases

  • Loading branch information...
1 parent 082b0d1 commit f1bf435f1e6124e9e38639ebc7292e78bd538920 @shrenik shrenik committed Aug 14, 2012
@@ -1,8 +1,5 @@
from django.contrib import admin
-from django.conf.urls.defaults import *
-from django.utils.translation import ugettext as _
-from django.db.models import *
-from country_dialcode.models import *
+from country_dialcode.models import Country, Prefix
class CountryAdmin(admin.ModelAdmin):
@@ -29,7 +29,10 @@ def iso_flag(country_id, flag_path=u''):
@stringfilter
def country_name(country_id):
"""
- Returns a country name
+ Returns a country name
+
+ >>> country_name(198)
+ 'Spain'
"""
try:
obj_country = Country.objects.get(id=country_id)
@@ -0,0 +1,92 @@
+#
+# Django-Country-Dialcode License
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# Copyright (C) 2011-2012 Star2Billing S.L.
+#
+# The Initial Developer of the Original Code is
+# Arezqui Belaid <info@star2billing.com>
+#
+
+from django.contrib.auth.models import User
+from django.test import TestCase
+from common.utils import BaseAuthenticatedClient
+from country_dialcode.models import Country, Prefix
+
+
+class CountryDialcodeAdminView(BaseAuthenticatedClient):
+ """Test cases for CountryDialcode Admin Interface."""
+
+ def test_admin_country_view_list(self):
+ """Test Function to check admin country list"""
+ response = self.client.get("/admin/country_dialcode/country/")
+ self.assertEqual(response.status_code, 200)
+
+ def test_admin_country_view_add(self):
+ """Test Function to check admin country add"""
+ response = self.client.get("/admin/country_dialcode/country/add/")
+ self.assertEqual(response.status_code, 200)
+
+ response = self.client.post('/admin/country_dialcode/country/add/',
+ data={'countrycode': 'ESP',
+ 'iso2': 'ES',
+ 'countryprefix': '34',
+ 'countryname': 'Spain',
+ })
+ self.assertEqual(response.status_code, 200)
+
+
+ def test_admin_prefix_view_list(self):
+ """Test Function to check admin prefix list"""
+ response = self.client.get("/admin/country_dialcode/prefix/")
+ self.assertEqual(response.status_code, 200)
+
+ def test_admin_prefix_view_add(self):
+ """Test Function to check admin prefix add"""
+ response = self.client.get("/admin/country_dialcode/prefix/add/")
+ self.assertEqual(response.status_code, 200)
+
+ response = self.client.post('/admin/country_dialcode/prefix/add/',
+ data={'prefix': '34',
+ 'destination': 'Spain',
+ 'country_id': 198,
+ 'carrier_name': 'xyz',
+ 'prefix_type': 1})
+ self.assertEqual(response.status_code, 200)
+
+
+class CountryDialcodeModel(TestCase):
+ """Test Country, Prefix models"""
+
+ def setUp(self):
+ # Country model
+ self.country = Country(
+ countrycode="ESP",
+ iso2='ES',
+ countryprefix='34',
+ countryname='Spain',
+ )
+ self.country.save()
+
+ # Prefix model
+ self.prefix = Prefix(
+ prefix=34,
+ destination='Spain',
+ country_id=198,
+ carrier_name='xyz',
+ prefix_type=1
+ )
+ self.prefix.save()
+
+ def test_country_prefix_name(self):
+ self.assertEqual(self.country.countryname, "Spain")
+ self.assertEqual(self.prefix.country_name, "Spain")
+
+ def teardown(self):
+ self.country.delete()
+ self.prefix.delete()
+
+
@@ -1,6 +1,4 @@
-from django.conf.urls.defaults import *
-from django.conf import settings
-
+from django.conf.urls.defaults import patterns
urlpatterns = patterns('',

0 comments on commit f1bf435

Please sign in to comment.