Skip to content

Commit

Permalink
Merge pull request #1227 from scieloorg/beta
Browse files Browse the repository at this point in the history
Incorporação de códigos estáveis
  • Loading branch information
gustavofonseca committed Nov 30, 2015
2 parents f8e7443 + aff20a3 commit a0c8225
Show file tree
Hide file tree
Showing 16 changed files with 547 additions and 369 deletions.
35 changes: 0 additions & 35 deletions scielomanager/api/resources_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
Collection,
Issue,
Section,
DataChangeEvent,
RegularPressRelease,
AheadPressRelease,
PressReleaseTranslation,
Expand Down Expand Up @@ -313,40 +312,6 @@ def dehydrate_pub_status_reason(self, bundle):
return bundle.obj.membership_info(col, 'reason')


class DataChangeEventResource(ModelResource):
collection_uri = fields.ForeignKey(CollectionResource, 'collection')
seq = fields.IntegerField(attribute='pk', readonly=True)
object_uri = GenericForeignKeyField({
Journal: JournalResource,
Issue: IssueResource,
}, 'content_object')

class Meta(ApiKeyAuthMeta):
resource_name = 'changes'
queryset = DataChangeEvent.objects.all()
excludes = [
'object_id',
'id',
]
allowed_methods = ['get', ]

def build_filters(self, filters=None):
"""
Custom filter that retrieves data by the collection's name_slug.
"""
if filters is None:
filters = {}

orm_filters = super(DataChangeEventResource, self).build_filters(filters)

if 'since' in filters:
events = DataChangeEvent.objects.filter(
pk__gte=int(filters['since']))
orm_filters['pk__in'] = events

return orm_filters


class PressReleaseTranslationResource(ModelResource):
language = fields.CharField(readonly=True)

Expand Down
36 changes: 0 additions & 36 deletions scielomanager/api/resources_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,42 +304,6 @@ def dehydrate_subject_categories(self, bundle):
for subject_category in bundle.obj.subject_categories.all()]


class DataChangeEventResource(ModelResource):
collection_uri = fields.ForeignKey(CollectionResource, 'collection')
seq = fields.IntegerField(attribute='pk', readonly=True)
object_uri = GenericForeignKeyField({
models.Journal: JournalResource,
models.Issue: IssueResource,
}, 'content_object')

class Meta(ApiKeyAuthMeta):
resource_name = 'changes'
queryset = models.DataChangeEvent.objects.all()
excludes = [
'object_id',
'id',
]
allowed_methods = ['get', ]

def build_filters(self, filters=None):
"""
Custom filter that retrieves data by since.
"""
if filters is None:
filters = {}

query_filters = {}

orm_filters = super(DataChangeEventResource, self).build_filters(filters)

if 'since' in filters:
query_filters['pk__gte'] = int(filters['since'])

orm_filters['pk__in'] = models.DataChangeEvent.objects.filter(**query_filters)

return orm_filters


class PressReleaseTranslationResource(ModelResource):
language = fields.CharField(readonly=True)

Expand Down
56 changes: 0 additions & 56 deletions scielomanager/api/tests_resources_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,62 +798,6 @@ def test_access_denied_for_unauthenticated_users(self):
self.assertEqual(response.status_code, 401)


class ChangesRestAPITest(WebTest):

def setUp(self):
self.user = auth.UserF(is_active=True)
self.extra_environ = _make_auth_environ(self.user.username,
self.user.api_key.key)

def test_changes_index(self):
event = modelfactories.DataChangeEventFactory.create()
response = self.app.get('/api/v1/changes/',
extra_environ=self.extra_environ)

self.assertEqual(response.status_code, 200)
self.assertTrue('objects' in response.content)

def test_since_filter(self):
seqs = []
for i in range(5):
event = modelfactories.DataChangeEventFactory.create()
seqs.append(event.pk)

response = self.app.get('/api/v1/changes/?since=%s' % seqs[1],
extra_environ=self.extra_environ)

self.assertEqual(response.status_code, 200)
self.assertTrue('objects' in response.content)
self.assertEqual(len(json.loads(response.content)['objects']), 4)

def test_post_data(self):
event = modelfactories.DataChangeEventFactory.create()
response = self.app.post('/api/v1/changes/',
extra_environ=self.extra_environ, status=405)

self.assertEqual(response.status_code, 405)

def test_put_data(self):
event = modelfactories.DataChangeEventFactory.create()
response = self.app.put('/api/v1/changes/',
extra_environ=self.extra_environ, status=405)

self.assertEqual(response.status_code, 405)

def test_del_data(self):
event = modelfactories.DataChangeEventFactory.create()
response = self.app.delete('/api/v1/changes/',
extra_environ=self.extra_environ, status=405)

self.assertEqual(response.status_code, 405)

def test_access_denied_for_unauthenticated_users(self):
event = modelfactories.DataChangeEventFactory.create()
response = self.app.get('/api/v1/changes/', status=401)

self.assertEqual(response.status_code, 401)


class PressReleaseRestAPITest(WebTest):

def setUp(self):
Expand Down
56 changes: 0 additions & 56 deletions scielomanager/api/tests_resources_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,62 +760,6 @@ def test_number_of_itens_when_change_filters(self):
self.assertEqual(len(content['objects']), 0)


class ChangesRestAPITest(WebTest):

def setUp(self):
self.user = auth.UserF(is_active=True)
self.extra_environ = _make_auth_environ(self.user.username,
self.user.api_key.key)

def test_changes_index(self):
modelfactories.DataChangeEventFactory.create()
response = self.app.get('/api/v2/changes/',
extra_environ=self.extra_environ)

self.assertEqual(response.status_code, 200)
self.assertTrue('objects' in response.content)

def test_since_filter(self):
seqs = []
for i in range(5):
event = modelfactories.DataChangeEventFactory.create()
seqs.append(event.pk)

response = self.app.get('/api/v2/changes/?since=%s' % seqs[1],
extra_environ=self.extra_environ)

self.assertEqual(response.status_code, 200)
self.assertTrue('objects' in response.content)
self.assertEqual(len(json.loads(response.content)['objects']), 4)

def test_post_data(self):
modelfactories.DataChangeEventFactory.create()
response = self.app.post('/api/v2/changes/',
extra_environ=self.extra_environ, status=405)

self.assertEqual(response.status_code, 405)

def test_put_data(self):
modelfactories.DataChangeEventFactory.create()
response = self.app.put('/api/v2/changes/',
extra_environ=self.extra_environ, status=405)

self.assertEqual(response.status_code, 405)

def test_del_data(self):
modelfactories.DataChangeEventFactory.create()
response = self.app.delete('/api/v2/changes/',
extra_environ=self.extra_environ, status=405)

self.assertEqual(response.status_code, 405)

def test_access_denied_for_unauthenticated_users(self):
modelfactories.DataChangeEventFactory.create()
response = self.app.get('/api/v2/changes/', status=401)

self.assertEqual(response.status_code, 401)


class PressReleaseRestAPITest(WebTest):

def setUp(self):
Expand Down
Loading

0 comments on commit a0c8225

Please sign in to comment.