def test_multiple_aircrafttypes(self): actype1 = helper.create_aircrafttype('Name1') actype2 = helper.create_aircrafttype('Name2') c = helper.create_checkout(aircraft_type=actype1) expected = [{ 'pilot_name': c.pilot.full_name, 'pilot_slug': c.pilot.username, 'airstrip_ident': c.airstrip.ident, 'airstrip_name': c.airstrip.name, 'actypes': { actype1.name: util.CHECKOUT_SUDAH, actype2.name: util.CHECKOUT_BELUM, }, },] self.assertEqual(util.checkout_filter(), expected) # Testing what happens when limiting to a particular aircraft type expected[0]['actypes'].pop(actype2.name) self.assertEqual(util.checkout_filter(aircraft_type=actype1), expected) helper.create_checkout(aircraft_type=actype2, pilot=c.pilot, airstrip=c.airstrip) expected[0]['actypes'][actype2.name] = util.CHECKOUT_SUDAH self.assertEqual(util.checkout_filter(), expected)
def test_multiple_pilots(self): pilot1 = helper.create_pilot('kim', 'Kim', 'Pilot1') pilot2 = helper.create_pilot('sam', 'Sam', 'Pilot2') c1 = helper.create_checkout(pilot=pilot1) expected = [{ 'pilot_name': pilot1.full_name, 'pilot_slug': c1.pilot.username, 'airstrip_ident': c1.airstrip.ident, 'airstrip_name': c1.airstrip.name, 'actypes': { c1.aircraft_type.name: util.CHECKOUT_SUDAH, }, },] self.assertEqual(util.checkout_filter(), expected) c2 = helper.create_checkout(pilot=pilot2, airstrip=c1.airstrip, aircraft_type=c1.aircraft_type) r = { 'pilot_name': pilot2.full_name, 'pilot_slug': c2.pilot.username, 'airstrip_ident': c2.airstrip.ident, 'airstrip_name': c2.airstrip.name, 'actypes': { c2.aircraft_type.name: util.CHECKOUT_SUDAH, }, } expected.append(r) self.assertEqual(util.checkout_filter(), expected)
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)
def test_single_checkout(self): c = helper.create_checkout() expected = [{ 'pilot_name': c.pilot.full_name, 'pilot_slug': c.pilot.username, 'airstrip_ident': c.airstrip.ident, 'airstrip_name': c.airstrip.name, 'actypes': { c.aircraft_type.name: util.CHECKOUT_SUDAH, }, },] self.assertEqual(util.checkout_filter(), expected)
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)
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)
def test_empty(self): self.assertEqual(util.checkout_filter(), [])