Beispiel #1
0
    def test_should_get_false_when_user_is_not_related_to_campaign(self):
        # given
        campaign = CampaignEntity()
        campaign.id = 99
        campaign.created_on = date(2020, 1, 1)
        campaign.modified_on = date(2020, 1, 1)
        campaign.opt_lock = 0
        campaign.campaign_name = "Test Campaign"
        campaign.begin_date = date(2055, 1, 1)
        campaign.passed_days = 10

        gm = UserEntity()
        gm.id = 77
        gm.created_on = date(2019, 1, 1)
        gm.modified_on = date(2019, 1, 1)
        gm.opt_lock = 0
        gm.user_name = "Test User"

        campaign.game_master = gm

        self.campaign_repository_mock.read_by_id.return_value = campaign

        # when
        result = campaign_service.check_if_user_related_to_campaign(88, 99)

        # then
        self.assertEqual(False, result)
Beispiel #2
0
    def test_should_get_campaign_details(self):
        # given
        campaign = CampaignEntity()
        campaign.id = 99
        campaign.created_on = datetime(2020, 1, 1, 12, 12, 12)
        campaign.modified_on = datetime(2020, 1, 1, 13, 13, 13)
        campaign.opt_lock = 0
        campaign.campaign_name = "Test Campaign"
        campaign.begin_date = date(2055, 1, 1)
        campaign.passed_days = 10

        gm = UserEntity()
        gm.id = 88
        gm.created_on = date(2019, 1, 1)
        gm.modified_on = date(2019, 1, 1)
        gm.opt_lock = 0
        gm.user_name = "Test User"

        campaign.game_master = gm

        self.campaign_repository_mock.read_by_id.return_value = campaign

        # when
        campaign_details = campaign_service.get_campaign_details(99)

        # then
        self.assertEqual(99, campaign_details["id"])
        self.assertEqual("Test Campaign", campaign_details["title"])
        self.assertEqual("2020-01-01T12:12:12", campaign_details["creationDate"])
        self.assertEqual("2055-01-01", campaign_details["startDate"])
        self.assertEqual(10, campaign_details["passedDays"])
        self.assertEqual("2055-01-11", campaign_details["currentDate"])
        self.assertEqual(88, campaign_details["gameMasterId"])
        self.assertEqual("Test User", campaign_details["gameMasterName"])
    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_get_campaign(self):
        # given
        user = UserEntity()
        user.user_name = "Test User"
        user.created_on = datetime.utcnow()
        user.modified_on = datetime.utcnow()
        user.opt_lock = 0

        campaign = CampaignEntity()
        campaign.campaign_name = "Test Campaign"
        campaign.created_on = datetime.utcnow()
        campaign.modified_on = datetime.utcnow()
        campaign.opt_lock = 0
        campaign.begin_date = date(2055, 1, 1)
        campaign.passed_days = 0
        campaign.game_master = user

        self.session.add(campaign)
        self.session.flush()

        # when
        found_campaign = campaign_repository.read_by_id(campaign.id)

        # then
        self.assertEqual(campaign, found_campaign)
Beispiel #5
0
    def test_should_create_timeline_entry(self):
        # given
        campaign = CampaignEntity()
        campaign.id = 99
        campaign.created_on = date(2020, 1, 1)
        campaign.modified_on = date(2020, 1, 1)
        campaign.opt_lock = 0
        campaign.campaign_name = "Test Campaign"
        campaign.begin_date = date(2055, 1, 1)
        campaign.passed_days = 10

        self.campaign_repository_mock.read_by_id.return_value = campaign

        entry_data = {
            "title": "Test entry",
            "sessionDate": date.fromisoformat("2020-01-01"),
            "summaryText": "Test text",
            "campaignId": campaign.id
        }
        editor_name = "Test user"

        # when
        campaign_service.create_timeline_entry(entry_data, editor_name)

        # then
        self.assertEqual(len(campaign.campaign_timeline_entries), 1)
        self.assertEqual(len(campaign.campaign_history_entries), 1)
        self.campaign_repository_mock.persist.assert_called_once_with(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)
Beispiel #7
0
def _create_campaign_entity(timestamp, campaign_name, begin_date, passed_days, game_master_id):
    """
    Create a new instance of the campaign entity with the given data.
    """

    campaign_entity = CampaignEntity()
    campaign_entity.created_on = timestamp
    campaign_entity.modified_on = timestamp
    campaign_entity.opt_lock = 0
    campaign_entity.campaign_name = campaign_name
    campaign_entity.begin_date = begin_date
    campaign_entity.passed_days = passed_days
    campaign_entity.game_master_id = game_master_id
    return campaign_entity
Beispiel #8
0
    def test_should_get_campaigns(self):
        # given
        campaign = CampaignEntity()
        campaign.campaign_name = "campaign 1"
        campaign.begin_date = date(2055, 1, 1)
        campaign.passed_days = 10

        self.campaign_repository_mock.read_by_gm_id.return_value = [campaign]
        self.user_service_mock.get_user_by_user_name.return_value = {
            "id": 1,
            "user_name": "test_user"
        }

        # when
        campaigns = campaign_service.get_campaigns_by_gm_id(1)

        # then
        self.assertIsNotNone(campaigns)
        self.assertEqual(1, len(campaigns))
        self.assertEqual("campaign 1", campaigns[0]["campaign_name"])
        self.assertEqual(date(2055, 1, 1), campaigns[0]["begin_date"])
        self.assertEqual(10, campaigns[0]["passed_days"])
    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())
    def test_should_get_all_campaigns_of_given_gm(self):
        # given
        user = UserEntity()
        user.user_name = "test_user"
        user.created_on = datetime.utcnow()
        user.modified_on = datetime.utcnow()
        user.opt_lock = 0

        campaign_1 = CampaignEntity()
        campaign_1.campaign_name = "campaign_1"
        campaign_1.created_on = datetime.utcnow()
        campaign_1.modified_on = datetime.utcnow()
        campaign_1.opt_lock = 0
        campaign_1.begin_date = date(2055, 1, 1)
        campaign_1.passed_days = 0
        campaign_1.game_master = user

        campaign_2 = CampaignEntity()
        campaign_2.campaign_name = "campaign_2"
        campaign_2.created_on = datetime.utcnow()
        campaign_2.modified_on = datetime.utcnow()
        campaign_2.opt_lock = 0
        campaign_2.begin_date = date(2055, 1, 1)
        campaign_2.passed_days = 0
        campaign_2.game_master = user

        other_user = UserEntity()
        other_user.user_name = "other_user"
        other_user.created_on = datetime.utcnow()
        other_user.modified_on = datetime.utcnow()
        other_user.opt_lock = 0

        campaign_3 = CampaignEntity()
        campaign_3.campaign_name = "campaign_3"
        campaign_3.created_on = datetime.utcnow()
        campaign_3.modified_on = datetime.utcnow()
        campaign_3.opt_lock = 0
        campaign_3.begin_date = date(2055, 1, 1)
        campaign_3.passed_days = 0
        campaign_3.game_master = other_user

        self.session.add(campaign_1)
        self.session.add(campaign_2)
        self.session.add(campaign_3)
        self.session.flush()

        # when
        found_campaigns = campaign_repository.read_by_gm_id(user.id)

        # then
        self.assertIsNotNone(found_campaigns)
        self.assertIn(campaign_1, found_campaigns)
        self.assertIn(campaign_2, found_campaigns)
        self.assertNotIn(campaign_3, found_campaigns)