Skip to content
This repository has been archived by the owner on Oct 15, 2021. It is now read-only.

Commit

Permalink
Fixes for tests in resources app, regarding source_language changes i…
Browse files Browse the repository at this point in the history
…n API.
  • Loading branch information
Apostolos Bessas committed Dec 13, 2011
1 parent 84ca7f5 commit 02672fa
Showing 1 changed file with 6 additions and 113 deletions.
119 changes: 6 additions & 113 deletions transifex/resources/tests/api/__init__.py
Expand Up @@ -52,85 +52,6 @@ def setUp(self):
}
)

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)
Expand Down Expand Up @@ -182,7 +103,7 @@ def test_get(self):
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/"
)
Expand Down Expand Up @@ -218,7 +139,6 @@ def test_post_errors(self):
data=simplejson.dumps({
'name': "resource1",
'slug': 'r1',
'source_language': 'el',
'foo': 'foo'
}),
content_type='application/json'
Expand All @@ -230,7 +150,6 @@ def test_post_errors(self):
'name': "resource1",
'name': "resource2",
'slug': 'r2',
'source_language': 'el',
}),
content_type='application/json'
)
Expand All @@ -245,7 +164,6 @@ def test_post_files(self):
data={
'name': "resource1",
'slug': 'r1',
'source_language': 'el',
'i18n_type': 'PO',
'name': 'name.po',
'attachment': f
Expand Down Expand Up @@ -291,22 +209,6 @@ def test_put(self):
'apiv2_resource',
kwargs={'project_slug': 'new_pr', 'resource_slug': 'r1'}
)
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({
Expand Down Expand Up @@ -342,7 +244,7 @@ def _create_project(self):
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'
Expand All @@ -358,7 +260,6 @@ def _create_resource(self):
data=simplejson.dumps({
'name': "resource1",
'slug': 'r1',
'source_language': 'el',
'i18n_type': 'PO',
'content': content,
}),
Expand Down Expand Up @@ -416,7 +317,7 @@ def test_long_slug(self):
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'
Expand All @@ -429,7 +330,6 @@ def test_long_slug(self):
data=simplejson.dumps({
'name': "resource1",
'slug': 'a-very-long-slug' * 10,
'source_language': 'el',
'i18n_type': 'PO',
'content': content,
}),
Expand All @@ -442,7 +342,7 @@ def test_post_errors(self):
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'
Expand All @@ -455,7 +355,6 @@ def test_post_errors(self):
data=simplejson.dumps({
'name': "resource1",
'slug': 'r1',
'source_language': 'el',
'i18n_type': 'PO',
'content': content,
}),
Expand All @@ -469,7 +368,6 @@ def test_post_errors(self):
data=simplejson.dumps({
'name': "resource1",
'slug': 'r1',
'source_language': 'el',
'i18n_type': 'PO',
'content': content,
}),
Expand All @@ -481,7 +379,6 @@ def test_post_errors(self):
data=simplejson.dumps({
'name': "resource2",
'slug': 'r2',
'source_language': 'el',
'i18n_type': 'PO',
}),
content_type='application/json'
Expand Down Expand Up @@ -837,7 +734,6 @@ def test_rlstats_updated(self):
data=simplejson.dumps({
'name': "resource1",
'slug': 'r1',
'source_language': 'el',
'i18n_type': 'INI',
'content': content,
}),
Expand Down Expand Up @@ -891,7 +787,6 @@ def test_unicode_resource_name(self):
data=simplejson.dumps({
'name': "rα",
'slug': 'r1',
'source_language': 'el',
'i18n_type': 'PO',
'content': content,
}),
Expand All @@ -916,7 +811,7 @@ def _create_project(self):
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'
Expand All @@ -932,7 +827,6 @@ def _create_resource(self):
data=simplejson.dumps({
'name': "resource1",
'slug': 'r1',
'source_language': 'el',
'i18n_type': 'PO',
'content': content,
}),
Expand Down Expand Up @@ -1034,7 +928,7 @@ def _create_project(self):
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'
Expand All @@ -1046,7 +940,6 @@ def _create_resource(self):
data=simplejson.dumps({
'name': "resource1",
'slug': self.resource_slug,
'source_language': 'el',
'i18n_type': 'INI',
'content': self.content,
}),
Expand Down

0 comments on commit 02672fa

Please sign in to comment.