Ejemplo n.º 1
0
    def test_can_get_institution_info(self):
        InstitutionFactory.create(name="Heavy Metal Institution", siglum="HMI", logo="http://l.com/logo.png")

        response = yield self.anonymous_fetch("/institutions/HMI", method="GET")
        expect(response.code).to_equal(200)
        institution = loads(response.body)
        expect(institution).to_length(3)
        expect(institution.get("name")).to_equal("Heavy Metal Institution")
        expect(institution.get("siglum")).to_equal("HMI")
        expect(institution.get("logo")).to_equal("http://l.com/logo.png")
Ejemplo n.º 2
0
    def test_cannot_add_legislature_twice(self):
        institution = InstitutionFactory.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(
            '/legislatures/',
            method='POST',
            body=dumps({
                'date_start': date_start,
                'date_end': date_end,
                'institution_id': institution.id,
            })
        )

        try:
            yield self.anonymous_fetch(
                '/legislatures/',
                method='POST',
                body=dumps({
                    'date_start': date_start,
                    'date_end': date_end,
                    'institution_id': institution.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')
Ejemplo n.º 3
0
    def test_can_get_all_institutions(self):
        institutions = []
        for x in range(5):
            institution = InstitutionFactory.create(name="Institution %s" % x, siglum="%s" % x)
            institutions.append(institution.to_dict())

        response = yield self.anonymous_fetch("/institutions/", method="GET")

        expect(response.code).to_equal(200)
        institutions_loaded = loads(response.body)
        expect(institutions_loaded).to_length(5)
        expect(institutions_loaded).to_be_like(institutions)
    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_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
            )
Ejemplo n.º 6
0
    def test_cannot_add_legislature_without_date_end(self):
        institution = InstitutionFactory.create()
        now = datetime.utcnow()
        date_start = date_to_timestamp(now.date())

        try:
            yield self.anonymous_fetch(
                '/legislatures/',
                method='POST',
                body=dumps({
                    'date_start': date_start,
                    'institution_id': institution.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 Legislature')
Ejemplo n.º 7
0
    def test_can_add_legislature(self):
        institution = InstitutionFactory.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(
            '/legislatures/',
            method='POST',
            body=dumps({
                'date_start': date_start,
                'date_end': date_end,
                'institution_id': institution.id,
            })
        )
        expect(response.code).to_equal(200)
        legislature = loads(response.body)
        expect(legislature.get('date_start')).to_equal(date_start)
        expect(legislature.get('date_end')).to_equal(date_end)
        expect(legislature.get('institution')).to_equal(institution.to_dict())
    def test_can_add_legislature(self, logging_mock):
        institution = InstitutionFactory.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 = {
            'institution_id': institution.id,
            'date_start': date_start,
            'date_end': date_end,
        }
        legislature = Legislature.add_legislature(self.db, data)

        expect(legislature.institution).to_equal(institution)
        expect(legislature.date_start).to_equal(d1)
        expect(legislature.date_end).to_equal(d2)
        expect(logging_mock.mock_calls).to_include(
            call.debug('Added legislature: "%s"', str(legislature))
        )