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
            )
예제 #2
0
    def test_can_get_all_mandate_events(self):
        events = []
        for x in range(5):
            mandate_events = MandateEventsFactory.create()
            events.append(mandate_events.to_dict())

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

        expect(response.code).to_equal(200)
        mandates_events_loaded = loads(response.body)
        expect(mandates_events_loaded).to_length(5)
        expect(mandates_events_loaded).to_be_like(events)
    def test_can_convert_to_dict(self):
        mandate_events = MandateEventsFactory.create()
        mandate_events_dict = mandate_events.to_dict()

        expect(mandate_events_dict.keys()).to_length(3)

        expect(mandate_events_dict.keys()).to_be_like([
            'date', 'mandate', 'mandate_events_type'
        ])

        date = date_to_timestamp(mandate_events.date)

        expect(mandate_events_dict['date']).to_equal(date)
        expect(mandate_events_dict['mandate_events_type']).to_equal(
            mandate_events.mandate_events_type.to_dict()
        )
    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
        )