Ejemplo n.º 1
0
    def test_cannot_add_mandate_events_twice(self):
        mandate = MandateFactory.create()
        mandate_events_type = MandateEventsTypeFactory.create()
        date = date_to_timestamp(datetime.utcnow().date())

        yield self.anonymous_fetch(
            '/mandate-events/',
            method='POST',
            body=dumps({
                'date': date,
                'mandate_id': mandate.id,
                'mandate_events_type_id': mandate_events_type.id
            })
        )

        try:
            yield self.anonymous_fetch(
                '/mandate-events/',
                method='POST',
                body=dumps({
                    'date': date,
                    'mandate_id': mandate.id,
                    'mandate_events_type_id': mandate_events_type.id
                })
            )
        except HTTPError as e:
            expect(e).not_to_be_null()
            expect(e.code).to_equal(500)
            expect(e.response.reason).to_be_like('Internal Server Error')
    def test_can_get_mandate_events_type_info(self):
        MandateEventsTypeFactory.create(name=u'Assumiu cargo no executivo')

        response = yield self.anonymous_fetch(
            '/mandate-events-types/assumiu-cargo-no-executivo',
            method='GET'
        )
        expect(response.code).to_equal(200)
        mandate_events_type = loads(response.body)
        expect(mandate_events_type).to_length(2)
        expect(mandate_events_type.get('name')).to_equal(
            'Assumiu cargo no executivo'
        )
        expect(mandate_events_type.get('slug')).to_equal(
            'assumiu-cargo-no-executivo'
        )
    def test_can_create_mandate_events_type(self):
        mandate_events_type = MandateEventsTypeFactory.create(
            name=u'Assumiu cargo no executivo'
        )

        expect(mandate_events_type.id).not_to_be_null()
        expect(mandate_events_type.name).to_equal('Assumiu cargo no executivo')
        expect(mandate_events_type.slug).to_equal('assumiu-cargo-no-executivo')
    def test_can_convert_to_dict(self):
        mandate_events_type = MandateEventsTypeFactory.create()
        mandate_events_type_dict = mandate_events_type.to_dict()

        expect(mandate_events_type_dict.keys()).to_length(2)
        expect(mandate_events_type_dict.keys()).to_be_like(['name', 'slug'])
        expect(mandate_events_type_dict['name']).to_equal(
            mandate_events_type.name
        )
        expect(mandate_events_type_dict['slug']).to_equal(
            mandate_events_type.slug
        )
    def test_can_get_all_mandate_events_types(self):
        mandate_events_types = []
        for x in range(5):
            mandate_events_type = MandateEventsTypeFactory.create()
            mandate_events_types.append(mandate_events_type.to_dict())

        response = yield self.anonymous_fetch(
            '/mandate-events-types/',
            method='GET'
        )

        expect(response.code).to_equal(200)
        mandate_events_types_loaded = loads(response.body)
        expect(mandate_events_types_loaded).to_length(5)
        expect(mandate_events_types_loaded).to_be_like(mandate_events_types)
    def test_cannot_add_mandate_events_twice(self):
        date = datetime.utcnow().date()
        mandate_events_type = MandateEventsTypeFactory.create()
        mandate = MandateFactory.create()

        MandateEventsFactory.create(
            mandate_events_type=mandate_events_type,
            date=date,
            mandate=mandate
        )

        with expect.error_to_happen(IntegrityError):
            MandateEventsFactory.create(
                mandate_events_type=mandate_events_type,
                date=date,
                mandate=mandate
            )
    def test_can_create_mandate_events(self):
        date = datetime.utcnow().date()
        mandate_events_type = MandateEventsTypeFactory.create()
        mandate = MandateFactory.create()

        mandate_events = MandateEventsFactory.create(
            date=date,
            mandate_events_type=mandate_events_type,
            mandate=mandate
        )

        expect(mandate_events.id).not_to_be_null()
        expect(mandate_events.date).to_equal(date)
        expect(mandate_events.mandate).to_equal(mandate)
        expect(mandate_events.mandate_events_type).to_equal(
            mandate_events_type
        )
Ejemplo n.º 8
0
    def test_cannot_add_mandate_events_without_date(self):
        mandate = MandateFactory.create()
        mandate_events_type = MandateEventsTypeFactory.create()

        try:
            yield self.anonymous_fetch(
                '/mandate-events/',
                method='POST',
                body=dumps({
                    'mandate_id': mandate.id,
                    'mandate_events_type_id': mandate_events_type.id
                })
            )
        except HTTPError as e:
            expect(e).not_to_be_null()
            expect(e.code).to_equal(400)
            expect(e.response.reason).to_be_like('Invalid Mandate Events')
    def test_cannot_add_mandate_events_without_mandate_id(self):
        mandate_events_type = MandateEventsTypeFactory.create()
        date = date_to_timestamp(datetime.utcnow().date())

        try:
            yield self.anonymous_fetch(
                '/mandate-events/',
                method='POST',
                body=dumps({
                    'date': date,
                    'mandate_events_type_id': mandate_events_type.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 Events')
            expect(loads(e.response.body)).to_equal({
                'message': 'Invalid Mandate Events'
            })
    def test_can_add_mandate_events(self, logging_mock):
        mandate = MandateFactory.create()
        mandate_events_type = MandateEventsTypeFactory.create()
        date = datetime.utcnow().date()
        d1 = date_to_timestamp(date)

        data = {
            'mandate_id': mandate.id,
            'mandate_events_type_id': mandate_events_type.id,
            'date': d1,
        }
        mandate_events = MandateEvents.add_mandate_events(self.db, data)

        expect(mandate_events.mandate).to_equal(mandate)
        expect(mandate_events.mandate_events_type).to_equal(
            mandate_events_type
        )
        expect(mandate_events.date).to_equal(date)
        expect(logging_mock.mock_calls).to_include(
            call.debug('Added mandate events: "%s"', str(mandate_events))
        )
Ejemplo n.º 11
0
    def test_can_add_mandate_events(self):
        mandate = MandateFactory.create()
        mandate_events_type = MandateEventsTypeFactory.create()
        date = date_to_timestamp(datetime.utcnow().date())

        response = yield self.anonymous_fetch(
            '/mandate-events/',
            method='POST',
            body=dumps({
                'date': date,
                'mandate_id': mandate.id,
                'mandate_events_type_id': mandate_events_type.id
            })
        )
        expect(response.code).to_equal(200)
        mandate_events = loads(response.body)
        expect(mandate_events.get('date')).to_equal(date)
        expect(mandate_events.get('mandate')).to_equal(mandate.to_dict())
        expect(mandate_events.get('mandate_events_type')).to_equal(
            mandate_events_type.to_dict()
        )
    def test_cannot_add_mandate_events_type_twice(self):
        MandateEventsTypeFactory.create(name=u'Assumiu cargo no executivo')

        with expect.error_to_happen(IntegrityError):
            MandateEventsTypeFactory.create(name=u'Assumiu cargo no executivo')