def setUp(self): # set up project settings.DEBUG = True # settings.OPENHUMANS_APP_BASE_URL = "http://127.0.0.1" call_command('init_proj_config') project_config = ProjectConfiguration.objects.get(id=1) project_config.oh_client_id = "6yNYmUlXN1wLwQFQR0lnUohR1KMeVt" project_config.oh_client_secret = "Y2xpZW50aWQ6Y2xpZW50c2VjcmV0" project_config.save() self.oh_file = FileMetaData() self.oh_file.name = "test" self.oh_file.description = 'a test file' self.oh_file.tags = json.dumps("my,tag,list") self.oh_file.save() # set up user data = {"access_token": 'foo', "refresh_token": 'bar', "expires_in": 36000} self.oh_member = OpenHumansMember.create(oh_id='1234567890abcdef', data=data) self.oh_member.save() self.user = self.oh_member.user self.user.set_password('foobar') self.user.save()
class UploadTestCase(TestCase): def setUp(self): # set up project settings.DEBUG = True # settings.OPENHUMANS_APP_BASE_URL = "http://127.0.0.1" call_command('init_proj_config') project_config = ProjectConfiguration.objects.get(id=1) project_config.oh_client_id = "6yNYmUlXN1wLwQFQR0lnUohR1KMeVt" project_config.oh_client_secret = "Y2xpZW50aWQ6Y2xpZW50c2VjcmV0" project_config.save() self.oh_file = FileMetaData() self.oh_file.name = "test" self.oh_file.description = 'a test file' self.oh_file.tags = json.dumps("my,tag,list") self.oh_file.save() # set up user data = {"access_token": 'foo', "refresh_token": 'bar', "expires_in": 36000} self.oh_member = OpenHumansMember.create(oh_id='1234567890abcdef', data=data) self.oh_member.save() self.user = self.oh_member.user self.user.set_password('foobar') self.user.save() def test_get_upload_old(self): c = Client() c.login(username=self.user.username, password='******') response = c.get("/upload_simple/") self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'main/upload_old.html') def test_upload_old_logged_out(self): c = Client() response = c.get("/upload_simple/") self.assertEqual(response.status_code, 302) self.assertRedirects(response, '/') @vcr.use_cassette('main/tests/fixtures/upload_file.yaml', record_mode='none') def test_post_upload_old(self): c = Client() c.login(username=self.user.username, password='******') test_file = BytesIO(b'mybinarydata') test_file.name = 'myimage.jpg' response = c.post("/complete/", {'file_1': test_file, 'file_desc_1': 'foo', 'tags_1': 'bar,baz'}, follow=True) self.assertRedirects(response, "/overview", status_code=302) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'main/overview.html')