def test_save_file_with_existing_si_and_correct_we_should_return_true(self):
        si = ''.join(random.sample(string.letters+string.digits, 12))
        we = ''.join(random.sample(string.letters+string.digits, 12))

        result = save_file(si, StringIO.StringIO('NEW_FILE_WITH_WE'), 20, we)
        updated = save_file(si, StringIO.StringIO('UPDATED_FILE'), 20, we)

        fp = open(os.path.join(FILE_STORE, si), 'r')
        content = fp.read()
        fp.close()

        self.assertTrue(result)
        self.assertTrue(updated)
        self.assertEqual(content, 'UPDATED_FILE')
Esempio n. 2
0
    def test_save_file_with_existing_si_and_correct_we_should_return_true(
            self):
        si = ''.join(random.sample(string.letters + string.digits, 12))
        we = ''.join(random.sample(string.letters + string.digits, 12))

        result = save_file(si, StringIO.StringIO('NEW_FILE_WITH_WE'), 20, we)
        updated = save_file(si, StringIO.StringIO('UPDATED_FILE'), 20, we)

        fp = open(os.path.join(FILE_STORE, si), 'r')
        content = fp.read()
        fp.close()

        self.assertTrue(result)
        self.assertTrue(updated)
        self.assertEqual(content, 'UPDATED_FILE')
Esempio n. 3
0
    def test_save_new_file_should_return_true(self):
        si = ''.join(random.sample(string.letters + string.digits, 12))
        return_code = save_file(si, StringIO.StringIO('TESTING'), 20)

        fp = open(os.path.join(FILE_STORE, si), 'r')
        result = fp.read()
        fp.close()

        self.assertTrue(return_code)
        self.assertEqual(result, 'TESTING')
    def test_save_new_file_should_return_true(self):
        si = ''.join(random.sample(string.letters+string.digits, 12))
        return_code = save_file(si, StringIO.StringIO('TESTING'), 20)

        fp = open(os.path.join(FILE_STORE, si), 'r')
        result = fp.read()
        fp.close()

        self.assertTrue(return_code)
        self.assertEqual(result, 'TESTING')
    def test_save_file_with_existing_si_and_wrong_we_should_raise_exception(self):
        si = ''.join(random.sample(string.letters+string.digits, 12))
        we = ''.join(random.sample(string.letters+string.digits, 12))
        wrong_we = ''.join(random.sample(string.letters+string.digits, 12))

        result = save_file(si, StringIO.StringIO('NEW_FILE_WITH_WE'), 20, we)
        file_obj = StringIO.StringIO('ERROR')
        self.assertRaises(FileSystemException, save_file, si, file_obj, 20,
                          wrong_we)

        fp = open(os.path.join(FILE_STORE, si), 'r')
        content = fp.read()
        fp.close()

        self.assertTrue(result)
        self.assertEqual(content, 'NEW_FILE_WITH_WE')
Esempio n. 6
0
    def test_save_file_with_existing_si_and_wrong_we_should_raise_exception(
            self):
        si = ''.join(random.sample(string.letters + string.digits, 12))
        we = ''.join(random.sample(string.letters + string.digits, 12))
        wrong_we = ''.join(random.sample(string.letters + string.digits, 12))

        result = save_file(si, StringIO.StringIO('NEW_FILE_WITH_WE'), 20, we)
        file_obj = StringIO.StringIO('ERROR')
        self.assertRaises(FileSystemException, save_file, si, file_obj, 20,
                          wrong_we)

        fp = open(os.path.join(FILE_STORE, si), 'r')
        content = fp.read()
        fp.close()

        self.assertTrue(result)
        self.assertEqual(content, 'NEW_FILE_WITH_WE')
Esempio n. 7
0
def put_file(request, storage_index=None, write_enabler=None):
    '''Handles HTTP PUT requests for new or existing files.

    If write_enabler is provided, it is further processed as an mutable
    file/directory.

    '''

    if _clean_input(storage_index) is not None:
        if request.PUT is not None:
            try:
                content_length = request.ENV['CONTENT_LENGTH']
                save_status = save_file(storage_index, request.PUT,
                                        content_length,
                                        _clean_input(write_enabler))

                return Response(status_code=save_status)
            except FileSystemException, e:
                return Response(e.text, status_code=e.code)
Esempio n. 8
0
def put_file(request, storage_index=None, write_enabler=None):
    '''Handles HTTP PUT requests for new or existing files.

    If write_enabler is provided, it is further processed as an mutable
    file/directory.

    '''

    if _clean_input(storage_index) is not None:
        if request.PUT is not None:
            try:
                content_length = request.ENV['CONTENT_LENGTH']
                save_status = save_file(
                    storage_index,
                    request.PUT,
                    content_length,
                    _clean_input(write_enabler)
                    )

                return Response(status_code=save_status)
            except FileSystemException, e:
                return Response(e.text, status_code=e.code)