def setup_class(cls): cls.repository = EventItemRepository() cls.test_event_items = [ EventItem('test_name', [candidate], id=i) for i in range(1, 5) ] event_id = 1 cls.repository.event_id_to_event_item_map[ event_id] = cls.test_event_items
class TestSave: def setup_method(self): self.repository = EventItemRepository() @pytest.mark.parametrize('event_item', [EventItem('test_name', [candidate])]) def test_succeeds_when_event_item_has_no_id(self, event_item): saved_event_item = self.repository.save(event_item) assert get_public_vars(self.repository.event_items[ saved_event_item.id]) == get_public_vars(event_item) @pytest.mark.parametrize('event_item, updated_event_item', [(EventItem( 'test_name', [candidate]), EventItem('updated', [candidate]))]) def test_update_succeeds_when_event_item_has_same_id( self, event_item, updated_event_item): saved_event_item = self.repository.save(event_item) updated_event_item.id = saved_event_item.id self.repository.save(updated_event_item) assert get_public_vars(self.repository.event_items[ saved_event_item.id]) == get_public_vars(updated_event_item)
class TestDelete: def setup_method(self): self.repository = EventItemRepository() self.repository.event_items[1] = [ EventItem('test_name', [candidate], id=1) ] @pytest.fixture() def regist_event_item_to_event_id_map(self): event_id = 1 event_item = EventItem('test_name', [candidate], id=1) self.repository.event_id_to_event_item_map[event_id] = [event_item] @pytest.mark.parametrize('event_item', [EventItem('test_name', [candidate], id=1)]) def test_succeeds_when_target_event_item_exists(self, event_item): self.repository.delete(event_item) @pytest.mark.parametrize('event_item, event_id', [(EventItem('test_name', [candidate], id=1), 1)]) def test_succeeds_when_target_event_item_registerd_in_event_id_map( self, event_item, event_id, regist_event_item_to_event_id_map): self.repository.delete(event_item) for registed_event_items \ in self.repository.event_id_to_event_item_map.values(): for registed_event_item in registed_event_items: assert event_item.id == registed_event_item.id @pytest.mark.parametrize('event_item', [EventItem('test_name2', [candidate], id=2)]) def test_return_value_error_when_target_event_item_does_not_exist( self, event_item): with pytest.raises(ValueError): assert self.repository.delete(event_item) @pytest.mark.parametrize('event_item', [EventItem('test_name', [candidate], id=None)]) def test_return_value_error_when_given_event_item_id_is_none( self, event_item): with pytest.raises(ValueError): assert self.repository.delete(event_item)
def test_raise_type_error_with_invalid_args(self, invalid_args): with pytest.raises(TypeError): EventItem(**invalid_args)
def test_succeeds_initialization_with_valid_args(self, valid_args, expected): event_item = EventItem(**valid_args) assert get_public_vars(event_item) == expected
def setup_class(cls): cls.repository = EventItemRepository() cls.repository.event_items[1] = EventItem('test_name', [candidate], id=1)
def regist_event_item_to_event_id_map(self): event_id = 1 event_item = EventItem('test_name', [candidate], id=1) self.repository.event_id_to_event_item_map[event_id] = [event_item]
def setup_method(self): self.repository = EventItemRepository() self.repository.event_items[1] = [ EventItem('test_name', [candidate], id=1) ]
import datetime import pytest from savoten.domain import Candidate, Event, EventItem, Period, User from tests.util import get_public_vars user = User('user_name', '*****@*****.**', 1) candidate = Candidate(user) event_item = EventItem('event_id_name', [candidate]) now = datetime.datetime.now() two_days_ago = now - datetime.timedelta(days=2) one_day_ago = now - datetime.timedelta(days=1) one_day_later = now + datetime.timedelta(days=1) period = Period(one_day_ago, one_day_later) class TestInit: @pytest.mark.parametrize('valid_args, expected', [({ 'id': 1, 'name': 'name', 'items': [event_item], 'period': period, 'description': 'description', 'anonymous': True, 'created_at': now, 'updated_at': one_day_later, 'deleted_at': one_day_later, }, {