def test_articles_offset_exceeded_gt(self): from ratchet.views import articles, general_post post_data = {'code': 'S0104-77602014000100002', 'page': 'html', 'type': 'article', 'access_date': '2014-12-25'} request = testing.DummyRequest(post=post_data, db=self.collection) try: general_post(request) except: pass post_data = {'code': 'S0100-07602014000100002', 'page': 'abstract', 'type': 'article', 'access_date': '2014-12-25'} request = testing.DummyRequest(post=post_data, db=self.collection) try: general_post(request) except: pass request = testing.DummyRequest(params={'offset': 3}, db=self.collection) with self.assertRaises(httpexceptions.HTTPBadRequest): response = articles(request)
def test_articles(self): from ratchet.views import articles, general_post post_data = {'code': 'S0104-77602014000100002', 'page': 'html', 'type': 'article', 'access_date': '2014-12-25'} request = testing.DummyRequest(post=post_data, db=self.collection) try: general_post(request) except: pass post_data = {'code': 'S0100-07602014000100002', 'page': 'abstract', 'type': 'article', 'access_date': '2014-12-25'} request = testing.DummyRequest(post=post_data, db=self.collection) try: general_post(request) except: pass request = testing.DummyRequest(db=self.collection) response = articles(request) self.assertEqual(len(response['objects']), 2)
def test_journals_offset_exceeded_gt(self): from ratchet.views import journals, general_post post_data = {'code': '0104-7760', 'page': 'journal', 'type': 'journal', 'access_date': '2014-12-25'} request = testing.DummyRequest(post=post_data, db=self.collection) try: general_post(request) except: pass post_data = {'code': '0100-0760', 'page': 'journal', 'type': 'journal', 'access_date': '2014-12-25'} request = testing.DummyRequest(post=post_data, db=self.collection) try: general_post(request) except: pass request = testing.DummyRequest(params={'offset': 3}, db=self.collection) with self.assertRaises(httpexceptions.HTTPBadRequest): response = journals(request)
def test_journals(self): from ratchet.views import journals, general_post post_data = {'code': '0104-7760', 'page': 'journal', 'type': 'journal', 'access_date': '2014-12-25'} request = testing.DummyRequest(post=post_data, db=self.collection) try: general_post(request) except: pass post_data = {'code': '0100-0760', 'page': 'journal', 'type': 'journal', 'access_date': '2014-12-25'} request = testing.DummyRequest(post=post_data, db=self.collection) try: general_post(request) except: pass request = testing.DummyRequest(db=self.collection) response = journals(request) self.assertEqual(len(response['objects']), 2)
def test_general_post_invalid_type_doc(self): from ratchet.views import general_post post_data = {'code': 'scl', 'page': 'journal', 'type': 'xxxx', 'access_date': '2014-12-25'} request = testing.DummyRequest(post=post_data, db=self.collection) with self.assertRaises(httpexceptions.HTTPBadRequest): general_post(request)
def test_general_post_unauthorized(self): from ratchet.views import general_post post_data = {'code': 'scl', 'page': 'journal', 'access_date': '2014-12-25', 'admintoken': 'invalid'} request = testing.DummyRequest(post=post_data, db=self.collection) with self.assertRaises(httpexceptions.HTTPUnauthorized): general_post(request)
def test_general_post(self): from ratchet.views import general_post post_data = {'code': 'scl', 'page': 'journal', 'access_date': '2014-12-25'} request = testing.DummyRequest(post=post_data, db=self.collection) with self.assertRaises(httpexceptions.HTTPCreated): general_post(request) self.assertEqual( self.collection.find_one()['journal']['y2014']['m12']['d25'], 1 )
def test_journal(self): from ratchet.views import journal, general_post post_data = {'code': '0104-7760', 'page': 'journal', 'type': 'journal', 'access_date': '2014-12-25'} request = testing.DummyRequest(post=post_data, db=self.collection) try: general_post(request) except: pass request = testing.DummyRequest(db=self.collection) request.matchdict.update(dict(code='0104-7760')) response = journal(request) self.assertEqual(response['code'], '0104-7760') self.assertEqual(response['total'], 1)
def test_article(self): from ratchet.views import article, general_post post_data = {'code': 'S0104-77602014000100002', 'page': 'abstract', 'type': 'article', 'access_date': '2014-12-25'} request = testing.DummyRequest(post=post_data, db=self.collection) try: general_post(request) except: pass request = testing.DummyRequest(db=self.collection) request.matchdict.update(dict(code='S0104-77602014000100002')) response = article(request) self.assertEqual(response['code'], 'S0104-77602014000100002') self.assertEqual(response['total'], 1)
def test_general_post_current_datetime(self): from ratchet.views import general_post post_data = {'code': 'scl', 'page': 'journal'} request = testing.DummyRequest(post=post_data, db=self.collection) try: general_post(request) except: pass day = 'd%02d' % datetime.date.today().day month = 'm%02d' % datetime.date.today().month year = 'y%02d' % datetime.date.today().year self.assertEqual( self.collection.find_one()['journal'][year][month][day], 1 )