Commits

Apostolis Bessas committed 6d85fce

Fixes for tests in resources app, regarding source_language changes in API.

  • Participants
  • Parent commits ea0a77e

Comments (0)

Files changed (1)

File transifex/resources/tests/api/__init__.py

             }
         )
 
-    def test_is_same_source_lang(self):
-        """Test the method that determines whether a source language is/is not
-        accepted in a project.
-        """
-        rh = ResourceHandler()
-        p = Project.objects.create(slug='slug', name='name', source_language=self.language_en)
-        r = Resource.objects.create(
-            slug='rslug1', project=p, source_language=self.language_en
-        )
-        r = Resource(
-            slug='rslug2', project=p
-        )
-        self.assertFalse(rh._is_same_source_lang(p, self.language_ar))
-        self.assertTrue(rh._is_same_source_lang(p, self.language_en))
-        r.source_language = self.language_en
-        r.save()
-        r = Resource(
-            slug='rslug3', project=p
-        )
-        self.assertFalse(rh._is_same_source_lang(p, self.language_ar))
-        self.assertTrue(rh._is_same_source_lang(p, self.language_en))
-
-    def test_create_resource_same_source_language(self):
-        """Test the restriction of having the same source languages when
-        creating a resource through the API.
-        """
-        self._create_project()
-        with open(self.po_file) as f:
-            content = f.read()
-        res = self.client['registered'].post(
-            self.url_create_resource,
-            data=simplejson.dumps({
-                    'name': "resource1",
-                    'slug': 'rslug1',
-                    'source_language': 'el',
-                    'i18n_type': 'PO',
-                    'content': content,
-            }),
-            content_type='application/json'
-        )
-        self.assertEquals(res.status_code, 201)
-        res = self.client['registered'].post(
-            self.url_create_resource,
-            data=simplejson.dumps({
-                    'name': "resource1",
-                    'slug': 'rslug2',
-                    'source_language': 'en',
-                    'i18n_type': 'PO',
-                    'content': content,
-            }),
-            content_type='application/json'
-        )
-        self.assertContains(res, "same source language", status_code=400)
-        res = self.client['registered'].post(
-            self.url_create_resource,
-            data=simplejson.dumps({
-                    'name': "resource1",
-                    'slug': 'rslug2',
-                    'source_language': 'el',
-                    'i18n_type': 'PO',
-                    'content': content,
-            }),
-            content_type='application/json'
-        )
-        self.assertEquals(res.status_code, 201)
-        res = self.client['registered'].post(
-            self.url_create_resource,
-            data=simplejson.dumps({
-                    'name': "resource1",
-                    'slug': 'rslug3',
-                    'i18n_type': 'PO',
-                    'content': content,
-            }),
-            content_type='application/json'
-        )
-        self.assertEquals(res.status_code, 201)
-        r = Resource.objects.get(slug='rslug3', project__slug='new_pr')
-        self.assertEquals(r.source_language.code, 'el')
-
     def test_get(self):
         res = self.client['anonymous'].get(self.url_resources)
         self.assertEquals(res.status_code, 401)
         res = self.client['registered'].get(self.url_new_resource)
         self.assertEquals(res.status_code, 200)
         data = simplejson.loads(res.content)
-        self.assertTrue('source_language' in data)
+        self.assertTrue('source_language_code' in data)
         res = self.client['registered'].get(
             self.url_new_resource + "content/"
         )
             data=simplejson.dumps({
                     'name': "resource1",
                     'slug': 'r1',
-                    'source_language': 'el',
                     'foo': 'foo'
             }),
             content_type='application/json'
                     'name': "resource1",
                     'name': "resource2",
                     'slug': 'r2',
-                    'source_language': 'el',
             }),
             content_type='application/json'
         )
             data={
                 'name': "resource1",
                 'slug': 'r1',
-                'source_language': 'el',
                 'i18n_type': 'PO',
                 'name': 'name.po',
                 'attachment': f
         res = self.client['registered'].put(
             url,
             data=simplejson.dumps({
-                    'source_language': "el_NN",
-            }),
-            content_type='application/json'
-        )
-        self.assertEquals(res.status_code, 400)
-        res = self.client['registered'].put(
-            url,
-            data=simplejson.dumps({
-                    'source_language': "el",
-            }),
-            content_type='application/json'
-        )
-        self.assertEquals(res.status_code, 400)
-        res = self.client['registered'].put(
-            url,
-            data=simplejson.dumps({
                     'i18n_type': "PO",
             }),
             content_type='application/json'
             self.url_new_project,
             data=simplejson.dumps({
                     'slug': 'new_pr', 'name': 'Project from API',
-                    'source_language': 'el',
+                    'source_language_code': 'el',
                     'maintainers': 'registered',
             }),
             content_type='application/json'
             data=simplejson.dumps({
                     'name': "resource1",
                     'slug': 'r1',
-                    'source_language': 'el',
                     'i18n_type': 'PO',
                     'content': content,
             }),
             self.url_new_project,
             data=simplejson.dumps({
                     'slug': 'new_pr', 'name': 'Project from API',
-                    'source_language': 'el',
+                    'source_language_code': 'el',
                     'maintainers': 'registered',
             }),
             content_type='application/json'
             data=simplejson.dumps({
                     'name': "resource1",
                     'slug': 'a-very-long-slug' * 10,
-                    'source_language': 'el',
                     'i18n_type': 'PO',
                     'content': content,
             }),
             self.url_new_project,
             data=simplejson.dumps({
                     'slug': 'new_pr', 'name': 'Project from API',
-                    'source_language': 'el',
+                    'source_language_code': 'el',
                     'maintainers': 'registered',
             }),
             content_type='application/json'
             data=simplejson.dumps({
                     'name': "resource1",
                     'slug': 'r1',
-                    'source_language': 'el',
                     'i18n_type': 'PO',
                     'content': content,
             }),
             data=simplejson.dumps({
                     'name': "resource1",
                     'slug': 'r1',
-                    'source_language': 'el',
                     'i18n_type': 'PO',
                     'content': content,
             }),
             data=simplejson.dumps({
                     'name': "resource2",
                     'slug': 'r2',
-                    'source_language': 'el',
                     'i18n_type': 'PO',
             }),
             content_type='application/json'
             data=simplejson.dumps({
                     'name': "resource1",
                     'slug': 'r1',
-                    'source_language': 'el',
                     'i18n_type': 'INI',
                     'content': content,
             }),
             data=simplejson.dumps({
                     'name': "rα",
                     'slug': 'r1',
-                    'source_language': 'el',
                     'i18n_type': 'PO',
                     'content': content,
             }),
             self.url_new_project,
             data=simplejson.dumps({
                     'slug': 'new_pr', 'name': 'Project from API',
-                    'source_language': 'el',
+                    'source_language_code': 'el',
                     'maintainers': 'registered',
             }),
             content_type='application/json'
             data=simplejson.dumps({
                     'name': "resource1",
                     'slug': 'r1',
-                    'source_language': 'el',
                     'i18n_type': 'PO',
                     'content': content,
             }),
             self.url_new_project,
             data=simplejson.dumps({
                     'slug': self.project_slug, 'name': 'Project from API',
-                    'source_language': 'el',
+                    'source_language_code': 'el',
                     'maintainers': 'registered',
             }),
             content_type='application/json'
             data=simplejson.dumps({
                     'name': "resource1",
                     'slug': self.resource_slug,
-                    'source_language': 'el',
                     'i18n_type': 'INI',
                     'content': self.content,
             }),