예제 #1
0
    def test_list_groundstations(self):
        """JRPC test: services.leop.groundstations.list
        Checks the functioning of the JRPC method that returns the list of
        GroundStations available for the administrator to create a LEOP system.
        """

        # Permissions basic test, no request, no permission
        try:
            launch_jrpc.list_groundstations('FAKE_ID', **{'request': None})
            self.fail('No request added, permission should not be granted')
        except django_ex.PermissionDenied:
            pass

        # First step: user is not staff, access forbidden...
        try:
            launch_jrpc.list_groundstations(
                self.__leop_id, **{'request': self.__request_1}
            )
            self.fail('User is not staff, permission should not be granted')
        except django_ex.PermissionDenied:
            pass

        # Second step: user is staff, therefore access should be granted
        e_gs = {
            launch_serial.JRPC_K_AVAILABLE_GS: [
                self.__gs_1_id, self.__gs_2_id
            ],
            launch_serial.JRPC_K_IN_USE_GS: []
        }

        try:
            a_gs = launch_jrpc.list_groundstations(
                self.__leop_id, **{'request': self.__request_2}
            )
            self.assertEqual(a_gs, e_gs)
        except django_ex.PermissionDenied:
            self.fail('User is staff, permission should have been granted')

        # Third step: one of the ground stations is added to the cluster, it
        # should not appear as available, only as in use.
        launch_jrpc.add_groundstations(
            self.__leop_id, groundstations=[self.__gs_1_id],
            **{'request': self.__request_2}
        )
        e_gs = {
            launch_serial.JRPC_K_AVAILABLE_GS: [self.__gs_2_id],
            launch_serial.JRPC_K_IN_USE_GS: [self.__gs_1_id]
        }
        a_gs = launch_jrpc.list_groundstations(
            self.__leop_id, **{'request': self.__request_2}
        )

        self.assertEqual(a_gs, e_gs)
예제 #2
0
    def test_remove_groundstations(self):
        """JRPC test: services.leop.groundstations.remove
        Validates the removal of an array of GroundStations to a given LEOP
        cluster.
        """

        # Permissions test (1): no request, no permission
        self.assertRaises(django_ex.PermissionDenied,
                          launch_jrpc.remove_groundstations, 'FAKE_ID', None,
                          **{'request': None})

        # Permissions test (2): user not authorized
        self.assertRaises(django_ex.PermissionDenied,
                          launch_jrpc.remove_groundstations, 'FAKE', None,
                          **{'request': self.__request_1})

        # Basic parameters test (1)
        self.assertRaises(launch_models.Launch.DoesNotExist,
                          launch_jrpc.remove_groundstations, 'FAKE', ['fake'],
                          **{'request': self.__request_2})

        # Basic parameters test (2)
        actual = launch_jrpc.remove_groundstations(
            self.__leop_id, None, **{'request': self.__request_2})
        expected = {launch_serial.JRPC_K_LEOP_ID: self.__leop_id}
        self.assertEqual(actual, expected)

        # Basic parameters test (3)
        actual = launch_jrpc.remove_groundstations(
            self.__leop_id, [], **{'request': self.__request_2})
        expected = {launch_serial.JRPC_K_LEOP_ID: self.__leop_id}
        self.assertEqual(actual, expected)

        # First, we add two groundstations to the cluster and we try to remove
        # them later.
        gss = [self.__gs_1_id, self.__gs_2_id]
        launch_jrpc.add_groundstations(self.__leop_id, gss,
                                       **{'request': self.__request_2})
        cluster = launch_models.Launch.objects.get(identifier=self.__leop_id)
        self.assertEqual(
            len(cluster.groundstations.all()), 2,
            'Two groundstations should be part of this cluster object')

        self.assertTrue(
            launch_jrpc.remove_groundstations(self.__leop_id, gss,
                                              **{'request': self.__request_2}),
            'Should have returned True')
        self.assertEqual(
            len(cluster.groundstations.all()), 0,
            'No groundstations should be part of this cluster object')
예제 #3
0
    def test_list_groundstations(self):
        """JRPC test: services.leop.groundstations.list
        Checks the functioning of the JRPC method that returns the list of
        GroundStations available for the administrator to create a LEOP system.
        """

        # Permissions basic test, no request, no permission
        try:
            launch_jrpc.list_groundstations('FAKE_ID', **{'request': None})
            self.fail('No request added, permission should not be granted')
        except django_ex.PermissionDenied:
            pass

        # First step: user is not staff, access forbidden...
        try:
            launch_jrpc.list_groundstations(self.__leop_id,
                                            **{'request': self.__request_1})
            self.fail('User is not staff, permission should not be granted')
        except django_ex.PermissionDenied:
            pass

        # Second step: user is staff, therefore access should be granted
        e_gs = {
            launch_serial.JRPC_K_AVAILABLE_GS:
            [self.__gs_1_id, self.__gs_2_id],
            launch_serial.JRPC_K_IN_USE_GS: []
        }

        try:
            a_gs = launch_jrpc.list_groundstations(
                self.__leop_id, **{'request': self.__request_2})
            self.assertEqual(a_gs, e_gs)
        except django_ex.PermissionDenied:
            self.fail('User is staff, permission should have been granted')

        # Third step: one of the ground stations is added to the cluster, it
        # should not appear as available, only as in use.
        launch_jrpc.add_groundstations(self.__leop_id,
                                       groundstations=[self.__gs_1_id],
                                       **{'request': self.__request_2})
        e_gs = {
            launch_serial.JRPC_K_AVAILABLE_GS: [self.__gs_2_id],
            launch_serial.JRPC_K_IN_USE_GS: [self.__gs_1_id]
        }
        a_gs = launch_jrpc.list_groundstations(self.__leop_id,
                                               **{'request': self.__request_2})

        self.assertEqual(a_gs, e_gs)
예제 #4
0
    def test_get_passes(self):
        """JRPC test: services.leop.getPasses
        Validates the retrieval of the passes for this launch.
        """
        self.assertEqual(
            launch_jrpc.get_pass_slots(self.__leop_id),
            [],
            'No passes should have been inserted yet'
        )

        self.assertEqual(
            launch_jrpc.add_groundstations(
                self.__leop_id, [self.__gs_1_id],
                **{'request': self.__request_2}
            ),
            {launch_serial.JRPC_K_LEOP_ID: self.__leop_id},
            'Should have returned launch identifier'
        )

        # 1 ufo gets identified, generates pass slots...
        launch_jrpc.add_unknown(self.__leop_id, self.__ufo_id)
        launch_jrpc.identify(
            self.__leop_id, self.__ufo_id, self.__ufo_callsign,
            self.__ufo_tle_l1, self.__ufo_tle_l2
        )

        slots = launch_jrpc.get_pass_slots(self.__leop_id)
        self.assertNotEqual(
            len(slots), 0, 'Pass slots should have been created'
        )
예제 #5
0
    def test_add_groundstations(self):
        """JRPC test: services.leop.groundstations.add
        Validates the addition of an array of GroundStations to a given LEOP
        cluster.
        """
        # Permissions test (1): no request, no permission
        try:
            launch_jrpc.add_groundstations(
                'FAKE_ID', None, **{'request': None}
            )
            self.fail('No request added, permission should not be granted')
        except django_ex.PermissionDenied:
            pass
        # Permissions test (2): user not authorized
        try:
            launch_jrpc.add_groundstations(
                'FAKE', None, **{'request': self.__request_1}
            )
            self.fail('No request added, permission should not be granted')
        except django_ex.PermissionDenied:
            pass
        # Basic parameters test (1)
        try:
            launch_jrpc.add_groundstations(
                'FAKE', ['fake'], **{'request': self.__request_2}
            )
            self.fail('The leop cluster does not exist')
        except launch_models.Launch.DoesNotExist:
            pass

        # Basic parameters test (2)
        self.assertRaises(
            Exception,
            launch_jrpc.add_groundstations,
            None, **{'request': self.__request_2}
        )

        # GroundStations array []
        gss = [self.__gs_1_id, self.__gs_2_id]
        actual = launch_jrpc.add_groundstations(
            self.__leop_id, gss, **{'request': self.__request_2}
        )
        expected = {launch_serial.JRPC_K_LEOP_ID: self.__leop_id}
        self.assertEqual(actual, expected)

        cluster = launch_models.Launch.objects.get(identifier=self.__leop_id)
        self.assertEqual(
            len(cluster.groundstations.all()), 2,
            'Two groundstations should be part of this cluster object'
        )
예제 #6
0
    def test_add_groundstations(self):
        """JRPC test: services.leop.groundstations.add
        Validates the addition of an array of GroundStations to a given LEOP
        cluster.
        """
        # Permissions test (1): no request, no permission
        try:
            launch_jrpc.add_groundstations('FAKE_ID', None,
                                           **{'request': None})
            self.fail('No request added, permission should not be granted')
        except django_ex.PermissionDenied:
            pass
        # Permissions test (2): user not authorized
        try:
            launch_jrpc.add_groundstations('FAKE', None,
                                           **{'request': self.__request_1})
            self.fail('No request added, permission should not be granted')
        except django_ex.PermissionDenied:
            pass
        # Basic parameters test (1)
        try:
            launch_jrpc.add_groundstations('FAKE', ['fake'],
                                           **{'request': self.__request_2})
            self.fail('The leop cluster does not exist')
        except launch_models.Launch.DoesNotExist:
            pass

        # Basic parameters test (2)
        self.assertRaises(Exception, launch_jrpc.add_groundstations, None,
                          **{'request': self.__request_2})

        # GroundStations array []
        gss = [self.__gs_1_id, self.__gs_2_id]
        actual = launch_jrpc.add_groundstations(
            self.__leop_id, gss, **{'request': self.__request_2})
        expected = {launch_serial.JRPC_K_LEOP_ID: self.__leop_id}
        self.assertEqual(actual, expected)

        cluster = launch_models.Launch.objects.get(identifier=self.__leop_id)
        self.assertEqual(
            len(cluster.groundstations.all()), 2,
            'Two groundstations should be part of this cluster object')
예제 #7
0
    def test_get_passes(self):
        """JRPC test: services.leop.getPasses
        Validates the retrieval of the passes for this launch.
        """
        self.assertEqual(launch_jrpc.get_pass_slots(self.__leop_id), [],
                         'No passes should have been inserted yet')

        self.assertEqual(
            launch_jrpc.add_groundstations(self.__leop_id, [self.__gs_1_id],
                                           **{'request': self.__request_2}),
            {launch_serial.JRPC_K_LEOP_ID: self.__leop_id},
            'Should have returned launch identifier')

        # 1 ufo gets identified, generates pass slots...
        launch_jrpc.add_unknown(self.__leop_id, self.__ufo_id)
        launch_jrpc.identify(self.__leop_id, self.__ufo_id,
                             self.__ufo_callsign, self.__ufo_tle_l1,
                             self.__ufo_tle_l2)

        slots = launch_jrpc.get_pass_slots(self.__leop_id)
        self.assertNotEqual(len(slots), 0,
                            'Pass slots should have been created')
예제 #8
0
    def _test_get_messages(self):
        """JRPC test: services.leop.getMessages
        Validates the retrieval of messages from the server.
        """
        # 1) interface robustness
        self.assertRaises(
            launch_models.Launch.DoesNotExist,
            messages_jrpc.get_messages, 'DOESNTEXIST', 'nulldate'
        )
        self.assertRaises(
            Exception, messages_jrpc.get_messages, self.__leop_id, None
        )
        self.assertRaises(
            Exception, messages_jrpc.get_messages, self.__leop_id, None
        )
        self.assertRaises(
            Exception, messages_jrpc.get_messages, self.__leop_id, 'null'
        )

        # 2) basic empty response
        self.assertEqual(
            messages_jrpc.get_messages(
                self.__leop_id, '2002-12-26T00:00:00-06:39'
            ),
            [],
            'No messages, an empty array should have been returned'
        )

        # 3) feeding 1 message, should be retrieved
        # 3.a) gs created and added to the launch
        self.assertEqual(
            launch_jrpc.add_groundstations(
                self.__leop_id, [self.__gs_1_id],
                **{'request': self.__request_2}
            ),
            {launch_serial.JRPC_K_LEOP_ID: self.__leop_id},
            'The identifier of the Launch should have been returned'
        )

        # 3.b) database fed with fake data frame
        message_1 = db_tools.create_message(self.__gs_1)

        # 3.c) service finally invoked
        yesterday = misc.get_now_utc() - datetime.timedelta(days=1)
        actual = messages_jrpc.get_messages(
            self.__leop_id, yesterday.isoformat()
        )
        expected = [{
            launch_serial.JRPC_K_GS_ID: self.__gs_1_id,
            messages_serial.JRPC_K_TS: message_1.groundstation_timestamp,
            messages_serial.JRPC_K_MESSAGE: db_tools.MESSAGE__1_TEST
        }]
        self.assertEqual(actual, expected)

        # 4) multiple groundstations:
        # 4.a) gs created and added to the launch
        self.assertEqual(
            launch_jrpc.add_groundstations(
                self.__leop_id, [self.__gs_2_id],
                **{'request': self.__request_2}
            ),
            {launch_serial.JRPC_K_LEOP_ID: self.__leop_id},
            'The identifier of the Launch should have been returned'
        )

        # 3.b) database fed with fake data frame
        message_2 = db_tools.create_message(
            self.__gs_2, message=db_tools.MESSAGE_BASE64
        )

        # 3.c) service finally invoked
        yesterday = misc.get_now_utc() - datetime.timedelta(days=1)
        actual = messages_jrpc.get_messages(
            self.__leop_id, yesterday.isoformat()
        )
        expected.append({
            launch_serial.JRPC_K_GS_ID: self.__gs_2_id,
            messages_serial.JRPC_K_TS: message_2.groundstation_timestamp,
            messages_serial.JRPC_K_MESSAGE: db_tools.MESSAGE_BASE64.decode()
        })

        self.assertEqual(actual, expected)
예제 #9
0
    def test_remove_groundstations(self):
        """JRPC test: services.leop.groundstations.remove
        Validates the removal of an array of GroundStations to a given LEOP
        cluster.
        """

        # Permissions test (1): no request, no permission
        self.assertRaises(
            django_ex.PermissionDenied,
            launch_jrpc.remove_groundstations,
            'FAKE_ID', None, **{'request': None}
        )

        # Permissions test (2): user not authorized
        self.assertRaises(
            django_ex.PermissionDenied,
            launch_jrpc.remove_groundstations,
            'FAKE', None, **{'request': self.__request_1}
        )

        # Basic parameters test (1)
        self.assertRaises(
            launch_models.Launch.DoesNotExist,
            launch_jrpc.remove_groundstations,
            'FAKE', ['fake'], **{'request': self.__request_2}
        )

        # Basic parameters test (2)
        actual = launch_jrpc.remove_groundstations(
            self.__leop_id, None, **{'request': self.__request_2}
        )
        expected = {launch_serial.JRPC_K_LEOP_ID: self.__leop_id}
        self.assertEqual(actual, expected)

        # Basic parameters test (3)
        actual = launch_jrpc.remove_groundstations(
            self.__leop_id, [], **{'request': self.__request_2}
        )
        expected = {launch_serial.JRPC_K_LEOP_ID: self.__leop_id}
        self.assertEqual(actual, expected)

        # First, we add two groundstations to the cluster and we try to remove
        # them later.
        gss = [self.__gs_1_id, self.__gs_2_id]
        launch_jrpc.add_groundstations(
            self.__leop_id, gss, **{'request': self.__request_2}
        )
        cluster = launch_models.Launch.objects.get(identifier=self.__leop_id)
        self.assertEqual(
            len(cluster.groundstations.all()), 2,
            'Two groundstations should be part of this cluster object'
        )

        self.assertTrue(
            launch_jrpc.remove_groundstations(
                self.__leop_id, gss, **{'request': self.__request_2}
            ),
            'Should have returned True'
        )
        self.assertEqual(
            len(cluster.groundstations.all()), 0,
            'No groundstations should be part of this cluster object'
        )
예제 #10
0
    def _test_get_messages(self):
        """JRPC test: services.leop.getMessages
        Validates the retrieval of messages from the server.
        """
        # 1) interface robustness
        self.assertRaises(launch_models.Launch.DoesNotExist,
                          messages_jrpc.get_messages, 'DOESNTEXIST',
                          'nulldate')
        self.assertRaises(Exception, messages_jrpc.get_messages,
                          self.__leop_id, None)
        self.assertRaises(Exception, messages_jrpc.get_messages,
                          self.__leop_id, None)
        self.assertRaises(Exception, messages_jrpc.get_messages,
                          self.__leop_id, 'null')

        # 2) basic empty response
        self.assertEqual(
            messages_jrpc.get_messages(self.__leop_id,
                                       '2002-12-26T00:00:00-06:39'), [],
            'No messages, an empty array should have been returned')

        # 3) feeding 1 message, should be retrieved
        # 3.a) gs created and added to the launch
        self.assertEqual(
            launch_jrpc.add_groundstations(self.__leop_id, [self.__gs_1_id],
                                           **{'request': self.__request_2}),
            {launch_serial.JRPC_K_LEOP_ID: self.__leop_id},
            'The identifier of the Launch should have been returned')

        # 3.b) database fed with fake data frame
        message_1 = db_tools.create_message(self.__gs_1)

        # 3.c) service finally invoked
        yesterday = misc.get_now_utc() - datetime.timedelta(days=1)
        actual = messages_jrpc.get_messages(self.__leop_id,
                                            yesterday.isoformat())
        expected = [{
            launch_serial.JRPC_K_GS_ID: self.__gs_1_id,
            messages_serial.JRPC_K_TS: message_1.groundstation_timestamp,
            messages_serial.JRPC_K_MESSAGE: db_tools.MESSAGE__1_TEST
        }]
        self.assertEqual(actual, expected)

        # 4) multiple groundstations:
        # 4.a) gs created and added to the launch
        self.assertEqual(
            launch_jrpc.add_groundstations(self.__leop_id, [self.__gs_2_id],
                                           **{'request': self.__request_2}),
            {launch_serial.JRPC_K_LEOP_ID: self.__leop_id},
            'The identifier of the Launch should have been returned')

        # 3.b) database fed with fake data frame
        message_2 = db_tools.create_message(self.__gs_2,
                                            message=db_tools.MESSAGE_BASE64)

        # 3.c) service finally invoked
        yesterday = misc.get_now_utc() - datetime.timedelta(days=1)
        actual = messages_jrpc.get_messages(self.__leop_id,
                                            yesterday.isoformat())
        expected.append({
            launch_serial.JRPC_K_GS_ID:
            self.__gs_2_id,
            messages_serial.JRPC_K_TS:
            message_2.groundstation_timestamp,
            messages_serial.JRPC_K_MESSAGE:
            db_tools.MESSAGE_BASE64.decode()
        })

        self.assertEqual(actual, expected)