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_single_unprecedented(self): pilot = helper.create_pilot() airstrip = helper.create_airstrip() aircraft = helper.create_aircrafttype() expected = {} self.assertEqual(util.get_precedented_checkouts(), expected)
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, )
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)
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)
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_unicode(self): o, attributes = helper.create_aircrafttype(object_only=False) self.assertEqual(str(o), attributes['name'])