Example #1
0
 def setUpClass(cls):
     logging.debug('Clearing the db...')
     Container.objects.all().delete()
     logging.debug('Creating user...')
     cls.user = User.objects.get_or_create(username='******')[0]
     logging.debug('Adding to the DB two bundles...')
     cls.ids = [Container.create('search_test_1', examples.bundles1(), cls.user, False).id,
                Container.create('search_test_1_other', examples.bundles2(), cls.user, False).id]
Example #2
0
 def testFileSubmit(self):
     client = Client()
     bundle = examples.bundles2()
     content = bundle.JSONEncoder().encode(bundle)
     file_tmp = open(self.path, 'w+')
     file_tmp.write(content)
     file_tmp.close()
     file_tmp = open(self.path)
     data="""{"rec_id": "#mockup","content": """+bundle.JSONEncoder().encode(bundle)+'}'
     logging.debug('Executing POST method with the submission attached...')
     response = client.post('/api/v0/bundle/',data={'data' : data, 'submission': file_tmp},
                                 **{'HTTP_AUTHORIZATION': self.auth})
     file_tmp.close()
     self.assertEqual(response.status_code, 201)
     bundle = Container.objects.get(id=json.JSONDecoder().decode(response.content)['id'])
     file_tmp = open(bundle.submission.content.path)
     self.assertEqual(content, file_tmp.read())
     file_tmp.close()
     os.remove(bundle.submission.content.path)