Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 def test_get_pilots(self):
     self.assertEqual(len(util.get_pilots()), 0)
     
     pilot1 = helper.create_pilot('kim', 'Kim', 'Pilot1')
     pilot2 = helper.create_pilot('sam', 'Sam', 'Pilot2')
     pilot3 = helper.create_pilot('ada', 'Ada', 'Pilot0')
     
     expected = [pilot3, pilot1, pilot2]
     query = util.get_pilots()
     
     self.assertEqual([o for o in query], expected)
     
     user1 = User.objects.create_user('user', 'User', 'Non-Pilot')
     
     query = util.get_pilots()
     self.assertEqual([o for o in query], expected)
Exemplo n.º 3
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)
Exemplo n.º 4
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,
     )
Exemplo n.º 5
0
 def test_user_is_pilot(self):
     pilot_user = helper.create_pilot('pilot','Pilot','User')
     self.assertTrue(user_is_pilot(pilot_user))
     
     normal_user = User.objects.create_user(
                     'username',
                     '*****@*****.**',
                     'secret',
                     first_name='Normal',
                     last_name='User')
     self.assertFalse(user_is_pilot(normal_user))
Exemplo n.º 6
0
    def test_PilotDetail(self):
        url = reverse('pilot_detail', kwargs={'username':'******'})
        request = self.factory.get(url)

        # Anonymous
        request.user = AnonymousUser()
        response = PilotDetail.as_view()(request, username='******')
        self.assertEqual(response.status_code, 302)

        # Not anonymous, pilot does not exist
        request.user = self.regular_user
        with self.assertRaises(Http404):
            _ = PilotDetail.as_view()(request, username='******')

        # Not anonymous, pilot exists
        request.user = self.regular_user
        helper.create_pilot(username='******')
        response = PilotDetail.as_view()(request, username='******')
        self.assertIsNotNone(response.context_data['pilot'])
        self.assertIsNotNone(response.context_data['checkouts'])
Exemplo n.º 7
0
 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)
     c2 = helper.create_checkout(pilot=pilot2, airstrip=c1.airstrip, aircraft_type=c1.aircraft_type)
     
     results = [{
         'pilot_name': pilot1.full_name,
         'pilot_slug': pilot1.username,
         'airstrip_ident': c1.airstrip.ident,
         'airstrip_name': c1.airstrip.name,
         'actypes': {
             c1.aircraft_type.name: util.CHECKOUT_SUDAH,
         },
     },]
     
     self.expected['aircraft_types'] = [c1.aircraft_type.name,]
     self.expected['results'] = results
     
     self.assertEqual(util.pilot_checkouts_grouped_by_airstrip(pilot1), self.expected)
Exemplo n.º 8
0
    def test_PilotList(self):
        url = reverse('pilot_list')
        request = self.factory.get(url)

        # Anonymous
        request.user = AnonymousUser()
        response = PilotList.as_view()(request)
        self.assertEqual(response.status_code, 302)

        # Not anonymous, no pilots
        request.user = self.regular_user
        response = PilotList.as_view()(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context_data['pilot_list']), 0)

        # Not anonymous, two pilots
        request.user = self.regular_user
        helper.create_pilot(username='******')
        helper.create_pilot(username='******')
        response = PilotList.as_view()(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context_data['pilot_list']), 2)
Exemplo n.º 9
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)
Exemplo n.º 10
0
 def test_user_full_name(self):
     user = helper.create_pilot()
     expected = '%s, %s' % (user.last_name, user.first_name)
     self.assertEqual(user_full_name(user), expected)
     
     user.first_name = ''
     expected = user.username
     self.assertEqual(user_full_name(user), expected)
     
     user.first_name = 'Foo'
     user.last_name = ''
     self.assertEqual(user_full_name(user), expected)
     
     user.first_name = ''
     self.assertEqual(user_full_name(user), expected)
Exemplo n.º 11
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)
Exemplo n.º 12
0
 def setUp(self):
     self.pilot = helper.create_pilot()
     self.scheduler = helper.create_flight_scheduler()
Exemplo n.º 13
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)
Exemplo n.º 14
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)
Exemplo n.º 15
0
 def test_empty(self):
     pilot = helper.create_pilot()
     self.assertEqual(util.pilot_checkouts_grouped_by_airstrip(pilot), self.expected)
Exemplo n.º 16
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)