
import os
from zipfile import ZipFile

from twisted.internet.defer import inlineCallbacks

from globaleaks.db.datainit import load_appdata
from globaleaks.settings import GLSettings
from globaleaks.tests import helpers
from globaleaks.utils.zipstream import ZipStream, get_compression_opts

class TestCollection(helpers.TestGL):
    files = []

    @inlineCallbacks
    def setUp(self):
        yield helpers.TestGL.setUp(self)
        self.test_collection_file = os.path.join(GLSettings.working_path, 'test.collection')

        for k in self.internationalized_text:
            self.files.append({'name': self.internationalized_text[k].encode('utf8'), 'buf': self.internationalized_text[k].encode('utf-8')})


    def test_collection(self):
        for compression in ['zipstored', 'zipdeflated']:
            with open(self.test_collection_file, 'w') as f:
                opts = get_compression_opts(compression)
                for data in ZipStream(self.files, opts['compression_type']):
                    f.write(data)

            with ZipFile(self.test_collection_file, 'r') as f:
                self.assertIsNone(f.testzip())


import os
from zipfile import ZipFile

from twisted.internet.defer import inlineCallbacks

from globaleaks.db.datainit import load_appdata
from globaleaks.settings import GLSettings
from globaleaks.tests import helpers
from globaleaks.utils.zipstream import ZipStream

class TestCollection(helpers.TestGL):
    files = []

    @inlineCallbacks
    def setUp(self):
        yield helpers.TestGL.setUp(self)
        self.test_collection_file = os.path.join(GLSettings.working_path, 'test.collection')

        for k in self.internationalized_text:
            self.files.append({'name': self.internationalized_text[k].encode('utf8'), 'buf': self.internationalized_text[k].encode('utf-8')})


    def test_collection(self):
        with open(self.test_collection_file, 'w') as f:
            for data in ZipStream(self.files):
                f.write(data)

        with ZipFile(self.test_collection_file, 'r') as f:
            self.assertIsNone(f.testzip())

Simplify zipstream following the simplification of the zip routines implemented
Simplify zipstream following the simplification of the zip routines implemented

  
  import os
  from zipfile import ZipFile
  
  from twisted.internet.defer import inlineCallbacks
  
  from globaleaks.db.datainit import load_appdata
  from globaleaks.settings import GLSettings
  from globaleaks.tests import helpers
- from globaleaks.utils.zipstream import ZipStream, get_compression_opts
+ from globaleaks.utils.zipstream import ZipStream
  
  class TestCollection(helpers.TestGL):
      files = []
  
      @inlineCallbacks
      def setUp(self):
          yield helpers.TestGL.setUp(self)
          self.test_collection_file = os.path.join(GLSettings.working_path, 'test.collection')
  
          for k in self.internationalized_text:
              self.files.append({'name': self.internationalized_text[k].encode('utf8'), 'buf': self.internationalized_text[k].encode('utf-8')})
  
  
      def test_collection(self):
-         for compression in ['zipstored', 'zipdeflated']:
-             with open(self.test_collection_file, 'w') as f:
+         with open(self.test_collection_file, 'w') as f:
-                 opts = get_compression_opts(compression)
-                 for data in ZipStream(self.files, opts['compression_type']):
+             for data in ZipStream(self.files):
-                     f.write(data)
+                 f.write(data)
  
-             with ZipFile(self.test_collection_file, 'r') as f:
+         with ZipFile(self.test_collection_file, 'r') as f:
-                 self.assertIsNone(f.testzip())
+             self.assertIsNone(f.testzip())
  
Simplify zipstream following the simplification of the zip routines implemented
## Code Before:

import os
from zipfile import ZipFile

from twisted.internet.defer import inlineCallbacks

from globaleaks.db.datainit import load_appdata
from globaleaks.settings import GLSettings
from globaleaks.tests import helpers
from globaleaks.utils.zipstream import ZipStream, get_compression_opts

class TestCollection(helpers.TestGL):
    files = []

    @inlineCallbacks
    def setUp(self):
        yield helpers.TestGL.setUp(self)
        self.test_collection_file = os.path.join(GLSettings.working_path, 'test.collection')

        for k in self.internationalized_text:
            self.files.append({'name': self.internationalized_text[k].encode('utf8'), 'buf': self.internationalized_text[k].encode('utf-8')})


    def test_collection(self):
        for compression in ['zipstored', 'zipdeflated']:
            with open(self.test_collection_file, 'w') as f:
                opts = get_compression_opts(compression)
                for data in ZipStream(self.files, opts['compression_type']):
                    f.write(data)

            with ZipFile(self.test_collection_file, 'r') as f:
                self.assertIsNone(f.testzip())

## Instruction:
Simplify zipstream following the simplification of the zip routines implemented
## Code After:

import os
from zipfile import ZipFile

from twisted.internet.defer import inlineCallbacks

from globaleaks.db.datainit import load_appdata
from globaleaks.settings import GLSettings
from globaleaks.tests import helpers
from globaleaks.utils.zipstream import ZipStream

class TestCollection(helpers.TestGL):
    files = []

    @inlineCallbacks
    def setUp(self):
        yield helpers.TestGL.setUp(self)
        self.test_collection_file = os.path.join(GLSettings.working_path, 'test.collection')

        for k in self.internationalized_text:
            self.files.append({'name': self.internationalized_text[k].encode('utf8'), 'buf': self.internationalized_text[k].encode('utf-8')})


    def test_collection(self):
        with open(self.test_collection_file, 'w') as f:
            for data in ZipStream(self.files):
                f.write(data)

        with ZipFile(self.test_collection_file, 'r') as f:
            self.assertIsNone(f.testzip())
