def setUp(self): import datetime today = datetime.date.today() self.u = User(username='******') self.u.save() self.baron = Plane(tailnumber="N1234", type='BE-55') self.baron.save() self.seaplane = Plane(tailnumber="N5678", cat_class=3) self.seaplane.save() self.local_route = Route.from_string('kvta kvta') self.more50nm_route = Route.from_string('kvta kluk') self.no_land_more50nm_route = Route.from_string('kvta @kluk kvta') self.less50nm_route = Route.from_string('kvta kcmh') self.no_land_less50nm_route = Route.from_string('kvta @kcmh kvta') self.f = Flight(total=11.0, pic=10.0, date=today, route=self.local_route)
def setUp(self): self.p = Plane(tailnumber="N444444", cat_class=4, type="TYPE") self.p.save() self.u = User(username='******') self.u.save() self.f = Flight( plane=self.p, route=Route.from_string('mer-lga'), user=self.u, date='2009-01-05', total=10.0, ) self.f.save()
def handle_flight(self, line): from forms import ImportFlightForm if not line.get("tailnumber") == "": kwargs = {"tailnumber": line.get("tailnumber"), "user": self.user} if line.get("type"): kwargs.update({"type": line.get("type")}) try: plane, created = Plane.objects.get_or_create(**kwargs) except Plane.MultipleObjectsReturned: plane = Plane.objects.filter(**kwargs)[0] else: ## 90 = the unknown plane plane = Plane(pk=90) ## FIXME should be something more intuitive line.update({"plane": plane.pk}) flight = Flight(user=self.user) form = ImportFlightForm(line, instance=flight, user=self.user) if form.is_valid(): ff = form.save(commit=False) ff.save(no_badges=True) message = 'good' else: message = form.errors return status_decorator( super(DatabaseImport, self).handle_flight, line, message)
def setUp(self): level = Level(flavor="Plain", plane_life_span=3, max_today_write=3, max_today_reply=3, next_level_likes=10) level.save() user = user_model.User.objects.create_user(username='******', password='******') user.save() reply_user = user_model.User.objects.create_user( username='******', password='******') reply_user.save() self.user = User(user=user, today_write_count=10, today_reply_count=10, total_likes=10, level=level) self.user.save() self.reply_user = User(user=reply_user, today_write_count=10, today_reply_count=10, total_likes=10, level=level) self.reply_user.save() self.plane = Plane(author=self.user, content='content', tag='tag') self.plane.save() self.reply = Reply(plane_author=self.user, reply_author=self.reply_user, original_content='orig', original_tag='orig_tag', content='cont') self.reply.save() self.client = Client()
def setUp(self): self.p = Plane(tailnumber="N444444", cat_class=4, type="TYPE") self.p.save() self.u = User(username='******') self.u.save() self.f = Flight(plane=self.p, route=Route.from_string('mer-lga'), user=self.u, date='2009-01-05', total=10.0, ) self.f.save()
def currency(request): """ Prepare the currency page """ ############################################ instrument below inst_out = [] for fake_class in ("fixed_wing", "helicopter", "glider"): inst = FAA_Instrument(request.display_user, fake_class=fake_class) if inst.eligible(): inst.calculate() cb = InstCurrBox(inst) inst_out.append(cb) land_out = [] for curr in CURRENCIES: land = FAA_Landing(request.display_user, item=curr) if land.eligible(): land.calculate() cb = LandCurrBox(land) land_out.append(cb) types = Plane.currency_types(request.display_user) type_out = [] for curr in types: land = FAA_Landing(request.display_user, item=curr) if land.eligible(): land.calculate() cb = LandCurrBox(land) type_out.append(cb) medi = FAA_Medical(request.display_user) medi_out = [] if medi.eligible(): medi.calculate() cb = MediCurrBox(medi) medi_out.append(cb) cert = FAA_Certs(request.display_user) cert_out = [] if cert.eligible(): cert.calculate() cb = CertsCurrBox(cert) cert_out.append(cb) return locals()
def clean(self, val): """ Turns the entered value (a tailnumber or a pk), into a plane instance """ if val == '' or val is None or val == '90': ## if input was blank, get and return the global unknown plane return Plane.objects.get(pk=settings.UNKNOWN_PLANE_ID) if re.match(r'^[0-9]+$', val): try: # most likely a PK return Plane.objects.user(self.user)\ .filter(retired=False, pk=val)[0] except IndexError: # but could also be a all numeric tailnumber return Plane.objects.user(self.user)\ .filter(retired=False, tailnumber=val)[0] if val.startswith("pk:"): pk = val[3:] p = Plane.goon(pk=pk, user=self.user) if p: return p else: return Plane.objects.get(pk=settings.UNKNOWN_PLANE_ID) elif " " in val: tn, ty = val.split(' ')[:2] ty = ty.upper() kwarg = {"tailnumber": tn, "user": self.user, "type": ty} else: tn = val kwarg = {"tailnumber": tn, "user": self.user} try: return Plane.objects.filter(retired=False, **kwarg)[0] except IndexError: # couldn't find airplane, it either doesn't exist, or it's retired return Plane.objects.create(**kwarg)
class ColumnsTest(TestCase): fixtures = ['airport/test-fixtures/ohio.json', 'airport/test-fixtures/test-region.json', 'airport/test-fixtures/test-country.json'] def setUp(self): import datetime today = datetime.date.today() self.u = User(username='******') self.u.save() self.baron = Plane(tailnumber="N1234", type='BE-55') self.baron.save() self.seaplane = Plane(tailnumber="N5678", cat_class=3) self.seaplane.save() self.local_route = Route.from_string('kvta kvta') self.more50nm_route = Route.from_string('kvta kluk') self.no_land_more50nm_route = Route.from_string('kvta @kluk kvta') self.less50nm_route = Route.from_string('kvta kcmh') self.no_land_less50nm_route = Route.from_string('kvta @kcmh kvta') self.f = Flight(total=11.0, pic=10.0, date=today, route=self.local_route) def test_cat_class_columns(self): """ Tests that all the columns that deal with category/class output the correct value """ # multi engine land ######################################################### self.f.plane = self.baron self.f.save() self.failUnlessEqual(self.f.column('single'), "") self.failUnlessEqual(self.f.column('m_pic'), "10.0") self.failUnlessEqual(self.f.column('m_t'), "") # multi-sea local ######################################################### self.f.plane = self.seaplane self.f.save() self.failUnlessEqual(self.f.column('single'), "11.0") self.failUnlessEqual(self.f.column('m_pic'), "") self.failUnlessEqual(self.f.column('m_t'), "") def test_local_route_columns(self): """ Tests the columns that depend on the properties of the route when the route is a local flight """ self.f.route = self.local_route # vta vta self.f.save() self.failUnlessEqual(self.f.column('p2p'), "") self.failUnlessEqual(self.f.column('atp_xc'), "") self.failUnlessEqual(self.f.column('max_width'), "") self.failUnlessEqual(self.f.column('line_dist'), "") def test_less_50_nm_route(self): """ Tests the columns that depend on the properties of the route when the route is greater than 50nm """ self.f.route = self.less50nm_route # vta cmh self.f.save() self.failUnlessEqual(self.f.column('p2p'), "11.0") self.failUnlessEqual(self.f.column('atp_xc'), "") self.failUnlessEqual(self.f.column('max_width'), "19.9") self.failUnlessEqual(self.f.column('line_dist'), "19.9") self.f.route = self.no_land_less50nm_route # vta @cmh vta self.f.save() self.failUnlessEqual(self.f.column('p2p'), "") self.failUnlessEqual(self.f.column('atp_xc'), "") self.failUnlessEqual(self.f.column('max_width'), "19.9") self.failUnlessEqual(self.f.column('line_dist'), "39.7") def test_more_50_nm_route(self): """ Tests the columns that depend on the properties of the route when the route is less than 50nm """ self.f.route = self.no_land_more50nm_route # vta @luk vta self.f.save() self.failUnlessEqual(self.f.column('p2p'), "") self.failUnlessEqual(self.f.column('atp_xc'), "11.0") self.failUnlessEqual(self.f.column('max_width'), "106.5") self.failUnlessEqual(self.f.column('line_dist'), "212.5") self.f.route = self.more50nm_route # vta luk self.f.save() self.failUnlessEqual(self.f.column('p2p'), "11.0") self.failUnlessEqual(self.f.column('atp_xc'), "11.0") self.failUnlessEqual(self.f.column('max_width'), "106.5") self.failUnlessEqual(self.f.column('line_dist'), "106.2")
class FuelBurnTest(TestCase): def setUp(self): self.p = Plane(tailnumber="N444444", cat_class=4, type="TYPE") self.p.save() self.u = User(username='******') self.u.save() self.f = Flight(plane=self.p, route=Route.from_string('mer-lga'), user=self.u, date='2009-01-05', total=10.0, ) self.f.save() def test_regular_fuel_burn(self): self.f.fuel_burn = '98gph' self.f.save() self.failUnlessEqual(self.f.gallons, 980.0) self.failUnlessEqual(self.f.gph, 98) self.f.fuel_burn = '874.5 g' self.f.save() self.failUnlessEqual(self.f.gallons, 874.5) self.failUnlessEqual(self.f.gph, 87.45) def test_conversion(self): """ Test that teh conversion routines are accurate """ self.f.fuel_burn = '10 l' self.f.save() self.failUnlessEqual("%.2f" % self.f.gallons, "%.2f" % 2.64172052) self.f.fuel_burn = '60 pll' self.f.save() self.failUnlessEqual(self.f.gallons, 360) self.f.fuel_burn = '60p' self.f.save() self.failUnlessEqual(self.f.gallons, 408.0) def test_zero_fuel_burn(self): """ Test that the routine can handle fuel burns that are zero and where the time is zero """ self.f.fuel_burn = '0 gph' self.f.save() self.failUnlessEqual(self.f.gallons, 0) self.failUnlessEqual(self.f.gph, 0) self.f.fuel_burn = '56 g' self.f.total = 0 self.f.save() self.failUnlessEqual(self.f.gallons, 56) self.failUnlessEqual(self.f.gph, 0) self.f.fuel_burn = '56 gph' self.f.total = 0 self.f.save() self.failUnlessEqual(self.f.gallons, 0) self.failUnlessEqual(self.f.gph, 56)
class ReplyTest(TestCase): def setUp(self): level = Level(flavor="Plain", plane_life_span=3, max_today_write=3, max_today_reply=3, next_level_likes=10) level.save() user = user_model.User.objects.create_user(username='******', password='******') user.save() reply_user = user_model.User.objects.create_user( username='******', password='******') reply_user.save() self.user = User(user=user, today_write_count=10, today_reply_count=10, total_likes=10, level=level) self.user.save() self.reply_user = User(user=reply_user, today_write_count=10, today_reply_count=10, total_likes=10, level=level) self.reply_user.save() self.plane = Plane(author=self.user, content='content', tag='tag') self.plane.save() self.reply = Reply(plane_author=self.user, reply_author=self.reply_user, original_content='orig', original_tag='orig_tag', content='cont') self.reply.save() self.client = Client() def test_write_plane(self): self.client.login(username='******', password='******') data = { 'plane_author': self.user.id, 'original_content': self.plane.content, 'original_tag': self.plane.tag, 'content': 'reply-content' } response = self.client.post('/api/reply/new/', json.dumps(data), content_type='application/json') self.assertEqual(response.status_code, 201) def test_get_reply_not_exist(self): self.client.login(username='******', password='******') response = self.client.get('/api/reply/123/') self.assertEqual(response.status_code, 404) def test_get_reply_wrong_user(self): reply_id = self.reply.id self.client.login(username='******', password='******') response = self.client.get('/api/reply/{}/'.format(reply_id)) self.assertEqual(response.status_code, 403) def test_get_reply(self): reply_id = self.reply.id self.client.login(username='******', password='******') response = self.client.get('/api/reply/{}/'.format(reply_id)) self.assertEqual(response.status_code, 200) def test_get_reply_by_user_wrong_user(self): user_id = self.reply_user.id self.client.login(username='******', password='******') response = self.client.get('/api/reply/user/123/') data = json.loads(response.content.decode()) self.assertEqual(data, []) def test_get_reply_by_user(self): user_id = self.user.id self.client.login(username='******', password='******') response = self.client.get('/api/reply/user/{}/'.format(user_id)) data = json.loads(response.content.decode()) self.assertEqual(data[0]['content'], 'cont') def test_report_not_exist(self): self.client.login(username='******', password='******') data = {'reply_id': 123} response = self.client.put('/api/reply/report/', json.dumps(data), content_type='application/json') self.assertEqual(response.status_code, 404) def test_report_wrong_user(self): self.client.login(username='******', password='******') data = {'reply_id': self.reply.id} response = self.client.put('/api/reply/report/', json.dumps(data), content_type='application/json') self.assertEqual(response.status_code, 403) def test_report(self): self.client.login(username='******', password='******') data = {'reply_id': self.reply.id} response = self.client.put('/api/reply/report/', json.dumps(data), content_type='application/json') self.assertEqual(response.status_code, 200) def test_like_not_exist(self): self.client.login(username='******', password='******') data = {'reply_id': 123} response = self.client.put('/api/reply/like/', json.dumps(data), content_type='application/json') self.assertEqual(response.status_code, 404) def test_like_wrong_user(self): self.client.login(username='******', password='******') data = {'reply_id': self.reply.id} response = self.client.put('/api/reply/like/', json.dumps(data), content_type='application/json') self.assertEqual(response.status_code, 403) def test_like(self): self.client.login(username='******', password='******') data = {'reply_id': self.reply.id} response = self.client.put('/api/reply/like/', json.dumps(data), content_type='application/json') self.assertEqual(response.status_code, 200) def test_like_duplicated(self): self.client.login(username='******', password='******') data = {'reply_id': self.reply.id} self.reply.liked = True self.reply.save() response = self.client.put('/api/reply/like/', json.dumps(data), content_type='application/json') self.assertEqual(response.status_code, 406) def test_delete_not_exist(self): self.client.login(username='******', password='******') data = {'reply_id': 123} response = self.client.put('/api/reply/delete/', json.dumps(data), content_type='application/json') self.assertEqual(response.status_code, 404) def test_delete_wrong_user(self): self.client.login(username='******', password='******') data = {'reply_id': self.reply.id} response = self.client.put('/api/reply/delete/', json.dumps(data), content_type='application/json') self.assertEqual(response.status_code, 403) def test_delete(self): self.client.login(username='******', password='******') data = {'reply_id': self.reply.id} response = self.client.put('/api/reply/delete/', json.dumps(data), content_type='application/json') self.assertEqual(response.status_code, 200)
class FuelBurnTest(TestCase): def setUp(self): self.p = Plane(tailnumber="N444444", cat_class=4, type="TYPE") self.p.save() self.u = User(username='******') self.u.save() self.f = Flight( plane=self.p, route=Route.from_string('mer-lga'), user=self.u, date='2009-01-05', total=10.0, ) self.f.save() def test_regular_fuel_burn(self): self.f.fuel_burn = '98gph' self.f.save() self.failUnlessEqual(self.f.gallons, 980.0) self.failUnlessEqual(self.f.gph, 98) self.f.fuel_burn = '874.5 g' self.f.save() self.failUnlessEqual(self.f.gallons, 874.5) self.failUnlessEqual(self.f.gph, 87.45) def test_conversion(self): """ Test that teh conversion routines are accurate """ self.f.fuel_burn = '10 l' self.f.save() self.failUnlessEqual("%.2f" % self.f.gallons, "%.2f" % 2.64172052) self.f.fuel_burn = '60 pll' self.f.save() self.failUnlessEqual(self.f.gallons, 360) self.f.fuel_burn = '60p' self.f.save() self.failUnlessEqual(self.f.gallons, 408.0) def test_zero_fuel_burn(self): """ Test that the routine can handle fuel burns that are zero and where the time is zero """ self.f.fuel_burn = '0 gph' self.f.save() self.failUnlessEqual(self.f.gallons, 0) self.failUnlessEqual(self.f.gph, 0) self.f.fuel_burn = '56 g' self.f.total = 0 self.f.save() self.failUnlessEqual(self.f.gallons, 56) self.failUnlessEqual(self.f.gph, 0) self.f.fuel_burn = '56 gph' self.f.total = 0 self.f.save() self.failUnlessEqual(self.f.gallons, 0) self.failUnlessEqual(self.f.gph, 56)
class ColumnsTest(TestCase): fixtures = [ 'airport/test-fixtures/ohio.json', 'airport/test-fixtures/test-region.json', 'airport/test-fixtures/test-country.json' ] def setUp(self): import datetime today = datetime.date.today() self.u = User(username='******') self.u.save() self.baron = Plane(tailnumber="N1234", type='BE-55') self.baron.save() self.seaplane = Plane(tailnumber="N5678", cat_class=3) self.seaplane.save() self.local_route = Route.from_string('kvta kvta') self.more50nm_route = Route.from_string('kvta kluk') self.no_land_more50nm_route = Route.from_string('kvta @kluk kvta') self.less50nm_route = Route.from_string('kvta kcmh') self.no_land_less50nm_route = Route.from_string('kvta @kcmh kvta') self.f = Flight(total=11.0, pic=10.0, date=today, route=self.local_route) def test_cat_class_columns(self): """ Tests that all the columns that deal with category/class output the correct value """ # multi engine land ######################################################### self.f.plane = self.baron self.f.save() self.failUnlessEqual(self.f.column('single'), "") self.failUnlessEqual(self.f.column('m_pic'), "10.0") self.failUnlessEqual(self.f.column('m_t'), "") # multi-sea local ######################################################### self.f.plane = self.seaplane self.f.save() self.failUnlessEqual(self.f.column('single'), "11.0") self.failUnlessEqual(self.f.column('m_pic'), "") self.failUnlessEqual(self.f.column('m_t'), "") def test_local_route_columns(self): """ Tests the columns that depend on the properties of the route when the route is a local flight """ self.f.route = self.local_route # vta vta self.f.save() self.failUnlessEqual(self.f.column('p2p'), "") self.failUnlessEqual(self.f.column('atp_xc'), "") self.failUnlessEqual(self.f.column('max_width'), "") self.failUnlessEqual(self.f.column('line_dist'), "") def test_less_50_nm_route(self): """ Tests the columns that depend on the properties of the route when the route is greater than 50nm """ self.f.route = self.less50nm_route # vta cmh self.f.save() self.failUnlessEqual(self.f.column('p2p'), "11.0") self.failUnlessEqual(self.f.column('atp_xc'), "") self.failUnlessEqual(self.f.column('max_width'), "19.9") self.failUnlessEqual(self.f.column('line_dist'), "19.9") self.f.route = self.no_land_less50nm_route # vta @cmh vta self.f.save() self.failUnlessEqual(self.f.column('p2p'), "") self.failUnlessEqual(self.f.column('atp_xc'), "") self.failUnlessEqual(self.f.column('max_width'), "19.9") self.failUnlessEqual(self.f.column('line_dist'), "39.7") def test_more_50_nm_route(self): """ Tests the columns that depend on the properties of the route when the route is less than 50nm """ self.f.route = self.no_land_more50nm_route # vta @luk vta self.f.save() self.failUnlessEqual(self.f.column('p2p'), "") self.failUnlessEqual(self.f.column('atp_xc'), "11.0") self.failUnlessEqual(self.f.column('max_width'), "106.5") self.failUnlessEqual(self.f.column('line_dist'), "212.5") self.f.route = self.more50nm_route # vta luk self.f.save() self.failUnlessEqual(self.f.column('p2p'), "11.0") self.failUnlessEqual(self.f.column('atp_xc'), "11.0") self.failUnlessEqual(self.f.column('max_width'), "106.5") self.failUnlessEqual(self.f.column('line_dist'), "106.2")