コード例 #1
0
class TestPlan(unittest.TestCase):
    def setUp(self):
        os.system("rm -rf ./test_content/*")
        self.account_dao = AccountDao(Path("./test_content"))
        account = self.account_dao.load({
            'identifier': 1,
            'name': 'Trilogy Partners',
            'email': '*****@*****.**'
        })
        self.account_dao.create(account)
        self.vessel_dao = VesselDao(Path("./test_content"), account.identifier)
        trilogy = self.vessel_dao.load({
            'account_id': 1,
            'identifier': 'trilogy',
            'name': 'SV Trilogy',
            'flag': 'Australian',
            'rego': '806176',
            'speed_kts': 7.6,
        })
        self.vessel_dao.create(trilogy)
        x = self.vessel_dao.retrieve('trilogy')
        self.plan_dao = PlanDao(Path("./test_content"), account.identifier)

    def test_create(self):
        # Note -- don't use the Account constructor directly. Use the AccountDao instead
        plan = self.plan_dao.load({
            'account_id':
            1,
            'vessel_id':
            'trilogy',
            'season_id':
            'med_summer_2019',
            'plan_id':
            self.plan_dao.get_random_id(),
            'cdl':
            "This is cruise description language\nit breaks over multiple lines"
        })
        self.plan_dao.create(plan)
        x = self.plan_dao.retrieve(plan.plan_id)
        self.assertEqual(type(x.plan_id), type(plan.plan_id))
        self.assertEqual(x.plan_id, plan.plan_id)
        self.assertEqual(x.account_id, plan.account_id)
        self.assertEqual(x.vessel_id, plan.vessel_id)
        self.assertEqual(x.season_id, plan.season_id)
        self.assertEqual(x.cdl, plan.cdl)

    def test_create_with_cdl(self):
        with open("../grammar/plan_B.cdl", 'r') as infile:
            cdl = infile.read()
        plan = self.plan_dao.load({
            'account_id': 1,
            'vessel_id': 'trilogy',
            'season_id': 'med_summer_2019',
            'plan_id': self.plan_dao.get_random_id(),
            'cdl': cdl
        })
        self.plan_dao.create(plan)
        x = self.plan_dao.retrieve(plan.plan_id)
        self.assertEqual(type(x.plan_id), type(plan.plan_id))
        self.assertEqual(x.plan_id, plan.plan_id)
        self.assertEqual(x.account_id, plan.account_id)
        self.assertEqual(x.vessel_id, plan.vessel_id)
        self.assertEqual(x.season_id, plan.season_id)
        self.assertEqual(x.cdl, plan.cdl)
コード例 #2
0
ファイル: server.py プロジェクト: smr547/cruise-description
def plan_add(account_id):
    dao = PlanDao(content, account_id)
    plan = dao.from_json(request.data)
    dao.create(plan)
    plan = dao.retrieve(plan.plan_id)
    return dao.get_schema().dumps(plan, indent=2), 200