def test_should_persist_new_campaign(self):
        # given
        user = UserEntity()
        user.user_name = "test_user"
        user.created_on = datetime.utcnow()
        user.modified_on = datetime.utcnow()
        user.opt_lock = 0

        self.session.add(user)
        self.session.flush()

        new_campaign = CampaignEntity()
        new_campaign.created_on = datetime.utcnow()
        new_campaign.modified_on = datetime.utcnow()
        new_campaign.opt_lock = 0
        new_campaign.campaign_name = "test campaign"
        new_campaign.begin_date = date(2054, 1, 1)
        new_campaign.passed_days = 0
        new_campaign.game_master_id = user.id

        # when
        campaign_repository.persist(new_campaign)

        # then
        self.assertIn(new_campaign, self.session.query(CampaignEntity).all())
    def test_should_raise_value_error_when_argument_is_of_wrong_type(self):
        # given
        new_campaign = str()

        # when then
        with self.assertRaises(ValueError):
            campaign_repository.persist(new_campaign)
    def test_should_get_persistence_error_on_constraint_violation(self):
        # given
        new_campaign = CampaignEntity()

        # when then
        with self.assertRaises(PersistenceError):
            campaign_repository.persist(new_campaign)
Esempio n. 4
0
def create_campaign(editor_name, campaign_name, begin_date, passed_days, game_master_id, game_master_name):
    """
    Create a new campaign.
    """

    # Saving the timestamp so all entities can share the same time of creation.
    timestamp = datetime.utcnow()

    # Creating the campaign.
    campaign = _create_campaign_entity(timestamp, campaign_name, begin_date, passed_days, game_master_id)

    # Adding history entry about creation.
    creation_history_entry_message = f"Kampania {campaign_name} została utworzona."
    _add_history_entry_to_campaign(campaign, editor_name, timestamp, creation_history_entry_message)

    # Adding history entry about the current game master.
    gm_history_entry_message = f"Obecnym mistrzem gry zostaje {game_master_name}."
    _add_history_entry_to_campaign(campaign, editor_name, timestamp, gm_history_entry_message)

    # Persisting.
    campaign_repository.persist(campaign)
    def test_should_persist_new_campaign_with_timeline_entry(self):
        # given
        user = UserEntity()
        user.user_name = "test_user"
        user.created_on = datetime.utcnow()
        user.modified_on = datetime.utcnow()
        user.opt_lock = 0

        self.session.add(user)
        self.session.flush()

        new_campaign = CampaignEntity()
        new_campaign.created_on = datetime.utcnow()
        new_campaign.modified_on = datetime.utcnow()
        new_campaign.opt_lock = 0
        new_campaign.campaign_name = "test campaign"
        new_campaign.begin_date = date(2054, 1, 1)
        new_campaign.passed_days = 0
        new_campaign.game_master_id = user.id

        new_campaign_timeline_entry = CampaignTimelineEntity()
        new_campaign_timeline_entry.created_on = datetime.utcnow()
        new_campaign_timeline_entry.modified_on = datetime.utcnow()
        new_campaign_timeline_entry.opt_lock = 0
        new_campaign_timeline_entry.title = "test session"
        new_campaign_timeline_entry.session_date = date.today()
        new_campaign_timeline_entry.summary_text = "this is summary"
        new_campaign_timeline_entry.campaign = new_campaign

        # when
        campaign_repository.persist(new_campaign)

        # then
        self.assertIn(new_campaign, self.session.query(CampaignEntity).all())
        self.assertIsNotNone(
            self.session.query(CampaignTimelineEntity).filter_by(
                campaign_id=new_campaign.id).first())
Esempio n. 6
0
def create_timeline_entry(entry_data: dict, editor_name: str) -> int:
    """
    Create an entry in the timeline of a campaign.
    """

    campaign = campaign_repository.read_by_id(entry_data["campaignId"])

    if campaign is None:
        raise DomainError("Campaign does not extist!", "DC002")

    timestamp = datetime.utcnow()
    timeline_entry = campaign_mapper.map_timeline_entry_data_to_timeline_entity(entry_data, timestamp)
    campaign.campaign_timeline_entries.append(timeline_entry)

    history_entry_data = {
        "editorName": editor_name,
        "message": get_message("campaign: timeline entry created").format(entry_data["title"])
    }
    history_entry = campaign_mapper.map_history_entry_data_to_history_entity(history_entry_data, timestamp)
    campaign.campaign_history_entries.append(history_entry)

    campaign_repository.persist(campaign)

    return timeline_entry.id