Exemplo n.º 1
0
def plan(account_id, plan_id):
    try:
        dao = PlanDao(content, account_id)
        plan = dao.retrieve(plan_id)
        return dao.get_schema().dumps(plan, indent=2), 200
    except Exception as e:
        raise InvalidUsage(str(e))
Exemplo n.º 2
0
def update_plan_cdl(account_id, plan_id):
    try:
        dao = PlanDao(content, account_id)
        plan = dao.retrieve(plan_id)
        plan.cdl = request.data
        dao.save(plan)
        return plan.cdl, 200
    except Exception as e:
        raise InvalidUsage(str(e))
Exemplo n.º 3
0
def plan_kml(account_id, plan_id):
    dao = PlanDao(content, account_id)
    plan = dao.retrieve(plan_id)
    fin = preprocess(StringIO(plan.cdl))
    analyser = CdlFileAnalyser()
    cdl_file = analyser.analyse(fin)
    kml = cdlfile_to_KML(cdl_file, plan_id)
    return kml, 200, {
        'Content-Type': 'application/vnd.google-earth.kml+xml; charset=utf-8'
    }
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
def plan_update(account_id, plan_id):
    try:
        dao = PlanDao(content, account_id)
        plan = dao.retrieve(plan_id)
        plan = dao.from_json(request.data)
        if plan_id != plan.plan_id:
            raise Exception("Cannot change the plan ID")
        dao.save(plan)
    except Exception as e:
        raise InvalidUsage(str(e))

    return dao.get_schema().dumps(plan, indent=2), 200
Exemplo n.º 6
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)
Exemplo n.º 7
0
def get_plan_cdl(account_id, plan_id):
    dao = PlanDao(content, account_id)
    plan = dao.retrieve(plan_id)
    return plan.cdl, 200
Exemplo n.º 8
0
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
Exemplo n.º 9
0
def plan_list(account_id):
    dao = PlanDao(content, account_id)
    plans = dao.find_all()
    return dao.get_schema().dumps(plans, many=True, indent=2), 200