from __future__ import unicode_literals

import functools

from scrapi.base import XMLHarvester
from scrapi.linter import RawDocument

from .utils import get_leaves
from .utils import TEST_SCHEMA, TEST_NAMESPACES, TEST_XML_DOC


class TestHarvester(XMLHarvester):

    def harvest(self, days_back=1):
        return [RawDocument({
            'doc': str(TEST_XML_DOC),
            'source': 'TEST',
            'filetype': 'XML',
            'docID': "1"
        })] * days_back


class TestTransformer(object):

    def setup_method(self, method):
        self.harvester = TestHarvester("TEST", TEST_SCHEMA, TEST_NAMESPACES)

    def test_process_schema(self):
        assert self.harvester.schema == TEST_SCHEMA
        self.harvester.process_schema()
        assert self.harvester.schema != TEST_SCHEMA

        for (k, v) in get_leaves(self.harvester.schema):
            assert type(v) == functools.partial

    def test_normalize(self):
        results = [
            self.harvester.normalize(record) for record in self.harvester.harvest(days_back=10)
        ]

        for result in results:
            assert result['properties']['title1'] == 'Test'
            assert result['properties']['title2'] == 'test'
            assert result['properties']['title3'] == 'Testtest'

            for (k, v) in get_leaves(result.attributes):
                assert type(v) != functools.partial

@@ -624,294 +624,8 @@
 S)%0A%0A
-    def test_process_schema(self):%0A        assert self.harvester.schema == TEST_SCHEMA%0A        self.harvester.process_schema()%0A        assert self.harvester.schema != TEST_SCHEMA%0A%0A        for (k, v) in get_leaves(self.harvester.schema):%0A            assert type(v) == functools.partial%0A%0A
     

Update tests