Ejemplo n.º 1
0
 def test_parse_bool_value_with_rejected_args(self):
     rejected_args = (3, -1, "", "True", "False", "yes", "no", "33", "-11",
                      [], (), {}, None)
     for arg in rejected_args:
         with self.assertRaisesRegex(ValueError,
                                     'Unacceptable bool value.'):
             U.parse_bool_value(arg)
Ejemplo n.º 2
0
 def test_parse_bool_value_with_rejected_args(self):
     rejected_args = (3, -1, "", "True", "False", "yes", "no", "33", "-11",
                      [], (), {}, None)
     for arg in rejected_args:
         try:
             U.parse_bool_value(arg)
         except ValueError as e:
             self.assertEqual(str(e), 'Unacceptable bool value.')
         except Exception:
             self.fail("Unexcept error occurs.")
         else:
             self.fail("Missing validations for %s" % arg)
Ejemplo n.º 3
0
 def test_parse_bool_value_with_rejected_args(self):
     rejected_args = (3, -1, "", "True", "False", "yes", "no", "33",
                      "-11", [], (), {}, None)
     for arg in rejected_args:
         try:
             U.parse_bool_value(arg)
         except ValueError as e:
             self.assertEqual(str(e), 'Unacceptable bool value.')
         except Exception:
             self.fail("Unexcept error occurs.")
         else:
             self.fail("Missing validations for %s" % arg)
Ejemplo n.º 4
0
Archivo: env.py Proyecto: jetlyb/Kiwi
def filter_groups(query):
    """
    .. function:: XML-RPC Env.filter_groups(query)

        Perform a search and return the resulting list of env groups.
        Parameter ``query`` is dict which recognizes the following
        keys:

        :param id: ID of env group
        :type id: int
        :param name: Name of env group
        :type name: str
        :param manager: Manager of this group. ForeignKey!
        :type manager: int or ``settings.AUTH_USER_MODEL`` object
        :param modified_by: Who modified the group. ForeignKey!
        :type modified_by: int or ``settings.AUTH_USER_MODEL`` object
        :param is_active: if this group is active or not
        :type is_active: bool
        :param property: Group property. ForeignKey
        :type property: int or :class:`tcms.management.models.TCMSEnvProperty`
        :returns: List of serialized env groups that match the query
        :rtype: list(dict)

    Query keys support the double-underscore field lookups from Django.
    For example to get all of env group with name containing 'Desktop'::

        >>> Env.filter_groups({'name__icontains': 'Desktop'})
    """
    if 'is_active' in query:
        query['is_active'] = parse_bool_value(query['is_active'])
    return TCMSEnvGroup.to_xmlrpc(query)
Ejemplo n.º 5
0
def create(request, values):
    """
    Description: Creates a new build object and stores it in the database

    Params:      $values - Hash: A reference to a hash with keys and values
                 matching the fields of the build to be created.

        +-------------+----------------+-----------+---------------------------+
        | Field       | Type           | Null      | Description               |
        +-------------+----------------+-----------+---------------------------+
        | product     | Integer/String | Required  | ID or Name of product     |
        | name        | String         | Required  |                           |
        | description | String         | Optional  |                           |
        | is_active   | Boolean        | Optional  | Defaults to True (1)      |
        +-------------+----------------+-----------+---------------------------+

    Returns:     The newly created object hash.

    Example:
    # Create build by product ID and set the build active.
    >>> Build.create({'product': 234, 'name': 'tcms_testing', 'description': 'None', 'is_active': 1})
    # Create build by product name and set the build to inactive.
    >>> Build.create({'product': 'TCMS', 'name': 'tcms_testing 2', 'description': 'None', 'is_active': 0})
    """
    if not values.get("product") or not values.get("name"):
        raise ValueError("Product and name are both required.")

    p = pre_check_product(values)

    return TestBuild.objects.create(
        product=p,
        name=values["name"],
        description=values.get("description"),
        is_active=parse_bool_value(values.get("is_active", True)),
    ).serialize()
Ejemplo n.º 6
0
Archivo: env.py Proyecto: jetlyb/Kiwi
def filter_values(query):
    """
    .. function:: XML-RPC Env.filter_values(query)

        Performs a search and returns the resulting list of env values.
        Parameter ``query`` is dict which recognizes the following
        keys:

        :param id: ID of env value
        :type id: int
        :param value: Object value
        :type value: str
        :param is_active:
        :type is_active: bool
        :param property: ForeignKey: TCMSEnvProperty
        :type property: int or :class:`tcms.management.models.TCMSEnvProperty`
        :returns: List of serialized env values matching the query
        :rtype: list(dict)

        For example to get all env values containing 'Desktop'::

            >>> Env.filter_values({'value__icontains': 'Desktop'})
    """
    if 'is_active' in query:
        query['is_active'] = parse_bool_value(query['is_active'])
    return TCMSEnvValue.to_xmlrpc(query)
Ejemplo n.º 7
0
def create(values):
    """
    .. function:: XML-RPC Build.create(values)

        Creates a new build object and stores it in the database.
        ``values`` is a dict matching the fields of the TestBuild object:

        :param product: **required** ID or name of Product to which this Build belongs
        :type product: int or str
        :param name: **required** name of the build (aka build version string)
        :type name: str
        :param description: optional description
        :type str:
        :param is_active: Optional, default to True
        :type is_active: bool
        :return: Serialized :class:`tcms.management.models.TestBuild` object
        :rtype: dict
        :raises: ValueError if product or name not specified
        :raises: PermissionDenied if missing *management.add_testbuild* permission
    """
    if not values.get('product') or not values.get('name'):
        raise ValueError('Product and name are both required.')

    p = pre_check_product(values)

    return TestBuild.objects.create(product=p,
                                    name=values['name'],
                                    description=values.get('description'),
                                    is_active=parse_bool_value(
                                        values.get('is_active',
                                                   True))).serialize()
Ejemplo n.º 8
0
def filter(query=None, **kwargs):  # pylint: disable=redefined-builtin
    """
    .. function:: XML-RPC User.filter(query)

        Search and return the resulting list of users.

        :param query: Field lookups for :class:`django.contrib.auth.models.User`
        :type query: dict
        :return: Serialized :class:`django.contrib.auth.models.User` object without
                 the password field!
        :rtype: dict

    .. note::

        If query is ``None`` will return the user issuing the RPC request.
    """
    if not query:
        query = {'pk': kwargs.get(REQUEST_KEY).user.pk}

    if 'is_active' in query:
        query['is_active'] = parse_bool_value(query['is_active'])
    users = User.objects.filter(**query)

    filtered_users = []
    for user in users:
        filtered_users.append(_get_user_dict(user))

    return filtered_users
Ejemplo n.º 9
0
def create(request, values):
    """Creates a new build object and stores it in the database

    :param dict values: a mapping containing following items to create a
        :class:`TestBuild`

        * product: (int or str) the product ID or name the new TestBuild should belong to.
        * name: (str) the build name.
        * description: (str) optional description.
        * is_active: (bool) optional. To indicate whether new build is active. Defaults to ``True``.

    :return: a mapping serialized from newly created :class:`TestBuild`.
    :rtype: dict

    Example::

        # Create build by product ID and set the build active.
        >>> Build.create({'product': 234, 'name': 'tcms_testing', 'description': 'None', 'is_active': 1})
        # Create build by product name and set the build to inactive.
        >>> Build.create({'product': 'TCMS', 'name': 'tcms_testing 2', 'description': 'None', 'is_active': 0})
    """
    if not values.get('product') or not values.get('name'):
        raise ValueError('Product and name are both required.')

    p = pre_check_product(values)

    return TestBuild.objects.create(
        product=p,
        name=values['name'],
        description=values.get('description'),
        is_active=parse_bool_value(values.get('is_active', True))
    ).serialize()
Ejemplo n.º 10
0
Archivo: build.py Proyecto: thr27/Kiwi
def create(request, values):
    """
    Description: Creates a new build object and stores it in the database

    Params:      $values - Hash: A reference to a hash with keys and values
                 matching the fields of the build to be created.

        +-------------+----------------+-----------+---------------------------+
        | Field       | Type           | Null      | Description               |
        +-------------+----------------+-----------+---------------------------+
        | product     | Integer/String | Required  | ID or Name of product     |
        | name        | String         | Required  |                           |
        | description | String         | Optional  |                           |
        | is_active   | Boolean        | Optional  | Defaults to True (1)      |
        +-------------+----------------+-----------+---------------------------+

    Returns:     The newly created object hash.

    Example:
    # Create build by product ID and set the build active.
    >>> Build.create({'product': 234, 'name': 'tcms_testing', 'description': 'None', 'is_active': 1})
    # Create build by product name and set the build to inactive.
    >>> Build.create({'product': 'TCMS', 'name': 'tcms_testing 2', 'description': 'None', 'is_active': 0})
    """
    if not values.get('product') or not values.get('name'):
        raise ValueError('Product and name are both required.')

    p = pre_check_product(values)

    return TestBuild.objects.create(product=p,
                                    name=values['name'],
                                    description=values.get('description'),
                                    is_active=parse_bool_value(
                                        values.get('is_active',
                                                   True))).serialize()
Ejemplo n.º 11
0
def filter_values(request, query):
    """
    Description: Performs a search and returns the resulting list of env properties.

    Params:      $query - Hash: keys must match valid search fields.

    +------------------------------------------------------------------+
    |               Product Search Parameters                          |
    +------------------------------------------------------------------+
    |        Key          |          Valid Values                      |
    | id                  | Integer: ID of env value                   |
    | value               | String                                     |
    | is_active           | Boolean                                    |
    | property            | ForeignKey: TCMSEnvProperty                |
    +------------------------------------------------------------------+

    Returns:     Array: Matching env values are retuned in a list of hashes.

    Example:
    # Get all of env values name contains 'Desktop'
    >>> Env.filter_values({'name__icontains': 'Desktop'})
    """
    if 'is_active' in query:
        query['is_active'] = parse_bool_value(query['is_active'])
    return TCMSEnvValue.to_xmlrpc(query)
Ejemplo n.º 12
0
def update(build_id, values):
    """
    .. function:: XML-RPC Build.update(build_id, values)

        Updates the fields of the selected build.

        :param build_id: PK of Build to modify
        :type build_id: int
        :param values: Field values for :class:`tcms.management.models.Build`
        :type values: dict
        :return: Serialized :class:`tcms.management.models.Build` object
        :rtype: dict
        :raises: Build.DoesNotExist if build not found
        :raises: PermissionDenied if missing *management.change_build* permission
    """
    selected_build = Build.objects.get(build_id=build_id)

    def _update_value(obj, name, value):
        setattr(obj, name, value)
        update_fields.append(name)

    update_fields = list()
    if values.get('product'):
        _update_value(selected_build, 'product', pre_check_product(values))
    if values.get('name'):
        _update_value(selected_build, 'name', values['name'])
    if values.get('description'):
        _update_value(selected_build, 'description', values['description'])
    if values.get('is_active') is not None:
        _update_value(selected_build, 'is_active', parse_bool_value(values.get(
            'is_active', True)))

    selected_build.save(update_fields=update_fields)

    return selected_build.serialize()
Ejemplo n.º 13
0
def filter(request, query):
    """
    Description: Performs a search and returns the resulting list of test cases

    Params:      $query - Hash: keys must match valid search fields.

        +------------------------------------------------------------------+
        |                 Case Search Parameters                           |
        +------------------------------------------------------------------+
        |        Key          |          Valid Values                      |
        | id                  | Integer: ID                                |
        | username            | String: User name                          |
        | first_name          | String: User first name                    |
        | last_name           | String: User last  name                    |
        | email               | String Email                               |
        | is_active           | Boolean: Return the active users           |
        | groups              | ForeignKey: AuthGroup                      |
        +------------------------------------------------------------------+

    Returns:     Array: Matching test cases are retuned in a list of hashes.

    Example:
    >>> User.filter({'username__startswith': 'x'})
    """
    if 'is_active' in query:
        query['is_active'] = parse_bool_value(query['is_active'])
    users = User.objects.filter(**query)
    return [get_user_dict(u) for u in users]
Ejemplo n.º 14
0
Archivo: user.py Proyecto: thr27/Kiwi
def filter(request, query):
    """
    Description: Performs a search and returns the resulting list of test cases

    Params:      $query - Hash: keys must match valid search fields.

        +------------------------------------------------------------------+
        |                 Case Search Parameters                           |
        +------------------------------------------------------------------+
        |        Key          |          Valid Values                      |
        | id                  | Integer: ID                                |
        | username            | String: User name                          |
        | first_name          | String: User first name                    |
        | last_name           | String: User last  name                    |
        | email               | String Email                               |
        | is_active           | Boolean: Return the active users           |
        | groups              | ForeignKey: AuthGroup                      |
        +------------------------------------------------------------------+

    Returns:     Array: Matching test cases are retuned in a list of hashes.

    Example:
    >>> User.filter({'username__startswith': 'x'})
    """
    if 'is_active' in query:
        query['is_active'] = parse_bool_value(query['is_active'])
    users = User.objects.filter(**query)
    return [get_user_dict(u) for u in users]
Ejemplo n.º 15
0
def create(request, values):
    """Creates a new build object and stores it in the database

    :param dict values: a mapping containing following items to create a
        :class:`TestBuild`

        * product: (int or str) the product ID or name the new TestBuild should belong to.
        * name: (str) the build name.
        * description: (str) optional description.
        * is_active: (bool) optional. To indicate whether new build is active. Defaults to ``True``.

    :return: a mapping serialized from newly created :class:`TestBuild`.
    :rtype: dict

    Example::

        # Create build by product ID and set the build active.
        >>> Build.create({'product': 234, 'name': 'tcms_testing', 'description': 'None', 'is_active': 1})
        # Create build by product name and set the build to inactive.
        >>> Build.create({'product': 'TCMS', 'name': 'tcms_testing 2', 'description': 'None', 'is_active': 0})
    """
    if not values.get('product') or not values.get('name'):
        raise ValueError('Product and name are both required.')

    p = pre_check_product(values)

    return TestBuild.objects.create(product=p,
                                    name=values['name'],
                                    description=values.get('description'),
                                    is_active=parse_bool_value(
                                        values.get('is_active',
                                                   True))).serialize()
Ejemplo n.º 16
0
    def test_parse_bool_value(self):
        false_values = (0, "0", False)
        for arg in false_values:
            try:
                value = U.parse_bool_value(arg)
            except Exception:
                self.fail("Unexcept error occurs.")
            else:
                self.assertFalse(value)

        true_values = (1, "1", True)
        for arg in true_values:
            try:
                value = U.parse_bool_value(arg)
            except Exception:
                self.fail("Unexcept error occurs.")
            else:
                self.assertTrue(value)
Ejemplo n.º 17
0
    def test_parse_bool_value(self):
        false_values = (0, "0", False)
        for arg in false_values:
            try:
                value = U.parse_bool_value(arg)
            except Exception:
                self.fail("Unexcept error occurs.")
            else:
                self.assertFalse(value)

        true_values = (1, "1", True)
        for arg in true_values:
            try:
                value = U.parse_bool_value(arg)
            except Exception:
                self.fail("Unexcept error occurs.")
            else:
                self.assertTrue(value)
Ejemplo n.º 18
0
    def test_parse_bool_value(self):
        self.assertFalse(U.parse_bool_value(0))
        self.assertFalse(U.parse_bool_value('0'))
        self.assertFalse(U.parse_bool_value(False))

        self.assertTrue(U.parse_bool_value(1))
        self.assertTrue(U.parse_bool_value('1'))
        self.assertTrue(U.parse_bool_value(True))
Ejemplo n.º 19
0
    def test_parse_bool_value(self):
        self.assertFalse(U.parse_bool_value(0))
        self.assertFalse(U.parse_bool_value('0'))
        self.assertFalse(U.parse_bool_value(False))

        self.assertTrue(U.parse_bool_value(1))
        self.assertTrue(U.parse_bool_value('1'))
        self.assertTrue(U.parse_bool_value(True))
Ejemplo n.º 20
0
def filter(query):  # pylint: disable=redefined-builtin
    """
    .. function:: XML-RPC Env.Value.filter(query)

        Performs a search and returns the resulting list of environment values.

        :param query: Field lookups for :class:`tcms.management.models.EnvValue`
        :type query: dict
        :returns: List of serialized :class:`tcms.management.models.EnvValue` objects
        :rtype: list(dict)
    """
    if 'is_active' in query:
        query['is_active'] = parse_bool_value(query['is_active'])
    return EnvValue.to_xmlrpc(query)
Ejemplo n.º 21
0
def filter(query):
    """
    .. function:: XML-RPC Env.Property.filter(query)

        Performs a search and returns the resulting list of environment properties.

        :param query: Field lookups for :class:`tcms.management.models.TCMSEnvProperty`
        :type query: dict
        :returns: List of serialized :class:`tcms.management.models.TCMSEnvProperty` objects
        :rtype: list(dict)
    """
    if 'is_active' in query:
        query['is_active'] = parse_bool_value(query['is_active'])
    return TCMSEnvProperty.to_xmlrpc(query)
Ejemplo n.º 22
0
def filter(query):
    """
    .. function:: XML-RPC Env.Group.filter(query)

        Perform a search and return the resulting list of
        :class:`tcms.management.models.EnvGroup` objects.

        :param query: Field lookups for :class:`tcms.management.models.EnvGroup`
        :type query: dict
        :returns: List of serialized :class:`tcms.management.models.EnvGroup` objects
        :rtype: list(dict)
    """
    if 'is_active' in query:
        query['is_active'] = parse_bool_value(query['is_active'])
    return EnvGroup.to_xmlrpc(query)
Ejemplo n.º 23
0
Archivo: build.py Proyecto: thr27/Kiwi
def update(request, build_id, values):
    """
    Description: Updates the fields of the selected build or builds.

    Params:      $id - Integer: A single build ID.

                 $values - Hash of keys matching Build fields and the new values
                 to set each field to.

        +-------------+----------------+-----------+---------------------------+
        | Field       | Type           | Null      | Description               |
        +-------------+----------------+-----------+---------------------------+
        | product     | Integer/String | Optional  | ID or Name of product     |
        | name        | String         | Optional  |                           |
        | description | String         | Optional  |                           |
        | is_active   | Boolean        | Optional  | True/False                |
        +-------------+----------------+-----------+---------------------------+

    Returns:     Hash: The updated Build object hash.

    Example:
    # Update name to 'foo' for build id 702
    >>> Build.update(702, {'name': 'foo'})
    # Update status to inactive for build id 702
    >>> Build.update(702, {'is_active': 0})
    """
    tb = TestBuild.objects.get(build_id=build_id)

    def _update_value(obj, name, value):
        setattr(obj, name, value)
        update_fields.append(name)

    update_fields = list()
    if values.get('product'):
        _update_value(tb, 'product', pre_check_product(values))
    if values.get('name'):
        _update_value(tb, 'name', values['name'])
    if values.get('description'):
        _update_value(tb, 'description', values['description'])
    if values.get('is_active') is not None:
        _update_value(tb, 'is_active',
                      parse_bool_value(values.get('is_active', True)))

    tb.save(update_fields=update_fields)

    return tb.serialize()
Ejemplo n.º 24
0
def update(request, build_id, values):
    """
    Description: Updates the fields of the selected build or builds.

    Params:      $id - Integer: A single build ID.

                 $values - Hash of keys matching Build fields and the new values
                 to set each field to.

        +-------------+----------------+-----------+---------------------------+
        | Field       | Type           | Null      | Description               |
        +-------------+----------------+-----------+---------------------------+
        | product     | Integer/String | Optional  | ID or Name of product     |
        | name        | String         | Optional  |                           |
        | description | String         | Optional  |                           |
        | is_active   | Boolean        | Optional  | True/False                |
        +-------------+----------------+-----------+---------------------------+

    Returns:     Hash: The updated Build object hash.

    Example:
    # Update name to 'foo' for build id 702
    >>> Build.update(702, {'name': 'foo'})
    # Update status to inactive for build id 702
    >>> Build.update(702, {'is_active': 0})
    """
    tb = TestBuild.objects.get(build_id=build_id)

    def _update_value(obj, name, value):
        setattr(obj, name, value)
        update_fields.append(name)

    update_fields = list()
    if values.get("product"):
        _update_value(tb, "product", pre_check_product(values))
    if values.get("name"):
        _update_value(tb, "name", values["name"])
    if values.get("description"):
        _update_value(tb, "description", values["description"])
    if values.get("is_active") is not None:
        _update_value(tb, "is_active", parse_bool_value(values.get("is_active", True)))

    tb.save(update_fields=update_fields)

    return tb.serialize()
Ejemplo n.º 25
0
def update(request, build_id, values):
    """
    Description: Updates the fields of the selected build or builds.

    :param int build_id: the build ID.
    :param dict values: a mapping containing build information to update.

        * product: (int or str) optional new product ID or name.
        * name: (str) optional new build name.
        * description: (str) optional new description.
        * is_active: (bool) set active or not optionally.

    :return: a mapping serialized from the updated :class:`TestBuild` object.
    :rtype: dict

    Example::

        # Update name to 'foo' for build id 702
        >>> Build.update(702, {'name': 'foo'})
        # Update status to inactive for build id 702
        >>> Build.update(702, {'is_active': 0})
    """
    tb = TestBuild.objects.get(build_id=build_id)

    def _update_value(obj, name, value):
        setattr(obj, name, value)
        update_fields.append(name)

    update_fields = list()
    if values.get('product'):
        _update_value(tb, 'product', pre_check_product(values))
    if values.get('name'):
        _update_value(tb, 'name', values['name'])
    if values.get('description'):
        _update_value(tb, 'description', values['description'])
    if values.get('is_active') is not None:
        _update_value(tb, 'is_active',
                      parse_bool_value(values.get('is_active', True)))

    tb.save(update_fields=update_fields)

    return tb.serialize()
Ejemplo n.º 26
0
def update(request, build_id, values):
    """
    Description: Updates the fields of the selected build or builds.

    :param int build_id: the build ID.
    :param dict values: a mapping containing build information to update.

        * product: (int or str) optional new product ID or name.
        * name: (str) optional new build name.
        * description: (str) optional new description.
        * is_active: (bool) set active or not optionally.

    :return: a mapping serialized from the updated :class:`TestBuild` object.
    :rtype: dict

    Example::

        # Update name to 'foo' for build id 702
        >>> Build.update(702, {'name': 'foo'})
        # Update status to inactive for build id 702
        >>> Build.update(702, {'is_active': 0})
    """
    tb = TestBuild.objects.get(build_id=build_id)

    def _update_value(obj, name, value):
        setattr(obj, name, value)
        update_fields.append(name)

    update_fields = list()
    if values.get('product'):
        _update_value(tb, 'product', pre_check_product(values))
    if values.get('name'):
        _update_value(tb, 'name', values['name'])
    if values.get('description'):
        _update_value(tb, 'description', values['description'])
    if values.get('is_active') is not None:
        _update_value(tb, 'is_active', parse_bool_value(values.get(
            'is_active', True)))

    tb.save(update_fields=update_fields)

    return tb.serialize()
Ejemplo n.º 27
0
def create(values):
    """
    .. function:: XML-RPC Build.create(values)

        Create a new build object and store it in the database.

        :param values: Field values for :class:`tcms.management.models.Build`
        :type values: dict
        :return: Serialized :class:`tcms.management.models.Build` object
        :rtype: dict
        :raises: ValueError if product or name not specified
        :raises: PermissionDenied if missing *management.add_build* permission
    """
    if not values.get('product') or not values.get('name'):
        raise ValueError('Product and name are both required.')

    return Build.objects.create(product=pre_check_product(values),
                                name=values['name'],
                                is_active=parse_bool_value(
                                    values.get('is_active',
                                               True))).serialize()
Ejemplo n.º 28
0
def get_values(request, env_property_id=None, is_active=True):
    """
    Description: Get the list of values associated with this env property.

    Params:      $env_property_id - Integer: env_property_id of the env property in the Database
                                    Return all of values when the argument is not specific.
                 $is_active       - Boolean: True to only include builds where is_active is true.
                                    Default: True
    Returns:     Array: Returns an array of env values objects.

    Example:
    # Get all of properties
    >>> Env.get_properties()
    # Get the properties in group 10
    >>> Env.get_properties(10)
    """
    query = {'is_active': parse_bool_value(is_active)}
    if env_property_id:
        query['property__pk'] = env_property_id

    return TCMSEnvValue.to_xmlrpc(query)
Ejemplo n.º 29
0
def filter_values(request, query):
    """Performs a search and returns the resulting list of env properties.

    :param dict query: mapping containing these criteria.

        * id: (int) ID of env value
        * value: (str)
        * is_active: (bool)
        * property: ForeignKey: :class:`TCMSEnvProperty`

    :return: list of mappings containing found environment property values.
    :rtype: list

    Example::

        # Get all of env values name contains 'Desktop'
        >>> Env.filter_values({'name__icontains': 'Desktop'})
    """
    if 'is_active' in query:
        query['is_active'] = parse_bool_value(query['is_active'])
    return TCMSEnvValue.to_xmlrpc(query)
Ejemplo n.º 30
0
def get_properties(request, env_group_id=None, is_active=True):
    """Get the list of properties associated with this env group.

    :param int env_group_id: env_group_id of the env group in the Database
        Return all of properties when the argument is not specified.
    :param bool is_active: If ``True``, only include builds. Default: ``True``.
    :return: list of found environment properties.
    :rtype: list

    Example::

        # Get all of properties
        >>> Env.get_properties()
        # Get the properties in group 10
        >>> Env.get_properties(10)
    """
    query = {'is_active': parse_bool_value(is_active)}
    if env_group_id:
        query['group__pk'] = env_group_id

    return TCMSEnvProperty.to_xmlrpc(query)
Ejemplo n.º 31
0
def update(build_id, values):
    """
    .. function:: XML-RPC Build.update(build_id, values)

        Updates the fields of the selected ``build_id``.
        ``values`` is a dict matching the fields of the TestBuild object:

        :param product: ID or name of Product to which this Build belongs
        :type product: int or str
        :param name: Name of the build (aka build version string)
        :type name: str
        :param description: Description
        :type str:
        :param is_active: If the Build is active
        :type is_active: bool
        :return: Serialized :class:`tcms.management.models.TestBuild` object
        :rtype: dict
        :raises: TestBuild.DoesNotExist if build not found
        :raises: PermissionDenied if missing *management.change_testbuild* permission
    """
    tb = TestBuild.objects.get(build_id=build_id)

    def _update_value(obj, name, value):
        setattr(obj, name, value)
        update_fields.append(name)

    update_fields = list()
    if values.get('product'):
        _update_value(tb, 'product', pre_check_product(values))
    if values.get('name'):
        _update_value(tb, 'name', values['name'])
    if values.get('description'):
        _update_value(tb, 'description', values['description'])
    if values.get('is_active') is not None:
        _update_value(tb, 'is_active',
                      parse_bool_value(values.get('is_active', True)))

    tb.save(update_fields=update_fields)

    return tb.serialize()
Ejemplo n.º 32
0
def get_builds(request, product, is_active=True):
    """Get the list of builds associated with this product.

    :param product: product ID or name.
    :type product: int or str
    :param bool is_active: if ``True``, only return active builds. Otherwise,
        inactive builds will be returned.
    :return: a list of mappings of :class:`TestBuild`.
    :rtype: list

    Example::

        # Get with product id including all builds
        >>> Product.get_builds(1)
        # Get with product name excluding all inactive builds
        >>> Product.get_builds('product name', 0)
    """
    from tcms.management.models import TestBuild

    p = pre_check_product(values=product)
    query = {'product': p, 'is_active': parse_bool_value(is_active)}
    return TestBuild.to_xmlrpc(query)
Ejemplo n.º 33
0
def get_builds(request, product, is_active=True):
    """
    Description: Get the list of builds associated with this product.

    Params:      $product  -  Integer/String
                              Integer: product_id of the product in the Database
                              String: Product name
                 $is_active - Boolean: True to only include builds where is_active is true.
                              Default: True
    Returns:     Array: Returns an array of Build objects.

    Example:
    # Get with product id including all builds
    >>> Product.get_builds(61)
    # Get with product name excluding all inactive builds
    >>> Product.get_builds('Red Hat Enterprise Linux 5', 0)
    """
    from tcms.management.models import TestBuild

    p = pre_check_product(values=product)
    query = {'product': p, 'is_active': parse_bool_value(is_active)}
    return TestBuild.to_xmlrpc(query)
Ejemplo n.º 34
0
def get_builds(request, product, is_active=True):
    """
    Description: Get the list of builds associated with this product.

    Params:      $product  -  Integer/String
                              Integer: product_id of the product in the Database
                              String: Product name
                 $is_active - Boolean: True to only include builds where is_active is true.
                              Default: True
    Returns:     Array: Returns an array of Build objects.

    Example:
    # Get with product id including all builds
    >>> Product.get_builds(61)
    # Get with product name excluding all inactive builds
    >>> Product.get_builds('Red Hat Enterprise Linux 5', 0)
    """
    from tcms.management.models import TestBuild

    p = pre_check_product(values=product)
    query = {'product': p, 'is_active': parse_bool_value(is_active)}
    return TestBuild.to_xmlrpc(query)
Ejemplo n.º 35
0
def get_builds(request, product, is_active=True):
    """Get the list of builds associated with this product.

    :param product: product ID or name.
    :type product: int or str
    :param bool is_active: if ``True``, only return active builds. Otherwise,
        inactive builds will be returned.
    :return: a list of mappings of :class:`TestBuild`.
    :rtype: list

    Example::

        # Get with product id including all builds
        >>> Product.get_builds(1)
        # Get with product name excluding all inactive builds
        >>> Product.get_builds('product name', 0)
    """
    from tcms.management.models import TestBuild

    p = pre_check_product(values=product)
    query = {'product': p, 'is_active': parse_bool_value(is_active)}
    return TestBuild.to_xmlrpc(query)
Ejemplo n.º 36
0
def get_values(request, env_property_id=None, is_active=True):
    """Get the list of values associated with this env property.

    :param int env_property_id: environment property ID. If omitted, all
        environment property values will be returned.
    :param bool is_active: indicate whether to get values from active
        properties. Default is ``True``.
    :return: list of mappings containing found environment property values.
    :rtype: list

    Example::

        # Get all values from active environment properties
        >>> Env.get_values()
        # Get the properties in group 10
        >>> Env.get_values(10)
    """
    query = {'is_active': parse_bool_value(is_active)}
    if env_property_id:
        query['property__pk'] = env_property_id

    return TCMSEnvValue.to_xmlrpc(query)
Ejemplo n.º 37
0
def filter_properties(request, query):
    """Performs a search and returns the resulting list of env properties.

    :param dict query: mapping containing following criteria to find out
        environment properties.

        * id: (int) environment property ID.
        * name: (str) property name.
        * is_active: (bool) whether to find active properties.
        * group: ForeignKey: :class:`TCMSEnvGroup`
        * value: ForeignKey: :class:`TCMSEnvValues`

    :return: Array: Matching env properties are retuned in a list of hashes.

    Example::

        # Get all of env properties name contains 'Desktop'
        >>> Env.filter_properties({'name__icontains': 'Desktop'})
    """
    if 'is_active' in query:
        query['is_active'] = parse_bool_value(query['is_active'])
    return TCMSEnvProperty.to_xmlrpc(query)
Ejemplo n.º 38
0
def filter(request, query):
    """Performs a search and returns the resulting list of test cases

    :param dict query: a mapping containing these criteria.

        * id: (int): ID
        * username: (str): User name
        * first_name: (str): User first name
        * last_name: (str): User last name
        * email: (str) Email
        * is_active: bool: Return the active users
        * groups: ForeignKey: AuthGroup

    :return: a list of mappings of found :class:`User <django.contrib.auth.models.User>`.
    :rtype: list[dict]

    Example::

        >>> User.filter({'username__startswith': 'z'})
    """
    if 'is_active' in query:
        query['is_active'] = parse_bool_value(query['is_active'])
    users = User.objects.filter(**query)
    return [get_user_dict(u) for u in users]
Ejemplo n.º 39
0
def filter(request, query):
    """Performs a search and returns the resulting list of test cases

    :param dict query: a mapping containing these criteria.

        * id: (int): ID
        * username: (str): User name
        * first_name: (str): User first name
        * last_name: (str): User last name
        * email: (str) Email
        * is_active: bool: Return the active users
        * groups: ForeignKey: AuthGroup

    :return: a list of mappings of found :class:`User <django.contrib.auth.models.User>`.
    :rtype: list[dict]

    Example::

        >>> User.filter({'username__startswith': 'z'})
    """
    if 'is_active' in query:
        query['is_active'] = parse_bool_value(query['is_active'])
    users = User.objects.filter(**query)
    return [get_user_dict(u) for u in users]
Ejemplo n.º 40
0
def filter_groups(request, query):
    """Performs a search and returns the resulting list of env groups.

    :param dict query: mapping containing following criteria to find out
        envrionment groups.

        * id: (int) environment group ID.
        * name: (str) environment group name.
        * manager: ForeignKey: Auth.user
        * modified_by: ForeignKey: Auth.user
        * is_active: (bool)
        * property: ForeignKey: :class:`TCMSEnvProperty`

    :return: list of mappings of found environment groups.
    :rtype: list

    Example::

        # Get all of env group name contains 'Desktop'
        >>> Env.filter_groups({'name__icontains': 'Desktop'})
    """
    if 'is_active' in query:
        query['is_active'] = parse_bool_value(query['is_active'])
    return TCMSEnvGroup.to_xmlrpc(query)
Ejemplo n.º 41
0
 def value_from_datadict(self, data, files, name):
     if name not in data:
         return False
     value = parse_bool_value(data.get(name))
     return value
Ejemplo n.º 42
0
 def value_from_datadict(self, data, files, name):
     if name not in data:
         return False
     value = parse_bool_value(data.get(name))
     return value