def test_cannot_add_legislature_twice(self):
        date_start = datetime.utcnow().date()
        date_end = (datetime.utcnow() + timedelta(days=10)).date()
        institution = InstitutionFactory.create()

        LegislatureFactory.create(
            institution=institution,
            date_start=date_start,
            date_end=date_end
        )

        with expect.error_to_happen(IntegrityError):
            LegislatureFactory.create(
                institution=institution,
                date_start=date_start,
                date_end=date_end
            )
Esempio n. 2
0
    def test_can_get_all_legislatures(self):
        legislatures = []
        for x in range(5):
            legislature = LegislatureFactory.create()
            legislatures.append(legislature.to_dict())

        response = yield self.anonymous_fetch(
            '/legislatures/',
            method='GET'
        )

        expect(response.code).to_equal(200)
        legislatures_loaded = loads(response.body)
        expect(legislatures_loaded).to_length(5)
        expect(legislatures_loaded).to_be_like(legislatures)
    def test_can_create_legislature(self):
        date_start = datetime.utcnow().date()
        date_end = (datetime.utcnow() + timedelta(days=10)).date()
        institution = InstitutionFactory.create()

        legislature = LegislatureFactory.create(
            institution=institution,
            date_start=date_start,
            date_end=date_end
        )

        expect(legislature.id).not_to_be_null()
        expect(legislature.date_start).to_equal(date_start)
        expect(legislature.date_end).to_equal(date_end)
        expect(legislature.institution).to_equal(institution)
    def test_can_convert_to_dict(self):
        legislature = LegislatureFactory.create()
        legislature_dict = legislature.to_dict()

        expect(legislature_dict.keys()).to_length(3)

        expect(legislature_dict.keys()).to_be_like([
            'date_start', 'date_end', 'institution'
        ])

        date_start = date_to_timestamp(legislature.date_start)
        date_end = date_to_timestamp(legislature.date_end)

        expect(legislature_dict['date_start']).to_equal(date_start)
        expect(legislature_dict['date_end']).to_equal(date_end)
        expect(legislature_dict['institution']).to_equal(
            legislature.institution.to_dict()
        )