Ejemplo n.º 1
0
 def test_multiple_airstrips(self):
     airstrip1 = helper.create_airstrip('ID1', 'Airstrip1')
     airstrip2 = helper.create_airstrip('ID2', 'Airstrip2')
     
     c = helper.create_checkout(airstrip=airstrip1)
     
     expected = [{
         'pilot_name': c.pilot.full_name,
         'pilot_slug': c.pilot.username,
         'airstrip_ident': airstrip1.ident,
         'airstrip_name': airstrip1.name,
         'actypes': {
             c.aircraft_type.name: util.CHECKOUT_SUDAH,
         },
     },]
     
     self.assertEqual(util.checkout_filter(), expected)
     
     helper.create_checkout(airstrip=airstrip2, pilot=c.pilot, aircraft_type=c.aircraft_type)
     r = {
         'pilot_name': c.pilot.full_name,
         'pilot_slug': c.pilot.username,
         'airstrip_ident': airstrip2.ident,
         'airstrip_name': airstrip2.name,
         'actypes': {
             c.aircraft_type.name: util.CHECKOUT_SUDAH,
         },
     }
     expected.append(r)
     
     self.assertEqual(util.checkout_filter(), expected)
Ejemplo n.º 2
0
 def test_unattached_airstrips(self):
     base1 = helper.create_airstrip('B1', is_base=True)
     # Single base, no airstrips
     self.assertEqual(base1.unattached_airstrips().count(), 0)
     
     airstrip1 = helper.create_airstrip('A1')
     airstrip2 = helper.create_airstrip('A2')
     # Single base, multiple airstrips
     self.assertEqual(base1.unattached_airstrips().count(), 2)
     
     airstrip1.bases.add(base1)
     # Single airstrip attached
     self.assertEqual(base1.unattached_airstrips().count(), 1)
     
     airstrip2.bases.add(base1)
     # Multiple airstrips attached
     self.assertEqual(base1.unattached_airstrips().count(), 0)
     
     base2 = helper.create_airstrip('B2', is_base=True)
     # Multiple bases, no attached airstrips
     self.assertEqual(base2.unattached_airstrips().count(), 3)
     
     airstrip1.bases.add(base2)
     # Multiple attached bases on airstrip
     self.assertEqual(base1.unattached_airstrips().count(), 1)
     self.assertEqual(base2.unattached_airstrips().count(), 2)
Ejemplo n.º 3
0
 def test_get_bases(self):
     self.assertEqual(len(util.get_bases()), 0)
     
     base1 = helper.create_airstrip('SCND', 'Second', is_base=True)
     base2 = helper.create_airstrip('FRST', 'First', is_base=True)
     base3 = helper.create_airstrip('THRD', 'Third', is_base=True)
     
     expected = [base2, base1, base3]
     query = util.get_bases()
     
     self.assertEqual([o for o in query], expected)
     
     airstrip1 = helper.create_airstrip('FRTH', 'Fourth', is_base=False)
     
     query = util.get_bases()
     self.assertEqual([o for o in query], expected)
Ejemplo n.º 4
0
 def test_single_unprecedented(self):
     pilot = helper.create_pilot()
     airstrip = helper.create_airstrip()
     aircraft = helper.create_aircrafttype()
     
     expected = {}
     
     self.assertEqual(util.get_precedented_checkouts(), expected)
Ejemplo n.º 5
0
 def setUp(self):
     self.pilot = helper.create_pilot()
     self.aircrafttype = helper.create_aircrafttype()
     self.airstrip = helper.create_airstrip()
     
     self.checkout = Checkout.objects.create(
         pilot = self.pilot,
         aircraft_type = self.aircrafttype,
         airstrip = self.airstrip,
     )
Ejemplo n.º 6
0
 def test_filtering_by_base(self):
     base1 = helper.create_airstrip('BASE', 'Base1', is_base=True)
     airstrip1 = helper.create_airstrip('ID1', 'Airstrip1')
     airstrip1.bases.add(base1)
     airstrip2 = helper.create_airstrip('ID2', 'Airstrip2')
     
     c = helper.create_checkout(airstrip=airstrip1)
     _ = helper.create_checkout(airstrip=airstrip2, pilot=c.pilot, aircraft_type=c.aircraft_type)
     
     expected = [{
         'pilot_name': c.pilot.full_name,
         'pilot_slug': c.pilot.username,
         'airstrip_ident': airstrip1.ident,
         'airstrip_name': airstrip1.name,
         'actypes': {
             c.aircraft_type.name: util.CHECKOUT_SUDAH,
         },
     },]
     
     self.assertEqual(util.checkout_filter(base=base1), expected)
Ejemplo n.º 7
0
 def test_multiple_pilots(self):
     airstrip1 = helper.create_airstrip('ID1', 'Airstrip1')
     airstrip2 = helper.create_airstrip('ID2', 'Airstrip2')
     
     c1 = helper.create_checkout(airstrip=airstrip1)
     c2 = helper.create_checkout(airstrip=airstrip2, pilot=c1.pilot, aircraft_type=c1.aircraft_type)
     
     results = [{
         'pilot_name': c1.pilot.full_name,
         'pilot_slug': c1.pilot.username,
         'airstrip_ident': airstrip1.ident,
         'airstrip_name': airstrip1.name,
         'actypes': {
             c1.aircraft_type.name: util.CHECKOUT_SUDAH,
         },
     },]
     
     self.expected['aircraft_types'] = [c1.aircraft_type.name,]
     self.expected['results'] = results
     
     self.assertEqual(util.airstrip_checkouts_grouped_by_pilot(airstrip1), self.expected)
Ejemplo n.º 8
0
 def test_multiple(self):
     pilot1 = helper.create_pilot('kim', 'Kim', 'Pilot1')
     pilot2 = helper.create_pilot('sam', 'Sam', 'Pilot2')
     airstrip1 = helper.create_airstrip('ID1', 'Airstrip1')
     airstrip2 = helper.create_airstrip('ID2', 'Airstrip2')
     
     expected = [
         (pilot1.username, airstrip1.ident),
         (pilot1.username, airstrip2.ident),
         (pilot2.username, airstrip1.ident),
         (pilot2.username, airstrip2.ident),
     ]
     self.assertEqual(util.get_pilot_airstrip_pairs(), expected)
     
     # Filter on Pilot
     expected = [
         (pilot1.username, airstrip1.ident),
         (pilot1.username, airstrip2.ident),
     ]
     self.assertEqual(util.get_pilot_airstrip_pairs(pilot=pilot1), expected)
     
     # Filter on Airstrip
     expected = [
         (pilot1.username, airstrip2.ident),
         (pilot2.username, airstrip2.ident),
     ]
     self.assertEqual(util.get_pilot_airstrip_pairs(airstrip=airstrip2), expected)
     
     # Filter on Base
     base1 = helper.create_airstrip('BASE', 'Base1', is_base=True)
     airstrip1.bases.add(base1)
     
     expected = [
         (pilot1.username, airstrip1.ident),
         (pilot2.username, airstrip1.ident),
     ]
     self.assertEqual(util.get_pilot_airstrip_pairs(base=base1), expected)
Ejemplo n.º 9
0
 def test_multiple(self):
     pilot1 = helper.create_pilot('kim', 'Kim', 'Pilot1')
     pilot2 = helper.create_pilot('sam', 'Sam', 'Pilot2')
     actype1 = helper.create_aircrafttype('Name1')    
     actype2 = helper.create_aircrafttype('Name2')
     airstrip1 = helper.create_airstrip('ID1', 'Airstrip1')
     airstrip2 = helper.create_airstrip('ID2', 'Airstrip2')
     airstrip3 = helper.create_airstrip('ID3', 'Airstrip3')
         
     c1 = helper.create_checkout(pilot=pilot1, airstrip=airstrip1, aircraft_type=actype1)
     c2 = helper.create_checkout(pilot=pilot1, airstrip=airstrip1, aircraft_type=actype2)
     c3 = helper.create_checkout(pilot=pilot2, airstrip=airstrip2, aircraft_type=actype1)
     
     expected = {
         airstrip1.ident: {
             actype1.name: True,
             actype2.name: True,
         },
         airstrip2.ident: {
             actype1.name: True,
         },
     }
     
     self.assertEqual(util.get_precedented_checkouts(), expected)
Ejemplo n.º 10
0
 def test_unicode(self):
     o, attributes = helper.create_airstrip(object_only=False)
     self.assertEqual(
         o.__unicode__(), 
         "%s (%s)" % (attributes['ident'], attributes['name'])
     ) 
Ejemplo n.º 11
0
 def test_with_data(self):
     pilot1 = helper.create_pilot('kim', 'Kim', 'Pilot1')
     pilot2 = helper.create_pilot('sam', 'Sam', 'Pilot2')
     actype1 = helper.create_aircrafttype('Name1')
     actype2 = helper.create_aircrafttype('Name2')
     airstrip1 = helper.create_airstrip('ID1', 'Airstrip1')
     airstrip2 = helper.create_airstrip('ID2', 'Airstrip2')
     airstrip3 = helper.create_airstrip('ID3', 'Airstrip3')
     
     c1 = helper.create_checkout(pilot=pilot1, airstrip=airstrip1, aircraft_type=actype1)
     c2 = helper.create_checkout(pilot=pilot1, airstrip=airstrip1, aircraft_type=actype2)
     c3 = helper.create_checkout(pilot=pilot2, airstrip=airstrip2, aircraft_type=actype1)
     
     results = [{
         'pilot_name': pilot1.full_name,
         'pilot_slug': pilot1.username,
         'airstrip_ident': airstrip2.ident,
         'airstrip_name': airstrip2.name,
         'actypes': {
             actype1.name: util.CHECKOUT_BELUM,
             actype2.name: util.CHECKOUT_UNPRECEDENTED,
         },
     }, {
         'pilot_name': pilot2.full_name,
         'pilot_slug': pilot2.username,
         'airstrip_ident': airstrip1.ident,
         'airstrip_name': airstrip1.name,
         'actypes': {
             actype1.name: util.CHECKOUT_BELUM,
             actype2.name: util.CHECKOUT_BELUM,
         },
     }, {
         'pilot_name': pilot2.full_name,
         'pilot_slug': pilot2.username,
         'airstrip_ident': airstrip2.ident,
         'airstrip_name': airstrip2.name,
         'actypes': {
             actype1.name: util.CHECKOUT_SUDAH,
             actype2.name: util.CHECKOUT_UNPRECEDENTED,
         },
     },]
     
     self.expected['aircraft_types'] = util.get_aircrafttype_names()
     self.expected['results'] = results
     
     self.assertEqual(util.belum_selesai(), self.expected)
     
     # Since we already have all these objects created, let's test the
     # 'belum selesai' filtering feature!
     self.expected['results'] = results[:1]
     self.assertEqual(util.belum_selesai(pilot=pilot1), self.expected)
     self.expected['results'] = results[1:]
     self.assertEqual(util.belum_selesai(pilot=pilot2), self.expected)
     self.expected['results'] = [results[1],]
     self.assertEqual(util.belum_selesai(airstrip=airstrip1), self.expected)
     self.expected['results'] = [r for i, r in enumerate(results) if i in (0,2)]
     self.assertEqual(util.belum_selesai(airstrip=airstrip2), self.expected)
     
     self.expected['results'] = results[:2]
     for r in self.expected['results']:
         r['actypes'].pop(actype2.name)
     self.expected['aircraft_types'] = [actype1.name,]
     self.assertEqual(util.belum_selesai(aircraft_type=actype1), self.expected)
Ejemplo n.º 12
0
 def test_single(self):
     pilot = helper.create_pilot()
     airstrip = helper.create_airstrip()
     
     expected = [(pilot.username, airstrip.ident)]
     self.assertEqual(util.get_pilot_airstrip_pairs(), expected)
Ejemplo n.º 13
0
 def test_empty(self):
     airstrip = helper.create_airstrip()
     self.assertEqual(util.airstrip_checkouts_grouped_by_pilot(airstrip), self.expected)
Ejemplo n.º 14
0
 def test_multiple_all(self):
     pilot1 = helper.create_pilot('kim', 'Kim', 'Pilot1')
     pilot2 = helper.create_pilot('sam', 'Sam', 'Pilot2')
     actype1 = helper.create_aircrafttype('Name1')    
     actype2 = helper.create_aircrafttype('Name2')
     airstrip1 = helper.create_airstrip('ID1', 'Airstrip1')
     airstrip2 = helper.create_airstrip('ID2', 'Airstrip2')
         
     c1 = helper.create_checkout(pilot=pilot1, airstrip=airstrip1, aircraft_type=actype1)
     c2 = helper.create_checkout(pilot=pilot1, airstrip=airstrip1, aircraft_type=actype2)
     c3 = helper.create_checkout(pilot=pilot1, airstrip=airstrip2, aircraft_type=actype1)
     c3 = helper.create_checkout(pilot=pilot1, airstrip=airstrip2, aircraft_type=actype2)
     c4 = helper.create_checkout(pilot=pilot2, airstrip=airstrip1, aircraft_type=actype1)
     c5 = helper.create_checkout(pilot=pilot2, airstrip=airstrip1, aircraft_type=actype2)
     c6 = helper.create_checkout(pilot=pilot2, airstrip=airstrip2, aircraft_type=actype1)
     c7 = helper.create_checkout(pilot=pilot2, airstrip=airstrip2, aircraft_type=actype2)
     
     expected = [{
         'pilot_name': pilot1.full_name,
         'pilot_slug': pilot1.username,
         'airstrip_ident': airstrip1.ident,
         'airstrip_name': airstrip1.name,
         'actypes': {
             actype1.name: util.CHECKOUT_SUDAH,
             actype2.name: util.CHECKOUT_SUDAH,
         },
     }, {
         'pilot_name': pilot1.full_name,
         'pilot_slug': pilot1.username,
         'airstrip_ident': airstrip2.ident,
         'airstrip_name': airstrip2.name,
         'actypes': {
             actype1.name: util.CHECKOUT_SUDAH,
             actype2.name: util.CHECKOUT_SUDAH,
         },
     }, {
         'pilot_name': pilot2.full_name,
         'pilot_slug': pilot2.username,
         'airstrip_ident': airstrip1.ident,
         'airstrip_name': airstrip1.name,
         'actypes': {
             actype1.name: util.CHECKOUT_SUDAH,
             actype2.name: util.CHECKOUT_SUDAH,
         },
     }, {
         'pilot_name': pilot2.full_name,
         'pilot_slug': pilot2.username,
         'airstrip_ident': airstrip2.ident,
         'airstrip_name': airstrip2.name,
         'actypes': {
             actype1.name: util.CHECKOUT_SUDAH,
             actype2.name: util.CHECKOUT_SUDAH,
         },
     },]
     
     self.assertEqual(util.checkout_filter(), expected)
     
     # Since we already have all these objects created, let's test the
     # filtering feature!
     self.assertEqual(util.checkout_filter(pilot=pilot1), expected[:2])
     self.assertEqual(util.checkout_filter(pilot=pilot2), expected[2:])
     t = [r for i, r in enumerate(expected) if i in (0,2)]
     self.assertEqual(util.checkout_filter(airstrip=airstrip1), t)
     t = [r for i, r in enumerate(expected) if i in (1,3)]
     self.assertEqual(util.checkout_filter(airstrip=airstrip2), t)
     
     c1.delete()
     expected = expected[1:]
     for e in expected:
        e['actypes'].pop(actype2.name)
     self.assertEqual(util.checkout_filter(aircraft_type=actype1), expected)