Commits

Andreas Loupasakis committed 4a9df20

Some more testing and cleanup.

Comments (0)

Files changed (10)

transifex/projects/models.py

 
 
 class Project(models.Model):
-
     """
     A project is a group of translatable resources.
-
-    >>> p, created = Project.objects.get_or_create(slug="foo", name="Foo Project")
-    >>> p = Project.objects.get(slug='foo')
-    >>> p
-    <Project: Foo Project>
-    >>> Project.objects.create(slug="foo", name="Foo Project")
-    Traceback (most recent call last):
-        ...
-    IntegrityError: column slug is not unique
-    >>> if created: p.delete()
-
     """
 
     private = models.BooleanField(default=False, verbose_name=_('Private'),

transifex/projects/tests/__init__.py

+from models import *
+from templates import *
+from views import *

transifex/projects/tests/models.py

+# -*- coding: utf-8 -*-
+from django.db import IntegrityError
+from txcommon.tests.base import BaseTestCase
+from languages.models import Language
+from resources.models import Translation
+from projects.models import Project
+
+
+class ModelTests(BaseTestCase):
+    
+    def setUp(self):
+        super(ModelTests, self).setUp()
+
+    def tearDown(self):
+        super(ModelTests, self).tearDown()
+
+    def test_project_slug_integrity(self):
+        """ Check duplication of project slug."""
+        p, created = Project.objects.get_or_create(slug="foo",
+                                                   name="Foo Project")
+        new_p = Project(slug="foo", name="Foo Project")
+        self.assertRaises(IntegrityError, new_p.save)
+
+    def test_project_number_of_languages(self):
+        """Test project available translated langs."""
+        self.assertEqual(self.project.available_languages,
+            Language.objects.filter(
+                id__in=Translation.objects.filter(
+          source_entity__resource__in=self.project.resources.all()).values_list(
+              'language', flat=True).distinct()).distinct())

transifex/projects/tests/templates.py

+# -*- coding: utf-8 -*-
+from django.core.urlresolvers import reverse
+from txcommon.tests.base import BaseTestCase
+
+
+class TemplateTests(BaseTestCase):
+    
+    def setUp(self):
+        super(TemplateTests, self).setUp()
+        #URL
+        self.project_detail_url = reverse('project_detail', 
+            args=[self.project.slug]) 
+
+    def tearDown(self):
+        super(TemplateTests, self).tearDown()
+
+    def test_project_number_of_languages(self):
+        """Test that project details template contains the project translated langs."""
+        for user in ['anonymous', 'registered','team_member', 'maintainer']:
+            resp = self.client[user].get(self.project_detail_url)
+            self.assertContains(resp,
+                                '<td class="number_of_languages">%s</td>' %
+                                 len(self.project.available_languages))

transifex/projects/tests/views.py

+# -*- coding: utf-8 -*-
+from txcommon.tests.base import BaseTestCase
+
+
+class StatusTests(BaseTestCase):
+    """
+    Test the status codes.
+    """
+    pass

transifex/resources/tests/templates.py

+# -*- coding: utf-8 -*-
+from django.conf import settings
+from django.core.urlresolvers import reverse
+from txcommon.tests.base import BaseTestCase
+from resources.models import SourceEntity
+
+
+class ResourcesTemplateTests(BaseTestCase):
+
+    def setUp(self):
+        super(ResourcesTemplateTests, self).setUp()
+        #URL
+        self.resource_detail_url = reverse('resource_detail',
+            args=[self.project.slug, self.resource.slug])
+        self.project_detail_url = reverse('project_detail', 
+            args=[self.project.slug]) 
+
+    def tearDown(self):
+        super(ResourcesTemplateTests, self).tearDown()
+
+    def test_create_resource_template_tag(self):
+        """Ensure that button and the form is appeared correctly."""
+        resp = self.client['maintainer'].get(self.project_detail_url)
+        self.assertTemplateUsed(resp,
+                                'projects/resource_list.html')
+        self.assertContains(resp,
+                            "Create Resource")
+        for user in ['anonymous', 'registered','team_member']:
+            resp = self.client[user].get(self.project_detail_url)
+            self.assertNotContains(resp,
+                                   "Create Resource")
+
+    def test_priority_table_snippet(self):
+        """ Check that priority td is presented correctly."""
+        resp = self.client['maintainer'].get(self.project_detail_url)
+        self.assertTemplateUsed(resp, 'projects/resource_list.html')
+        self.assertContains(resp,
+                            'id="priority_%s"' % 
+                            (self.resource.slug ,),
+                            status_code=200)
+        self.assertContains(resp,
+                            '<span class="priority_sort" style="display:none">%s</span>' %
+                            (self.resource.priority.level ,))
+        self.assertContains(resp,
+                            '<img src="%spriorities/images/%s.png"' %
+                            (settings.STATIC_URL, 
+                             self.resource.priority.display_level ))
+        for user in ['anonymous', 'registered','team_member']:
+            resp = self.client[user].get(self.project_detail_url)
+            self.assertNotContains(resp,
+                                   'id="priority_%s"' % 
+                                   (self.resource.slug ,),
+                                   status_code=200)
+
+    def test_edit_delete_buttons_per_resource(self):
+        """ Test that edit/delete buttons appear only for maintainer in 
+        resource_list.html"""
+        resp = self.client['maintainer'].get(self.project_detail_url)
+        self.assertTemplateUsed(resp, 'projects/resource_list.html')
+        self.assertContains(resp,
+                            '<a href="%s">edit</a>' % 
+                            (reverse('resource_edit', 
+                                     args=[self.project.slug,
+                                           self.resource.slug]),),
+                            status_code=200)
+        self.assertContains(resp,
+                            '<a href="%s">del</a>' %
+                            (reverse('resource_delete', 
+                                     args=[self.project.slug,
+                                           self.resource.slug])),
+                            status_code=200)
+        # All the other user classes should not see these snippets
+        for user in ['anonymous', 'registered','team_member']:
+            resp = self.client[user].get(self.project_detail_url)
+            self.assertNotContains(resp,
+                                '<a href="%s">edit</a>' % 
+                                (reverse('resource_edit', 
+                                         args=[self.project.slug,
+                                               self.resource.slug]),),
+                                status_code=200)
+            self.assertNotContains(resp,
+                                '<a href="%s">del</a>' %
+                                (reverse('resource_delete', 
+                                         args=[self.project.slug,
+                                               self.resource.slug])),
+                                status_code=200)
+
+    def test_available_langs_per_resource(self):
+        """ Test that the correct number of resource languages appear in template."""
+        self.assertEqual(type(self.resource.available_languages.count()), int)
+        for user in ['anonymous', 'registered','team_member', 'maintainer']:
+            resp = self.client[user].get(self.project_detail_url)
+            self.assertContains(resp, 'Available Languages: %s' %
+                                (self.resource.available_languages.count()))
+
+    def test_total_strings_per_resource(self):
+        """Test that resource.total_entities return the correct amount of
+        strings in the resource_list page."""
+        self.assertEqual(self.resource.entities_count, 
+                         SourceEntity.objects.filter(
+                             resource=self.resource).count())
+        for user in ['anonymous', 'registered','team_member', 'maintainer']:
+            resp = self.client[user].get(self.project_detail_url)
+            self.assertContains(resp, 'title="Total Strings: %s' %
+                                (self.resource.entities_count))
+
+    def test_javascript_snippet_cycle_priority(self):
+        """Test if we include the ajax triggering js for priority changes."""
+        resp = self.client['maintainer'].get(self.project_detail_url)
+        self.assertTemplateUsed(resp, 'projects/resource_list.html')
+        self.assertContains(resp,
+                            'var resource_priority_cycle_url = \'%s\';'% 
+                            (reverse('cycle_resource_priority', 
+                                     args=[self.project.slug, "1111111111"]),),
+                            status_code=200)
+        self.assertContains(resp,
+                            'title="Click the flags to modify the importance of a resource."')
+        # All the other user classes should not see these snippets
+        for user in ['anonymous', 'registered','team_member']:
+            resp = self.client[user].get(self.project_detail_url)
+            self.assertNotContains(resp,
+                                'var resource_priority_cycle_url = \'%s\';'% 
+                                (reverse('cycle_resource_priority', 
+                                         args=[self.project.slug, "1111111111"]),),
+                                status_code=200)
+            self.assertNotContains(resp,
+                                'title="Click the flags to modify the importance of a resource."')
+
+    def test_translate_resource_button(self):
+        """Test that translate resource button appears in resource details."""
+        # Test the response contents
+        for user in ['team_member', 'maintainer']:
+            resp = self.client[user].get(self.resource_detail_url)
+            self.assertTemplateUsed(resp, 'resources/resource.html')
+            self.assertContains(resp,
+                                '<a id="new_translation1" class="buttonized i16 add">Translate Resource</a>',
+                                status_code=200)
+        # The anonymous users and the non-team members must not see the button
+        for user in ['anonymous', 'registered']:
+            resp = self.client[user].get(self.resource_detail_url)
+            self.assertNotContains(resp,
+                                '<a id="new_translation1" class="buttonized i16 add">Translate Resource</a>',
+                                status_code=200)
+
+    def test_resource_edit_button(self):
+        """Test that resource edit button is rendered correctly in details."""
+        # Test the response contents
+        resp = self.client['maintainer'].get(self.resource_detail_url)
+        self.assertTemplateUsed(resp, 'resources/resource.html')
+        self.assertContains(resp,
+                            '<a class="i16 edit buttonized" href="/projects/p/%s/resource/%s/edit">Edit</a>' % 
+                            (self.project.slug, self.resource.slug),
+                            status_code=200)
+        # In any other case of user this should not be rendered
+        for user in ['anonymous', 'registered', 'team_member']:
+            resp = self.client[user].get(self.resource_detail_url)
+            self.assertNotContains(resp,
+                                '<a class="i16 edit buttonized" href="/projects/p/%s/resource/%s/edit">Edit</a>' %
+                                (self.project.slug, self.resource.slug),
+                                status_code=200)
+
+    def test_delete_translation_resource_button(self):
+        """Test that delete translation resource button is rendered correctly."""
+        resp = self.client['maintainer'].get(self.resource_detail_url)
+        self.assertTemplateUsed(resp, 'resources/resource.html')
+        self.assertContains(resp,
+                            '<a class="i16 edit buttonized" href="/projects/p/%s/resource/%s/edit">Edit</a>' % 
+                            (self.project.slug, self.resource.slug),
+                            status_code=200)
+        # In any other case of user this should not be rendered
+        for user in ['anonymous', 'registered', 'team_member']:
+            resp = self.client[user].get(self.resource_detail_url)
+            self.assertNotContains(resp,
+                                '<a class="i16 delete buttonized" href="/projects/p/%s/resource/%s/delete">Delete translation resource</a>' %
+                                (self.project.slug, self.resource.slug),
+                                status_code=200)

transifex/resources/tests/views/views.py

 class CoreViewsTest(BaseTestCase):
     """Test basic view function"""
 
-    def test_stringset_handling(self):
-        """
-        Test AJAX stringset handler.
-        """
-        #FIXME: Find a way to emulate dataTables in order to test this view
-        pass
-
     def test_resource_details(self):
         """
         Test resource details of a resource.

transifex/resources/views.py

 
 from resources.forms import ResourceForm
 from resources.models import Translation, Resource
-from resources.stats import ResourceStatsList
+from resources.stats import ResourceStatsList, ProjectStatsList
 
 from autofetch.forms import URLInfoForm
 from autofetch.models import URLInfo

transifex/templates/projects/project_detail.html

 
     <tr>
       <th class="i16 language" title="only for resources">{% blocktrans %}Number of Languages: {% endblocktrans %}</th>
-      <td>
-        {{ statslist.available_languages|length }}
-      </td>
+      <td class="number_of_languages">{{ statslist.available_languages|length }}</td>
     </tr>
 
 {% comment %}

transifex/templates/resources/resource_list_more.html

     </a>
     <sup class="entry_metalink">
         {% if is_maintainer or request.user.is_superuser %}
-            <a href="{% url resource_edit project_slug=project.slug resource_slug=res.slug %}">{% trans "edit" %}</a>
-            , <a href="{% url resource_delete project_slug=project.slug resource_slug=res.slug %}">{% trans "del" %}</a>
+            <a href="{% url resource_edit project_slug=project.slug resource_slug=stat.resource.slug %}">{% trans "edit" %}</a>
+            , <a href="{% url resource_delete project_slug=project.slug resource_slug=stat.resource.slug %}">{% trans "del" %}</a>
         {% endif %}
     </sup>
     </td>