Ejemplo n.º 1
0
    def test_get_user(self):
        """UNIT test: services.accounts.utils - user from HTTP request
        Should extract the user object and username from a HTTP request
        """
        username = '******'
        user_profile = db_tools.create_user_profile(
            username=username
        )
        http_request = db_tools.create_request(user_profile=user_profile)
        username_2 = 'another'
        user_profile_2 = db_tools.create_user_profile(
            username=username_2
        )

        self.assertEqual(
            account_models.get_user(
                http_request=http_request,
                permissions_flag=False,
                test_username=username,
                testing_flag=False
            ),
            (user_profile, username),
            'Error extracing the user data from HTTP request'
        )

        self.assertEqual(
            account_models.get_user(
                http_request=http_request,
                permissions_flag=False,
                test_username=username_2,
                testing_flag=False
            ),
            (user_profile_2, username_2),
            'Error extracting the user data when no HTTP request is given'
        )
Ejemplo n.º 2
0
def create(identifier, callsign, elevation, latitude, longitude, **kwargs):
    """JRPC method: configuration.gs.create
    Creates a new ground station with the given configuration.

    :param identifier: Identifier of the Ground Station
    :param callsign: Callsign string of the Ground Station
    :param elevation: Minimum contact elevation
    :param latitude: Latitude of the location
    :param longitude: Longitude of the location
    :param kwargs: Additional JRPC parameters dictionary
    """

    user, username = account_models.get_user(
        http_request=kwargs.get('request', None)
    )

    gs = segment_models.GroundStation.objects.create(
        latitude=latitude,
        longitude=longitude,
        identifier=identifier,
        callsign=callsign,
        contact_elevation=elevation,
        username=username
    )

    return {
        segment_serializers.GS_ID_K: str(gs.identifier)
    }
Ejemplo n.º 3
0
def create(identifier, callsign, tle_id, **kwargs):
    """JRPC test: configuration.sc.create
    Creates a new ground station with the given configuration.
    User name must be obtained from the request, since this has already been
    validated by the authentication backend

    :param identifier: Identifier of the Spacecraft
    :param callsign: Callsign string of the Spacecraft
    :param tle_id: Identifier of the TLE associated with the Spacecraft
    :param kwargs: Additional JRPC parameters dictionary
    """

    try:

        user, username = account_models.get_user(
            http_request=kwargs.get('request', None)
        )

        sc = segments.Spacecraft.objects.create(
            tle_id,
            username=username,
            identifier=identifier,
            callsign=callsign
        )

    except Exception as ex:

        logger.exception(ex)
        raise ex

    return {
        segment_serializers.SC_ID_K: str(sc.identifier)
    }
Ejemplo n.º 4
0
def create(identifier, callsign, tle_id, **kwargs):
    """JRPC test: configuration.sc.create
    Creates a new ground station with the given configuration.
    User name must be obtained from the request, since this has already been
    validated by the authentication backend

    :param identifier: Identifier of the Spacecraft
    :param callsign: Callsign string of the Spacecraft
    :param tle_id: Identifier of the TLE associated with the Spacecraft
    :param kwargs: Additional JRPC parameters dictionary
    """

    try:

        user, username = account_models.get_user(
            http_request=kwargs.get('request', None))

        sc = segments.Spacecraft.objects.create(tle_id,
                                                username=username,
                                                identifier=identifier,
                                                callsign=callsign)

    except Exception as ex:

        logger.exception(ex)
        raise ex

    return {segment_serializers.SC_ID_K: str(sc.identifier)}
Ejemplo n.º 5
0
def current_user(**kwargs):
    """JRPC method
    Retrieves the username for the currently logged user
    :param kwargs: Necessary to access to the HTTP request object
    :return: String with the name of the currently logged user
    """
    user, username = account_models.get_user(
        http_request=kwargs.get('request', None))

    return username
Ejemplo n.º 6
0
def current_user(**kwargs):
    """JRPC method
    Retrieves the username for the currently logged user
    :param kwargs: Necessary to access to the HTTP request object
    :return: String with the name of the currently logged user
    """
    user, username = account_models.get_user(
        http_request=kwargs.get('request', None)
    )

    return username
Ejemplo n.º 7
0
def list_groundstations_others(**kwargs):
    """JRPC test: configuration.gs.list.mine
    Creates a list with the identifiers of the groundstations that belong to the
    user that is making the remote call.

    :param kwargs: Additional JRPC parameters dictionary
    :return:
    """
    # 1) user must be obtained from the request
    user, username = account_models.get_user(
        http_request=kwargs.get('request', None))
    # 2) only the groundstations that belong to the incoming user are excluded
    return [
        str(s.identifier)
        for s in segment_models.GroundStation.objects.exclude(user=user)
    ]
Ejemplo n.º 8
0
def list_spacecraft_mine(**kwargs):
    """JRPC test: configuration.sc.list.mine
    Creates a list with the identifiers of the spacecraft that belong to the
    user that is making the remote call.

    :param kwargs: Additional JRPC parameters dictionary
    :return:
    """
    # 1) user must be obtained from the request
    user, username = account_models.get_user(
        http_request=kwargs.get('request', None))
    # 2) only the spacecraft that belong to the incoming user are returned
    return [
        str(s.identifier)
        for s in segments.Spacecraft.objects.filter(user=user)
    ]
Ejemplo n.º 9
0
def list_groundstations_others(**kwargs):
    """JRPC test: configuration.gs.list.mine
    Creates a list with the identifiers of the groundstations that belong to the
    user that is making the remote call.

    :param kwargs: Additional JRPC parameters dictionary
    :return:
    """
    # 1) user must be obtained from the request
    user, username = account_models.get_user(
        http_request=kwargs.get('request', None)
    )
    # 2) only the groundstations that belong to the incoming user are excluded
    return [
        str(s.identifier) for s in segment_models.GroundStation.objects.exclude(
            user=user
        )
    ]
Ejemplo n.º 10
0
def list_spacecraft_mine(**kwargs):
    """JRPC test: configuration.sc.list.mine
    Creates a list with the identifiers of the spacecraft that belong to the
    user that is making the remote call.

    :param kwargs: Additional JRPC parameters dictionary
    :return:
    """
    # 1) user must be obtained from the request
    user, username = account_models.get_user(
        http_request=kwargs.get('request', None)
    )
    # 2) only the spacecraft that belong to the incoming user are returned
    return [
        str(s.identifier) for s in segments.Spacecraft.objects.filter(
            user=user
        )
    ]
Ejemplo n.º 11
0
def create(identifier, callsign, elevation, latitude, longitude, **kwargs):
    """JRPC method: configuration.gs.create
    Creates a new ground station with the given configuration.

    :param identifier: Identifier of the Ground Station
    :param callsign: Callsign string of the Ground Station
    :param elevation: Minimum contact elevation
    :param latitude: Latitude of the location
    :param longitude: Longitude of the location
    :param kwargs: Additional JRPC parameters dictionary
    """

    user, username = account_models.get_user(
        http_request=kwargs.get('request', None))

    gs = segment_models.GroundStation.objects.create(
        latitude=latitude,
        longitude=longitude,
        identifier=identifier,
        callsign=callsign,
        contact_elevation=elevation,
        username=username)

    return {segment_serializers.GS_ID_K: str(gs.identifier)}