From 82f48843b3f723411777938b7e6777760e9463e5 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 24 Oct 2014 12:06:54 -0300 Subject: Card #30 - information for alternatives and attachments are different --- service/test/unit/adapter/soledad_querier_test.py | 54 +++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 service/test/unit/adapter/soledad_querier_test.py (limited to 'service/test/unit/adapter/soledad_querier_test.py') diff --git a/service/test/unit/adapter/soledad_querier_test.py b/service/test/unit/adapter/soledad_querier_test.py new file mode 100644 index 00000000..87ed5512 --- /dev/null +++ b/service/test/unit/adapter/soledad_querier_test.py @@ -0,0 +1,54 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . +import unittest +from pixelated.adapter.soledad_querier import SoledadQuerier +from mockito import mock, when, any +import json +import os + + +class SoledadQuerierTest(unittest.TestCase): + + def test_extract_parts(self): + soledad = mock() + bdoc = mock() + bdoc.content = {'raw': 'esse papo seu ta qualquer coisa'} + when(soledad).get_from_index('by-type-and-payloadhash', 'cnt', any(unicode)).thenReturn([bdoc]) + multipart_attachment_file = os.path.join(os.path.dirname(__file__), '..', 'fixtures', 'multipart_attachment.json') + with open(multipart_attachment_file) as f: + hdoc = json.loads(f.read()) + querier = SoledadQuerier(soledad) + + parts = querier._extract_parts(hdoc) + + self.assertIn('alternatives', parts.keys()) + self.assertIn('attachments', parts.keys()) + self.assertEquals(2, len(parts['alternatives'])) + self.assertEquals(1, len(parts['attachments'])) + + self.check_alternatives(parts) + self.check_attachments(parts) + + def check_alternatives(self, parts): + for alternative in parts['alternatives']: + self.assertIn('headers', alternative) + self.assertIn('content', alternative) + + def check_attachments(self, parts): + for attachment in parts['attachments']: + self.assertIn('headers', attachment) + self.assertIn('ident', attachment) + self.assertIn('name', attachment) -- cgit v1.2.3