예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
 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!"))
예제 #4
0
    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'])
예제 #5
0
    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'])
예제 #6
0
 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)
예제 #7
0
    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'))
예제 #8
0
 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)
예제 #9
0
    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())
예제 #10
0
    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'))
예제 #11
0
 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)
예제 #12
0
    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())