def test_post_should_create_model(self): data = { 'field': 'test value', 'file': files.create_inmemory_file('test.txt', content=b'Hello multipart!'), } request = self.factory.post(data=data, format='multipart') response = self.view(request) self.assert_status_equal(response, status.HTTP_201_CREATED)
def test_post_should_create_model(self): data = { 'field': 'test value', 'file': files.create_inmemory_file('test.txt', content=b'Hello multipart!'), } request = self.factory.post(data=data, format='multipart') response = self.view(request) self.assert_status_equal(response, status.HTTP_201_CREATED)
def test_correct_file(self): """ If the file is valid, observations are created. """ contents = "\n".join(self.lines) aavso_file = create_inmemory_file('data.txt', contents.encode('utf-8')) with self.assert_instance_created(Observation, star=self.star, notes='test3'): request = self.factory.post(data={ 'aavso_file': aavso_file, }, user=self.user) request.observer = self.observer response = self.view(request) self.assert_redirect(response) self.assert_message_exists(request, messages.SUCCESS, _("File uploaded successfully!"))
def test_listdir_should_return_proper_paths(self): file_name = '/a/b/test.txt' new_file = files.create_inmemory_file(file_name, b'Avada Kedavra') default_storage.save(file_name, new_file) dirs, files_list = default_storage.listdir('/') sub_dirs, sub_files_list = default_storage.listdir('/a/') sub_sub_dirs, sub_sub_files_list = default_storage.listdir('/a/b/') self.assertEqual(dirs, ['a']) self.assertFalse(files_list) self.assertEqual(sub_dirs, ['b']) self.assertFalse(sub_files_list) self.assertFalse(sub_sub_dirs) self.assertEqual(sub_sub_files_list, ['test.txt'])
def test_listdir_should_return_proper_paths(self): file_name = '/a/b/test.txt' new_file = files.create_inmemory_file(file_name, b'Avada Kedavra') default_storage.save(file_name, new_file) dirs, files_list = default_storage.listdir('/') sub_dirs, sub_files_list = default_storage.listdir('/a/') sub_sub_dirs, sub_sub_files_list = default_storage.listdir('/a/b/') self.assertEqual(dirs, ['a']) self.assertFalse(files_list) self.assertEqual(sub_dirs, ['b']) self.assertFalse(sub_files_list) self.assertFalse(sub_sub_dirs) self.assertEqual(sub_sub_files_list, ['test.txt'])
def test_malformed_file(self): """ Check that a bad magnitude value raises an exception. """ observations_count_before = Observation.objects.count() self.lines[-1] = "%s,2450702.1234,ASDF,na,110,113,070613,test3" % self.star.name contents = "\n".join(self.lines) aavso_file = create_inmemory_file('data.txt', contents.encode('utf-8')) request = self.factory.post(data={ 'aavso_file': aavso_file, }, user=self.user) request.observer = self.observer response = self.view(request) self.assert_redirect(response) self.assert_message_exists(request, messages.SUCCESS, _("File uploaded successfully!")) observations_count_after = Observation.objects.count() self.assertEqual(observations_count_after, observations_count_before)
def test_aaa_just_saving_file(self): default_storage.save('cross.txt', files.create_inmemory_file('aa.txt')) self.assertTrue(default_storage.exists('cross.txt'))
def setUp(self): self.file_name = 'test.txt' self.file = files.create_inmemory_file(self.file_name, b'Avada Kedavra') default_storage.save(self.file_name, self.file)
def test_make_inmemory_file_should_pass(self): file = files.create_inmemory_file('test.txt', b'Avada Kedavra') self.assertEqual(file.name, 'test.txt') self.assertIn(b'Avada Kedavra', file.readlines())
def test_aaa_just_saving_file(self): default_storage.save('cross.txt', files.create_inmemory_file('aa.txt')) self.assertTrue(default_storage.exists('cross.txt'))
def setUp(self): self.file_name = 'test.txt' self.file = files.create_inmemory_file(self.file_name, b'Avada Kedavra') default_storage.save(self.file_name, self.file)
def test_make_inmemory_file_should_pass(self): file = files.create_inmemory_file('test.txt', b'Avada Kedavra') self.assertEqual(file.name, 'test.txt') self.assertIn(b'Avada Kedavra', file.readlines())