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_mandate_twice(self): date_start = datetime.utcnow().date() date_end = (datetime.utcnow() + timedelta(days=10)).date() political_office = PoliticalOfficeFactory.create() legislator = LegislatorFactory.create() MandateFactory.create( legislator=legislator, political_office=political_office, date_start=date_start, date_end=date_end ) with expect.error_to_happen(IntegrityError): MandateFactory.create( legislator=legislator, political_office=political_office, date_start=date_start, date_end=date_end )
def test_can_get_all_mandates(self): mandates = [] for x in range(5): mandate = MandateFactory.create() mandates.append(mandate.to_dict()) response = yield self.anonymous_fetch( '/mandates/', method='GET' ) expect(response.code).to_equal(200) mandates_loaded = loads(response.body) expect(mandates_loaded).to_length(5) expect(mandates_loaded).to_be_like(mandates)
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 )
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 )
def test_cannot_add_mandate_events_without_date(self): mandate = MandateFactory.create() mandate_events_type = MandateEventsTypeFactory.create() try: yield self.anonymous_fetch( '/mandate-events/', method='POST', body=dumps({ '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(400) expect(e.response.reason).to_be_like('Invalid Mandate Events')
def test_can_create_mandate(self): date_start = datetime.utcnow().date() date_end = (datetime.utcnow() + timedelta(days=10)).date() political_office = PoliticalOfficeFactory.create() legislator = LegislatorFactory.create() mandate = MandateFactory.create( legislator=legislator, political_office=political_office, date_start=date_start, date_end=date_end ) expect(mandate.id).not_to_be_null() expect(mandate.date_start).to_equal(date_start) expect(mandate.date_end).to_equal(date_end) expect(mandate.political_office).to_equal(political_office)
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' })
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)) )
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_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() )