# Path: montanha/tests/fixtures.py
# class InstitutionFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = Institution
# 
#     name = factory.Sequence(lambda t: 'name-{0}'.format(t))
#     siglum = factory.Sequence(lambda t: 'siglum-{0}'.format(t))
# 
# class LegislatureFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = Legislature
# 
#     institution = factory.SubFactory(InstitutionFactory)
#     original_id = factory.Sequence(lambda t: 'id-{0}'.format(t))
#     date_start = factory.LazyFunction(datetime.now().date)
#     date_end = factory.LazyFunction(datetime.now().date)
# 
# class CollectionRunFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = CollectionRun
# 
#     date = factory.LazyFunction(datetime.now().date)
#     legislature = factory.SubFactory(LegislatureFactory)
#     committed = False


from datetime import datetime, timedelta
from django.core.management.base import CommandError
from django.core.management import call_command
from django.test import TestCase
from mock import patch, call
from montanha.tests.fixtures import (
    InstitutionFactory, LegislatureFactory, CollectionRunFactory
)
            call_command('collect')

    @patch('montanha.management.commands.collect.Command.collection_runs')
    @patch('montanha.management.commands.collect.call_command')
    @patch('montanha.management.commands.collectors.almg.ALMG')
    def test_with_instituiton_almg(
            self, mock_institution, mock_call_command, collection_runs_mock):

        self._create_instituiton('ALMG')

        collection_run = CollectionRunFactory.create()
        collection_runs_mock.__iter__.return_value = [collection_run]

        call_command('collect', 'almg')

        self.assertIn(call().update_legislators(), mock_institution.mock_calls)
        self.assertIn(call().update_data(), mock_institution.mock_calls)
        self.assertIn(call().update_legislators_data(), mock_institution.mock_calls)
        self.assertEqual(
            mock_call_command.mock_calls, [call('consolidate', 'almg')]
        )

    @patch('montanha.management.commands.collect.Command.collection_runs')
    @patch('montanha.management.commands.collect.call_command')
    @patch('montanha.management.commands.collectors.algo.ALGO')
    def test_with_instituiton_algo(
            self, mock_institution, mock_call_command, collection_runs_mock):

        self._create_instituiton('ALGO')


# Path: montanha/tests/fixtures.py
# class InstitutionFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = Institution
# 
#     name = factory.Sequence(lambda t: 'name-{0}'.format(t))
#     siglum = factory.Sequence(lambda t: 'siglum-{0}'.format(t))
# 
# class LegislatureFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = Legislature
# 
#     institution = factory.SubFactory(InstitutionFactory)
#     original_id = factory.Sequence(lambda t: 'id-{0}'.format(t))
#     date_start = factory.LazyFunction(datetime.now().date)
#     date_end = factory.LazyFunction(datetime.now().date)
# 
# class CollectionRunFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = CollectionRun
# 
#     date = factory.LazyFunction(datetime.now().date)
#     legislature = factory.SubFactory(LegislatureFactory)
#     committed = False


# Path: montanha/management/commands/tests/test_collect.py
from datetime import datetime, timedelta
from django.core.management.base import CommandError
from django.core.management import call_command
from django.test import TestCase
from mock import patch, call
from montanha.tests.fixtures import (
    InstitutionFactory, LegislatureFactory, CollectionRunFactory
)

            call_command('collect')

    @patch('montanha.management.commands.collect.Command.collection_runs')
    @patch('montanha.management.commands.collect.call_command')
    @patch('montanha.management.commands.collectors.almg.ALMG')
    def test_with_instituiton_almg(
            self, mock_institution, mock_call_command, collection_runs_mock):

        self._create_instituiton('ALMG')

        collection_run = CollectionRunFactory.create()
        collection_runs_mock.__iter__.return_value = [collection_run]

        call_command('collect', 'almg')

        self.assertIn(call().update_legislators(), mock_institution.mock_calls)
        self.assertIn(call().update_data(), mock_institution.mock_calls)
        self.assertIn(call().update_legislators_data(), mock_institution.mock_calls)
        self.assertEqual(
            mock_call_command.mock_calls, [call('consolidate', 'almg')]
        )

    @patch('montanha.management.commands.collect.Command.collection_runs')
    @patch('montanha.management.commands.collect.call_command')
    @patch('montanha.management.commands.collectors.algo.ALGO')
    def test_with_instituiton_algo(
            self, mock_institution, mock_call_command, collection_runs_mock):

        self._create_instituiton('ALGO')


        collection_run = CollectionRunFactory.create()