示例#1
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')
    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))
        )
示例#3
0
 def to_dict(self):
     return {
         'legislator': self.legislator.to_dict(),
         'political_office': self.political_office.to_dict(),
         'date_start': date_to_timestamp(self.date_start),
         'date_end': date_to_timestamp(self.date_end),
     }
    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())
示例#5
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_cannot_add_legislator_events_twice(self):
        legislator = LegislatorFactory.create()
        legislator_events_type = LegislatorEventsTypeFactory.create()
        date = date_to_timestamp(datetime.utcnow().date())

        yield self.anonymous_fetch(
            '/legislator-events/',
            method='POST',
            body=dumps({
                'date': date,
                'legislator_id': legislator.id,
                'legislator_events_type_id': legislator_events_type.id
            })
        )

        try:
            yield self.anonymous_fetch(
                '/legislator-events/',
                method='POST',
                body=dumps({
                    'date': date,
                    'legislator_id': legislator.id,
                    'legislator_events_type_id': legislator_events_type.id
                })
            )
        except HTTPError as e:
            expect(e).not_to_be_null()
            expect(e.code).to_equal(409)
            expect(e.response.reason).to_be_like(
                'Legislator Events already exists'
            )
            expect(loads(e.response.body)).to_equal({
                'message': 'Legislator Events already exists'
            })
示例#7
0
    def test_cannot_add_legislature_without_institution(self):
        now = datetime.utcnow()
        date_start = date_to_timestamp(now.date())
        date_end = date_to_timestamp((now + timedelta(days=10)).date())

        try:
            yield self.anonymous_fetch(
                '/legislatures/',
                method='POST',
                body=dumps({
                    'date_start': date_start,
                    'date_end': date_end,
                })
            )
        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')
    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()
        )
示例#9
0
    def test_can_add_legislator(self, logging_mock):
        date_of_birth = date_to_timestamp(datetime.utcnow().date())
        data = {'name': 'Marcelo Jorge Vieira', 'date_of_birth': date_of_birth}
        legislator = Legislator.add_legislator(self.db, data)

        expect(legislator.name).to_equal('Marcelo Jorge Vieira')
        expect(logging_mock.mock_calls).to_include(
            call.debug('Added legislator: "%s"', 'Marcelo Jorge Vieira')
        )
示例#10
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_convert_to_dict(self):
        mandate = MandateFactory.create()
        mandate_dict = mandate.to_dict()

        expect(mandate_dict.keys()).to_length(4)

        expect(mandate_dict.keys()).to_be_like([
            'date_start', 'date_end', 'political_office', 'legislator'
        ])

        date_start = date_to_timestamp(mandate.date_start)
        date_end = date_to_timestamp(mandate.date_end)

        expect(mandate_dict['date_start']).to_equal(date_start)
        expect(mandate_dict['date_end']).to_equal(date_end)
        expect(mandate_dict['political_office']).to_equal(
            mandate.political_office.to_dict()
        )
        expect(mandate_dict['legislator']).to_equal(
            mandate.legislator.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))
        )
示例#13
0
    def to_dict(self):
        date_of_birth = None
        if self.date_of_birth:
            date_of_birth = date_to_timestamp(self.date_of_birth)

        return {
            "name": self.name,
            "picture": self.picture,
            "website": self.website,
            "email": self.email,
            "gender": self.gender,
            "date_of_birth": date_of_birth,
            "about": self.about,
        }
    def to_dict(self):
        date_of_birth = None
        if self.date_of_birth:
            date_of_birth = date_to_timestamp(self.date_of_birth)

        return {
            'name': self.name,
            'picture': self.picture,
            'website': self.website,
            'email': self.email,
            'gender': self.gender,
            'date_of_birth': date_of_birth,
            'about': self.about,
        }
    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'
            })
    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_cannot_add_legislator_events_without_legislator_events_type_id(self):
        legislator = LegislatorFactory.create()
        date = date_to_timestamp(datetime.utcnow().date())

        try:
            yield self.anonymous_fetch(
                '/legislator-events/',
                method='POST',
                body=dumps({
                    'date': date,
                    'legislator_id': legislator.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 Legislator Events')
示例#18
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')
    def test_cannot_add_mandate_events_without_mandate_events_type_id(self):
        mandate = MandateFactory.create()
        date = date_to_timestamp(datetime.utcnow().date())

        try:
            yield self.anonymous_fetch(
                '/mandate-events/',
                method='POST',
                body=dumps({
                    'date': date,
                    'mandate_id': mandate.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'
            })
示例#20
0
    def test_can_convert_to_dict(self):
        legislator = LegislatorFactory.create()
        legislator_dict = legislator.to_dict()

        expect(legislator_dict.keys()).to_length(7)

        expect(legislator_dict.keys()).to_be_like([
            'name', 'picture', 'website', 'email', 'gender',
            'date_of_birth', 'about',
        ])

        date_of_birth = date_to_timestamp(legislator.date_of_birth)

        expect(legislator_dict['name']).to_equal(legislator.name)
        expect(legislator_dict['picture']).to_equal(legislator.picture)
        expect(legislator_dict['website']).to_equal(legislator.website)
        expect(legislator_dict['email']).to_equal(legislator.email)
        expect(legislator_dict['gender']).to_equal(legislator.gender)
        expect(legislator_dict['date_of_birth']).to_equal(date_of_birth)
        expect(legislator_dict['about']).to_equal(legislator.about)
    def test_can_add_legislator_events(self):
        legislator = LegislatorFactory.create()
        legislator_events_type = LegislatorEventsTypeFactory.create()
        date = date_to_timestamp(datetime.utcnow().date())

        response = yield self.anonymous_fetch(
            '/legislator-events/',
            method='POST',
            body=dumps({
                'date': date,
                'legislator_id': legislator.id,
                'legislator_events_type_id': legislator_events_type.id
            })
        )
        expect(response.code).to_equal(200)
        legislator_events = loads(response.body)
        expect(legislator_events.get('date')).to_equal(date)
        expect(legislator_events.get('legislator')).to_equal(legislator.to_dict())
        expect(legislator_events.get('legislator_events_type')).to_equal(
            legislator_events_type.to_dict()
        )
    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))
        )
示例#23
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_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'
            })
示例#25
0
 def to_dict(self):
     return {
         'institution': self.institution.to_dict(),
         'date_start': date_to_timestamp(self.date_start),
         'date_end': date_to_timestamp(self.date_end),
     }
示例#26
0
 def to_dict(self):
     return {
         'date': date_to_timestamp(self.date),
         'mandate': self.mandate.to_dict(),
         'mandate_events_type': self.mandate_events_type.to_dict(),
     }
 def test_can_convert_date_to_timestamp(self):
     dt = datetime.strptime('Jun 27 2015', '%b %d %Y').date()
     expect(date_to_timestamp(dt)).to_equal(1435363200)
 def to_dict(self):
     return {
         'date': date_to_timestamp(self.date),
         'legislator': self.legislator.to_dict(),
         'legislator_events_type': self.legislator_events_type.to_dict(),
     }