Пример #1
0
    def test_can_get_political_office_info(self):
        PoliticalOfficeFactory.create(name='Deputado Estadual')

        response = yield self.anonymous_fetch(
            '/political-offices/deputado-estadual/',
            method='GET'
        )
        expect(response.code).to_equal(200)
        political_office = loads(response.body)
        expect(political_office).to_length(2)
        expect(political_office.get('name')).to_equal('Deputado Estadual')
        expect(political_office.get('slug')).to_equal('deputado-estadual')
    def test_can_add_mandate(self):
        political_office = PoliticalOfficeFactory.create()
        legislator = LegislatorFactory.create()

        now = datetime.utcnow()
        date_start = date_to_timestamp(now.date())
        date_end = date_to_timestamp((now + timedelta(days=10)).date())

        response = yield self.anonymous_fetch(
            '/mandates/',
            method='POST',
            body=dumps({
                'date_start': date_start,
                'date_end': date_end,
                'political_office_id': political_office.id,
                'legislator_id': legislator.id,
            })
        )
        expect(response.code).to_equal(200)
        mandate = loads(response.body)
        expect(mandate.get('date_start')).to_equal(date_start)
        expect(mandate.get('date_end')).to_equal(date_end)
        expect(mandate.get('political_office')).to_equal(
            political_office.to_dict()
        )
        expect(mandate.get('legislator')).to_equal(legislator.to_dict())
    def test_can_add_mandate(self, logging_mock):
        political_office = PoliticalOfficeFactory.create()
        legislator = LegislatorFactory.create()

        now = datetime.utcnow()
        d1 = now.date()
        date_start = date_to_timestamp(d1)
        d2 = (now + timedelta(days=10)).date()
        date_end = date_to_timestamp(d2)

        data = {
            'legislator_id': legislator.id,
            'political_office_id': political_office.id,
            'date_start': date_start,
            'date_end': date_end,
        }
        mandate = Mandate.add_mandate(self.db, data)

        expect(mandate.legislator).to_equal(legislator)
        expect(mandate.political_office).to_equal(political_office)
        expect(mandate.date_start).to_equal(d1)
        expect(mandate.date_end).to_equal(d2)
        expect(logging_mock.mock_calls).to_include(
            call.debug('Added mandate: "%s"', str(mandate))
        )
Пример #4
0
    def test_can_convert_to_dict(self):
        political_office = PoliticalOfficeFactory.create()
        political_office_dict = political_office.to_dict()

        expect(political_office_dict.keys()).to_length(2)
        expect(political_office_dict.keys()).to_be_like(['name', 'slug'])
        expect(political_office_dict['name']).to_equal(political_office.name)
        expect(political_office_dict['slug']).to_equal(political_office.slug)
Пример #5
0
    def test_can_create_political_office(self):
        political_office = PoliticalOfficeFactory.create(
            name='Deputado Federal',
        )

        expect(political_office.id).not_to_be_null()
        expect(political_office.name).to_equal('Deputado Federal')
        expect(political_office.slug).to_equal('deputado-federal')
Пример #6
0
    def test_can_get_all_political_offices(self):
        political_offices = []
        for x in range(5):
            political_office = PoliticalOfficeFactory.create()
            political_offices.append(political_office.to_dict())

        response = yield self.anonymous_fetch(
            '/political-offices/',
            method='GET'
        )

        expect(response.code).to_equal(200)
        political_offices_loaded = loads(response.body)
        expect(political_offices_loaded).to_length(5)
        expect(political_offices_loaded).to_be_like(political_offices)
    def test_can_create_mandate(self):
        date_start = datetime.utcnow().date()
        date_end = (datetime.utcnow() + timedelta(days=10)).date()
        political_office = PoliticalOfficeFactory.create()
        legislator = LegislatorFactory.create()

        mandate = MandateFactory.create(
            legislator=legislator,
            political_office=political_office,
            date_start=date_start,
            date_end=date_end
        )

        expect(mandate.id).not_to_be_null()
        expect(mandate.date_start).to_equal(date_start)
        expect(mandate.date_end).to_equal(date_end)
        expect(mandate.political_office).to_equal(political_office)
    def test_cannot_add_mandate_twice(self):
        date_start = datetime.utcnow().date()
        date_end = (datetime.utcnow() + timedelta(days=10)).date()
        political_office = PoliticalOfficeFactory.create()
        legislator = LegislatorFactory.create()

        MandateFactory.create(
            legislator=legislator,
            political_office=political_office,
            date_start=date_start,
            date_end=date_end
        )

        with expect.error_to_happen(IntegrityError):
            MandateFactory.create(
                legislator=legislator,
                political_office=political_office,
                date_start=date_start,
                date_end=date_end
            )
    def test_cannot_add_mandate_twice(self):
        political_office = PoliticalOfficeFactory.create()
        legislator = LegislatorFactory.create()

        now = datetime.utcnow()
        date_start = date_to_timestamp(now.date())
        date_end = date_to_timestamp((now + timedelta(days=10)).date())

        yield self.anonymous_fetch(
            '/mandates/',
            method='POST',
            body=dumps({
                'date_start': date_start,
                'date_end': date_end,
                'political_office_id': political_office.id,
                'legislator_id': legislator.id,
            })
        )

        try:
            yield self.anonymous_fetch(
                '/mandates/',
                method='POST',
                body=dumps({
                    'date_start': date_start,
                    'date_end': date_end,
                    'political_office_id': political_office.id,
                    'legislator_id': legislator.id,
                })
            )
        except HTTPError as e:
            expect(e).not_to_be_null()
            expect(e.code).to_equal(409)
            expect(e.response.reason).to_be_like('Mandate already exists')
            expect(loads(e.response.body)).to_equal({
                'message': 'Mandate already exists'
            })
Пример #10
0
    def test_cannot_add_mandate_without_date_end(self):
        political_office = PoliticalOfficeFactory.create()
        legislator = LegislatorFactory.create()

        now = datetime.utcnow()
        date_start = date_to_timestamp(now.date())

        try:
            yield self.anonymous_fetch(
                '/mandates/',
                method='POST',
                body=dumps({
                    'date_start': date_start,
                    'political_office_id': political_office.id,
                    'legislator_id': legislator.id,
                })
            )
        except HTTPError as e:
            expect(e).not_to_be_null()
            expect(e.code).to_equal(422)
            expect(e.response.reason).to_be_like('Invalid Mandate')
            expect(loads(e.response.body)).to_equal({
                'message': 'Invalid Mandate'
            })
Пример #11
0
    def test_cannot_add_political_office_twice(self):
        PoliticalOfficeFactory.create(name='Deputado Federal')

        with expect.error_to_happen(IntegrityError):
            PoliticalOfficeFactory.create(name='Deputado Federal')