This looks good. I have couple comments below, but the one on the test case is the only one I feel is important. This is good to land with that change.
> === modified file 'lib/lp/translations/scripts/po_export_queue.py'
> --- lib/lp/translations/scripts/po_export_queue.py 2010-08-20 20:31:18 +0000
> +++ lib/lp/translations/scripts/po_export_queue.py 2011-01-13 18:25:08 +0000
> @@ -250,6 +252,46 @@
> 'request_url': self.request_url,
> }
>
> + def setExportFile(self, exported_file):
> + """Attach an exported file to the result, for upload to the Librarian.
> +
> + After this is set, `upload` will perform the actual upload. The two
> + actions are separated so as to isolate write access to the database.
> +
> + :param exported_file: An `IExportedTranslationFile` containing the
> + exported data.
> + """
> + self.exported_file = exported_file
Given how very little this method is doing, I'm not sure it needs to be a separate method. It's not hurting anything to have it this way, but seems slightly unnecesary.
Jeroen--
This looks good. I have couple comments below, but the one on the test case is the only one I feel is important. This is good to land with that change.
> === modified file 'lib/lp/ translations/ scripts/ po_export_ queue.py' translations/ scripts/ po_export_ queue.py 2010-08-20 20:31:18 +0000 translations/ scripts/ po_export_ queue.py 2011-01-13 18:25:08 +0000 lationFile` containing the
> --- lib/lp/
> +++ lib/lp/
> @@ -250,6 +252,46 @@
> 'request_url': self.request_url,
> }
>
> + def setExportFile(self, exported_file):
> + """Attach an exported file to the result, for upload to the Librarian.
> +
> + After this is set, `upload` will perform the actual upload. The two
> + actions are separated so as to isolate write access to the database.
> +
> + :param exported_file: An `IExportedTrans
> + exported data.
> + """
> + self.exported_file = exported_file
Given how very little this method is doing, I'm not sure it needs to be a separate method. It's not hurting anything to have it this way, but seems slightly unnecesary.
> === added file 'lib/lp/ translations/ tests/test_ exportresult. py' translations/ tests/test_ exportresult. py 1970-01-01 00:00:00 +0000 translations/ tests/test_ exportresult. py 2011-01-13 18:25:08 +0000 librarian. testing. fake import FakeLibrarian testing. layers import ZopelessDatabas eLayer log.logger import DevNullLogger .scripts. po_export_ queue import ExportResult nslationFile: lationFile` for testing.""" splitext( path) read(*args, **kwargs) t(TestCaseWithF actory) : eLayer t(self) : makePOFile( )] makePerson( ) requester, request, logger) nslationFile( self): getUniqueString () getUniqueString () nslationFile( filename, content, mime_type) exported_ file(self) : (FakeLibrarian( )) edTranslationFi le() Result( ) result. setExportFile( export) result. upload( ) qual(None, export_result.url)
> --- lib/lp/
> +++ lib/lp/
> @@ -0,0 +1,67 @@
> +# Copyright 2010 Canonical Ltd. This software is licensed under the
> +# GNU Affero General Public License version 3 (see the file LICENSE).
> +
> +"""Tests for `ExportResult`."""
> +
> +__metaclass__ = type
> +
> +import hashlib
> +import os.path
> +from StringIO import StringIO
> +
> +from canonical.
> +from canonical.
> +from lp.services.
> +from lp.testing import TestCaseWithFactory
> +from lp.translations
> +
> +
> +class FakeExportedTra
> + """Fake `IExportedTrans
> +
> + def __init__(self, path, content, content_type):
> + self.path = path
> + base, ext = os.path.
> + self.file_extension = ext
> + self.size = len(content)
> + self.content = content
> + self.file = StringIO(content)
> + self.content_type = content_type
> +
> + def read(self, *args, **kwargs):
> + return self.file.
> +
> +
> +class TestExportResul
> +
> + layer = ZopelessDatabas
> +
> + def makeExportResul
> + request = [self.factory.
> + requester = self.factory.
> + logger = DevNullLogger()
> + return ExportResult(
> +
> + def makeExportedTra
> + filename = self.factory.
> + content = self.factory.
> + mime_type = "text/plain"
> + return FakeExportedTra
> +
> + def test_upload_
> + librarian = self.useFixture
> + export = self.makeExport
> + export_result = self.makeExport
> + export_
> + export_
> +
> + self.assertNotE
Asserting equalilty or inequality on None feels odd to me. self.assertIsNo t(None, export_result.url) would be better.
> + sha1 = hashlib. sha1(export. content) .hexdigest( ) l(sha1, librarian. aliases. values( )[0].content. sha1) findBySHA1( sha1) l(export. path, alias.filename) without_ exported_ file_does_ nothing( self): Result( ) result. upload( )
> + self.assertEqua
> + alias = librarian.
> + self.assertEqua
> +
> + def test_upload_
> + export_result = self.makeExport
> + export_
> + self.assertIs(None, export_result.url)