def test_can_get_legislator_events_type_info(self): LegislatorEventsTypeFactory.create(name=u'Presidente do Partido') response = yield self.anonymous_fetch( '/legislator-events-types/presidente-do-partido', method='GET' ) expect(response.code).to_equal(200) legislator_events_type = loads(response.body) expect(legislator_events_type).to_length(2) expect(legislator_events_type.get('name')).to_equal( 'Presidente do Partido' ) expect(legislator_events_type.get('slug')).to_equal( 'presidente-do-partido' )
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' })
def test_can_create_legislator_events_type(self): legislator_events_type = LegislatorEventsTypeFactory.create( name=u'Presidente do Partido' ) expect(legislator_events_type.id).not_to_be_null() expect(legislator_events_type.name).to_equal('Presidente do Partido') expect(legislator_events_type.slug).to_equal('presidente-do-partido')
def test_can_convert_to_dict(self): legislator_events_type = LegislatorEventsTypeFactory.create() legislator_events_type_dict = legislator_events_type.to_dict() expect(legislator_events_type_dict.keys()).to_length(2) expect(legislator_events_type_dict.keys()).to_be_like(['name', 'slug']) expect(legislator_events_type_dict['name']).to_equal( legislator_events_type.name ) expect(legislator_events_type_dict['slug']).to_equal( legislator_events_type.slug )
def test_can_get_all_legislator_events_types(self): legislator_events_types = [] for x in range(5): legislator_events_type = LegislatorEventsTypeFactory.create() legislator_events_types.append(legislator_events_type.to_dict()) response = yield self.anonymous_fetch( '/legislator-events-types/', method='GET' ) expect(response.code).to_equal(200) legislator_events_types_loaded = loads(response.body) expect(legislator_events_types_loaded).to_length(5) expect(legislator_events_types_loaded).to_be_like( legislator_events_types )
def test_cannot_add_legislator_events_without_legislator_id(self): legislator_events_type = LegislatorEventsTypeFactory.create() date = date_to_timestamp(datetime.utcnow().date()) try: yield self.anonymous_fetch( '/legislator-events/', method='POST', body=dumps({ 'date': date, 'legislator_events_type_id': legislator_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 Legislator Events')
def test_cannot_add_legislator_events_without_date(self): legislator = LegislatorFactory.create() legislator_events_type = LegislatorEventsTypeFactory.create() try: yield self.anonymous_fetch( '/legislator-events/', method='POST', body=dumps({ '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(422) expect(e.response.reason).to_be_like('Invalid Legislator Events') expect(loads(e.response.body)).to_equal({ 'message': 'Invalid Legislator Events' })
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_cannot_add_legislator_events_type_twice(self): LegislatorEventsTypeFactory.create(name=u'Presidente do Partido') with expect.error_to_happen(IntegrityError): LegislatorEventsTypeFactory.create(name=u'Presidente do Partido')