Example #1
0
 def test_pre_check_product_with_illegal_types(self):
     types = ((), [], True, False, self,)
     for arg in types:
         try:
             U.pre_check_product(arg)
         except ValueError as e:
             self.assertEqual(str(e), 'The type of product is not '
                                      'recognizable.')
         else:
             self.fail("Missing validations for %s" % arg)
Example #2
0
    def test_pre_check_product_with_no_exist(self):
        try:
            U.pre_check_product(9999)
        except ObjectDoesNotExist:
            pass
        else:
            self.fail("Unexcept error occurs.")

        try:
            U.pre_check_product("AAAAAAA")
        except ObjectDoesNotExist:
            pass
        else:
            self.fail("Unexcept error occurs.")
Example #3
0
    def test_pre_check_product_with_no_exist(self):
        try:
            U.pre_check_product(9999)
        except ObjectDoesNotExist:
            pass
        else:
            self.fail("Unexcept error occurs.")

        try:
            U.pre_check_product("AAAAAAA")
        except ObjectDoesNotExist:
            pass
        else:
            self.fail("Unexcept error occurs.")
Example #4
0
    def test_pre_check_product_with_dict(self):
        try:
            product = U.pre_check_product({"product": 4})
        except ObjectDoesNotExist:
            self.fail("Unexcept error occurs.")
        else:
            self.assertEqual(product.name, "World Of Warcraft")

        try:
            product = U.pre_check_product({"product": "World Of Warcraft"})
        except ObjectDoesNotExist:
            self.fail("Unexcept error occurs.")
        else:
            self.assertEqual(product.name, "World Of Warcraft")
Example #5
0
 def test_pre_check_product_with_name(self):
     try:
         product = U.pre_check_product("World Of Warcraft")
     except ValueError:
         self.fail("Unexcept error occurs.")
     else:
         self.assertEqual(product.name, "World Of Warcraft")
Example #6
0
File: build.py Project: 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()
Example #7
0
def add_version(request, values):
    """Add version to specified product.

    :param dict values: a mapping containing these data

        * product: (int or str) product ID or name.
        * value: (str) the version value.

    :return: a mapping representing newly added :class:`Version`.
    :raise ValueError: if fail to add version.

    Example::

        # Add version for specified product:
        >>> Product.add_version({'value': 'devel', 'product': 1})
        {'product': 'Test Product', 'id': '1', 'value': 'devel', 'product_id': 1}
        # Run it again:
        >>> Product.add_version({'value': 'devel', 'product': 1})
        [['__all__', 'Version with this Product and Value already exists.']]
    """
    from tcms.management.forms import VersionForm
    from tcms.core import forms

    product = pre_check_product(values)
    form_values = values.copy()
    form_values['product'] = product.pk

    form = VersionForm(form_values)
    if form.is_valid():
        version = form.save()
        return version.serialize()
    else:
        raise ValueError(forms.errors_to_list(form))
Example #8
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()
Example #9
0
def add_version(request, values):
    """Add version to specified product.

    :param dict values: a mapping containing these data

        * product: (int or str) product ID or name.
        * value: (str) the version value.

    :return: a mapping representing newly added :class:`Version`.
    :raise ValueError: if fail to add version.

    Example::

        # Add version for specified product:
        >>> Product.add_version({'value': 'devel', 'product': 1})
        {'product': 'Test Product', 'id': '1', 'value': 'devel', 'product_id': 1}
        # Run it again:
        >>> Product.add_version({'value': 'devel', 'product': 1})
        [['__all__', 'Version with this Product and Value already exists.']]
    """
    from tcms.management.forms import VersionForm
    from tcms.core import forms

    product = pre_check_product(values)
    form_values = values.copy()
    form_values['product'] = product.pk

    form = VersionForm(form_values)
    if form.is_valid():
        version = form.save()
        return version.serialize()
    else:
        raise ValueError(forms.errors_to_list(form))
Example #10
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()
Example #11
0
 def test_pre_check_product_with_no_key(self):
     try:
         product = U.pre_check_product({})
     except ObjectDoesNotExist:
         self.fail("Unexcept error occurs.")
     else:
         self.assertIsNone(product)
Example #12
0
 def test_pre_check_product_with_name(self):
     try:
         product = U.pre_check_product("World Of Warcraft")
     except ValueError:
         self.fail("Unexcept error occurs.")
     else:
         self.assertEqual(product.name, "World Of Warcraft")
Example #13
0
def add_version(request, values):
    """
    Description: Add version to specified product.

    Params:      $product - Integer/String
                            Integer: product_id of the product in the Database
                            String: Product name
                 $value   - String
                            The name of the version string.

    Returns:     Array: Returns the newly added version object, error info if failed.

    Example:
    # Add version for specified product:
    >>> Product.add_version({'value': 'devel', 'product': 272})
    {'product': 'QE Test Product', 'id': '1106', 'value': 'devel', 'product_id': 272}
    # Run it again:
    >>> Product.add_version({'value': 'devel', 'product': 272})
    [['__all__', 'Version with this Product and Value already exists.']]
    """
    from tcms.management.forms import VersionForm
    from tcms.core import forms

    product = pre_check_product(values)
    form_values = values.copy()
    form_values['product'] = product.pk

    form = VersionForm(form_values)
    if form.is_valid():
        version = form.save()
        return version.serialize()
    else:
        raise ValueError(forms.errors_to_list(form))
Example #14
0
 def test_pre_check_product_with_illegal_types(self):
     types = (
         (),
         [],
         True,
         False,
         self,
     )
     for arg in types:
         try:
             U.pre_check_product(arg)
         except ValueError as e:
             self.assertEqual(str(e), 'The type of product is not '
                              'recognizable.')
         else:
             self.fail("Missing validations for %s" % arg)
Example #15
0
 def test_pre_check_product_with_no_key(self):
     try:
         product = U.pre_check_product({})
     except ObjectDoesNotExist:
         self.fail("Unexcept error occurs.")
     else:
         self.assertIsNone(product)
Example #16
0
def create(values):
    """
    .. function:: XML-RPC Version.create(values)

        Add new version.

        :param values: Field values for :class:`tcms.management.models.Version`
        :type query: dict
        :return: Serialized :class:`tcms.management.models.Version` object
        :rtype: dict
        :raises: ValueError if input data validation fails
        :raises: PermissionDenied if missing *management.add_version* permission

    Example::

        # Add version for specified product:
        >>> Version.create({'value': 'devel', 'product': 272})
        {'product': 'QE Test Product', 'id': '1106', 'value': 'devel', 'product_id': 272}
    """
    product = pre_check_product(values)
    form_values = values.copy()
    form_values['product'] = product.pk

    form = VersionForm(form_values)
    if form.is_valid():
        version = form.save()
        return version.serialize()
    else:
        raise ValueError(form_errors_to_list(form))
Example #17
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=values.get('is_active', True)
    ).serialize()
Example #18
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()
Example #19
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()
Example #20
0
    def test_pre_check_product_with_dict(self):
        try:
            product = U.pre_check_product({
                "product": 4
            })
        except ObjectDoesNotExist:
            self.fail("Unexcept error occurs.")
        else:
            self.assertEqual(product.name, "World Of Warcraft")

        try:
            product = U.pre_check_product({
                "product": "World Of Warcraft"
            })
        except ObjectDoesNotExist:
            self.fail("Unexcept error occurs.")
        else:
            self.assertEqual(product.name, "World Of Warcraft")
Example #21
0
 def test_pre_check_product_with_number(self):
     types = (4, "4")
     for arg in types:
         try:
             product = U.pre_check_product(arg)
         except ValueError:
             self.fail("Unexcept error occurs.")
         else:
             self.assertEqual(product.name, "World Of Warcraft")
Example #22
0
 def test_pre_check_product_with_number(self):
     types = (4, "4")
     for arg in types:
         try:
             product = U.pre_check_product(arg)
         except ValueError:
             self.fail("Unexcept error occurs.")
         else:
             self.assertEqual(product.name, "World Of Warcraft")
Example #23
0
def check_build(name, product):
    """
    .. function:: XML-RPC Build.check_build(name, product)

        Looks up and returns a build by name.

        :param name: name of the build
        :type name: str
        :param product: Product ID or name to which this build belongs
        :type product: int or str
        :return: Serialized :class:`tcms.management.models.TestBuild` object
        :rtype: dict
        :raises: TestBuild.DoesNotExist if build not found
    """
    p = pre_check_product(values=product)
    return TestBuild.objects.get(name=name, product=p).serialize()
Example #24
0
def check_product(request, name):
    """Looks up and returns a validated product.

    :param name: product ID or name.
    :type name: int or str
    :return: a mapping representing the :class:`Product`.
    :rtype: dict

    Example::

        # Get with product ID
        >>> Product.check_product(1)
        # Get with product name
        >>> Product.check_product('Product A')
    """
    p = pre_check_product(values=name)
    return p.serialize()
Example #25
0
def add_component(product, name, **kwargs):
    """
    Description: Add component to selected product.


    Params:      $product - Integer/String
                            Integer: product_id of the product in the Database
                            String: Product name
                 $name    - String: Component name
                 [$initial_owner_id] - Integer: (OPTIONAL) The numeric ID or the login
                                                           of the author.
                                    Defaults to logged in user.
                 [$initial_qa_contact_id] - Integer: (OPTIONAL) The numeric ID or the login
                                                                of the author.
                                         Defaults to logged in user.


    Returns:     Hash: Component object hash.

    Example:
    >>> Product.add_component(71, 'JPBMM')
    """
    from tcms.management.models import Component

    initial_owner_id = kwargs.get('initial_owner_id', None)
    initial_qa_contact_id = kwargs.get('initial_qa_contact_id', None)
    request = kwargs.get(REQUEST_KEY)

    product = pre_check_product(values=product)

    if User.objects.filter(pk=initial_owner_id).exists():
        _initial_owner_id = initial_owner_id
    else:
        _initial_owner_id = request.user.pk

    if User.objects.filter(pk=initial_qa_contact_id).exists():
        _initial_qa_contact_id = initial_qa_contact_id
    else:
        _initial_qa_contact_id = request.user.pk

    return Component.objects.create(
        name=name,
        product=product,
        initial_owner_id=_initial_owner_id,
        initial_qa_contact_id=_initial_qa_contact_id,
    ).serialize()
Example #26
0
def check_product(request, name):
    """Looks up and returns a validated product.

    :param name: product ID or name.
    :type name: int or str
    :return: a mapping representing the :class:`Product`.
    :rtype: dict

    Example::

        # Get with product ID
        >>> Product.check_product(1)
        # Get with product name
        >>> Product.check_product('Product A')
    """
    p = pre_check_product(values=name)
    return p.serialize()
Example #27
0
File: build.py Project: 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()
Example #28
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', values.get('is_active', True))

    tb.save(update_fields=update_fields)

    return tb.serialize()
Example #29
0
def check_product(request, name):
    """
    Description: Looks up and returns a validated product.

    Params:      $name - Integer/String
                         Integer: product_id of the product in the Database
                         String: Product name

    Returns:     Hash: Matching Product object hash or error if not found.

    Example:
    # Get with product ID
    >>> Product.check_product(61)
    # Get with product name
    >>> Product.check_product('Red Hat Enterprise Linux 5')
    """
    p = pre_check_product(values=name)
    return p.serialize()
Example #30
0
File: build.py Project: thr27/Kiwi
def check_build(request, name, product):
    """
    Description: Looks up and returns a build by name.

    Params:      $name - String: name of the build.
                 $product - product_id of the product in the Database

    Returns:     Hash: Matching Build object hash or error if not found.

    Example:
    # Get with product ID
    >>> Build.check_build('2008-02-25', 61)
    # Get with product name
    >>> Build.check_build('2008-02-25', 'Red Hat Enterprise Linux 5')
    """
    p = pre_check_product(values=product)
    tb = TestBuild.objects.get(name=name, product=p)
    return tb.serialize()
Example #31
0
def check_build(request, name, product):
    """
    Description: Looks up and returns a build by name.

    Params:      $name - String: name of the build.
                 $product - product_id of the product in the Database

    Returns:     Hash: Matching Build object hash or error if not found.

    Example:
    # Get with product ID
    >>> Build.check_build('2008-02-25', 61)
    # Get with product name
    >>> Build.check_build('2008-02-25', 'Red Hat Enterprise Linux 5')
    """
    p = pre_check_product(values=product)
    tb = TestBuild.objects.get(name=name, product=p)
    return tb.serialize()
Example #32
0
def check_product(request, name):
    """
    Description: Looks up and returns a validated product.

    Params:      $name - Integer/String
                         Integer: product_id of the product in the Database
                         String: Product name

    Returns:     Hash: Matching Product object hash or error if not found.

    Example:
    # Get with product ID
    >>> Product.check_product(61)
    # Get with product name
    >>> Product.check_product('Red Hat Enterprise Linux 5')
    """
    p = pre_check_product(values=name)
    return p.serialize()
Example #33
0
def check_build(request, name, product):
    """Looks up and returns a build by name

    :param str name: name of the build.
    :param product: product_id of the product in the Database
    :type product: int or str
    :return: matching :class:`TestBuild` object hash or error if not found.
    :rtype: dict

    Example::

        # Get with product ID
        >>> Build.check_build('2008-02-25', 1)
        # Get with product name
        >>> Build.check_build('2008-02-25', 'Product A')
    """
    p = pre_check_product(values=product)
    tb = TestBuild.objects.get(name=name, product=p)
    return tb.serialize()
Example #34
0
def get_cases(request, product):
    """Get the list of cases associated with this product.

    :param product: product ID or name.
    :type product: int or str
    :return: a list of mappings of :class:`TestCase`.

    Example::

        # Get with product id
        >>> Product.get_cases(61)
        # Get with product name
        >>> Product.get_cases('product name')
    """
    from tcms.testcases.models import TestCase

    p = pre_check_product(values=product)
    query = {'category__product': p}
    return TestCase.to_xmlrpc(query)
Example #35
0
def get_cases(request, product):
    """Get the list of cases associated with this product.

    :param product: product ID or name.
    :type product: int or str
    :return: a list of mappings of :class:`TestCase`.

    Example::

        # Get with product id
        >>> Product.get_cases(61)
        # Get with product name
        >>> Product.get_cases('product name')
    """
    from tcms.testcases.models import TestCase

    p = pre_check_product(values=product)
    query = {'category__product': p}
    return TestCase.to_xmlrpc(query)
Example #36
0
def check_component(request, name, product):
    """Looks up and returns a component by name.

    :param str name: name of the category.
    :param product: product ID or name.
    :return: a mapping representing a :class:`Component`
    :rtype: dict

    Example::

        # Get with product ID
        >>> Product.check_component('acpi', 1)
        # Get with product name
        >>> Product.check_component('acpi', 'Product A')
    """
    from tcms.management.models import Component

    p = pre_check_product(values=product)
    return Component.objects.get(name=name, product=p).serialize()
Example #37
0
def check_build(request, name, product):
    """Looks up and returns a build by name

    :param str name: name of the build.
    :param product: product_id of the product in the Database
    :type product: int or str
    :return: matching :class:`TestBuild` object hash or error if not found.
    :rtype: dict

    Example::

        # Get with product ID
        >>> Build.check_build('2008-02-25', 1)
        # Get with product name
        >>> Build.check_build('2008-02-25', 'Product A')
    """
    p = pre_check_product(values=product)
    tb = TestBuild.objects.get(name=name, product=p)
    return tb.serialize()
Example #38
0
def check_component(request, name, product):
    """Looks up and returns a component by name.

    :param str name: name of the category.
    :param product: product ID or name.
    :return: a mapping representing a :class:`Component`
    :rtype: dict

    Example::

        # Get with product ID
        >>> Product.check_component('acpi', 1)
        # Get with product name
        >>> Product.check_component('acpi', 'Product A')
    """
    from tcms.management.models import Component

    p = pre_check_product(values=product)
    return Component.objects.get(name=name, product=p).serialize()
Example #39
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()
Example #40
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()
Example #41
0
def check_category(request, name, product):
    """Looks up and returns a category by name.

    :param str name: name of the category.
    :param product: product ID or name.
    :type product: int or str
    :return: a mapping representing the category.
    :rtype: dict

    Example::

        # Get with product ID
        >>> Product.check_category('Feature', 1)
        # Get with product name
        >>> Product.check_category('Feature', 'product name')
    """
    from tcms.testcases.models import TestCaseCategory

    p = pre_check_product(values=product)
    return TestCaseCategory.objects.get(name=name, product=p).serialize()
Example #42
0
def get_runs(request, product):
    """Get the list of runs associated with this product.

    :params product: product ID or name.
    :type product: int or str
    :return: a list of mappings of test runs.
    :rtype: list

    Example::

        # Get with product id
        >>> Product.get_runs(1)
        # Get with product name
        >>> Product.get_runs('product name')
    """
    from tcms.testruns.models import TestRun

    p = pre_check_product(values=product)
    query = {'build__product': p}
    return TestRun.to_xmlrpc(query)
Example #43
0
def get_versions(request, product):
    """Get the list of versions associated with this product.

    :param product: product ID or name.
    :type product: int or str
    :return: a list of mappings of versions.
    :rtype: list

    Example::

        # Get with product id
        >>> Product.get_versions(1)
        # Get with product name
        >>> Product.get_versions('product name')
    """
    from tcms.management.models import Version

    p = pre_check_product(values=product)
    query = {'product': p}
    return Version.to_xmlrpc(query)
Example #44
0
def get_components(request, product):
    """Get the list of components associated with this product.

    :param product: product ID or name.
    :type product: int or str
    :return: a list of mappings of :class:`Component`.
    :rtype: list

    Example::

        # Get with product id
        >>> Product.get_components(61)
        # Get with product name
        >>> Product.get_components('product name')
    """
    from tcms.management.models import Component

    p = pre_check_product(values=product)
    query = {'product': p}
    return Component.to_xmlrpc(query)
Example #45
0
def get_versions(request, product):
    """Get the list of versions associated with this product.

    :param product: product ID or name.
    :type product: int or str
    :return: a list of mappings of versions.
    :rtype: list

    Example::

        # Get with product id
        >>> Product.get_versions(1)
        # Get with product name
        >>> Product.get_versions('product name')
    """
    from tcms.management.models import Version

    p = pre_check_product(values=product)
    query = {'product': p}
    return Version.to_xmlrpc(query)
Example #46
0
def get_components(request, product):
    """Get the list of components associated with this product.

    :param product: product ID or name.
    :type product: int or str
    :return: a list of mappings of :class:`Component`.
    :rtype: list

    Example::

        # Get with product id
        >>> Product.get_components(61)
        # Get with product name
        >>> Product.get_components('product name')
    """
    from tcms.management.models import Component

    p = pre_check_product(values=product)
    query = {'product': p}
    return Component.to_xmlrpc(query)
Example #47
0
def check_category(request, name, product):
    """Looks up and returns a category by name.

    :param str name: name of the category.
    :param product: product ID or name.
    :type product: int or str
    :return: a mapping representing the category.
    :rtype: dict

    Example::

        # Get with product ID
        >>> Product.check_category('Feature', 1)
        # Get with product name
        >>> Product.check_category('Feature', 'product name')
    """
    from tcms.testcases.models import TestCaseCategory

    p = pre_check_product(values=product)
    return TestCaseCategory.objects.get(name=name, product=p).serialize()
Example #48
0
def get_runs(request, product):
    """Get the list of runs associated with this product.

    :params product: product ID or name.
    :type product: int or str
    :return: a list of mappings of test runs.
    :rtype: list

    Example::

        # Get with product id
        >>> Product.get_runs(1)
        # Get with product name
        >>> Product.get_runs('product name')
    """
    from tcms.testruns.models import TestRun

    p = pre_check_product(values=product)
    query = {'build__product': p}
    return TestRun.to_xmlrpc(query)
Example #49
0
def get_plans(request, product):
    """Get the list of plans associated with this product.

    :param product: product ID or name.
    :type product: int or str
    :return: a list of mappings of :class:`TestPlan`.
    :rtype: list

    Example::

        # Get with product id
        Product.get_plans(61)
        # Get with product name
        Product.get_plans('product name')
    """
    from tcms.testplans.models import TestPlan

    p = pre_check_product(values=product)
    query = {'product': p}
    return TestPlan.to_xmlrpc(query)
Example #50
0
def add_component(request,
                  product,
                  name,
                  initial_owner_id=None,
                  initial_qa_contact_id=None):
    """Add component to selected product.

    :param product: product ID or name.
    :type product: int or str
    :param str name: Component name
    :param int initial_owner_id: optional initial owner ID. Defaults to current
        logged in user.
    :param int initial_qa_contact_id: optional initial QA contact ID. Defaults
        to current logged in user.
    :return: a mapping of new :class:`Component`.
    :rtype: dict

    Example::

        >>> Product.add_component(71, 'JPBMM')
    """
    from tcms.management.models import Component

    product = pre_check_product(values=product)

    if User.objects.filter(pk=initial_owner_id).exists():
        _initial_owner_id = initial_owner_id
    else:
        _initial_owner_id = request.user.pk

    if User.objects.filter(pk=initial_qa_contact_id).exists():
        _initial_qa_contact_id = initial_qa_contact_id
    else:
        _initial_qa_contact_id = request.user.pk

    return Component.objects.create(
        name=name,
        product=product,
        initial_owner_id=_initial_owner_id,
        initial_qa_contact_id=_initial_qa_contact_id,
    ).serialize()
Example #51
0
def check_component(request, name, product):
    """
    Description: Looks up and returns a component by name.

    Params:      $name - String: name of the category.
                 $product - Integer/String
                            Integer: product_id of the product in the Database
                            String: Product name

    Returns:     Hash: Matching component object hash or error if not found.

    Example:
    # Get with product ID
    >>> Product.check_component('acpi', 61)
    # Get with product name
    >>> Product.check_component('acpi', 'Red Hat Enterprise Linux 5')
    """
    from tcms.apps.management.models import Component

    p = pre_check_product(values=product)
    return Component.objects.get(name=name, product=p).serialize()
Example #52
0
def get_categories(request, product):
    """
    Description: Get the list of categories associated with this product.

    Params:      $product - Integer/String
                            Integer: product_id of the product in the Database
                            String: Product name

    Returns:     Array: Returns an array of Case Category objects.

    Example:
    # Get with product id
    >>> Product.get_categories(61)
    # Get with product name
    >>> Product.get_categories('Red Hat Enterprise Linux 5')
    """
    from tcms.testcases.models import TestCaseCategory

    p = pre_check_product(values=product)
    query = {'product': p}
    return TestCaseCategory.to_xmlrpc(query)
Example #53
0
def get_versions(request, product):
    """
    Description: Get the list of versions associated with this product.

    Params:      $product - Integer/String
                            Integer: product_id of the product in the Database
                            String: Product name

    Returns:     Array: Returns an array of Version objects.

    Example:
    # Get with product id
    >>> Product.get_runs(61)
    # Get with product name
    >>> Product.get_runs('Red Hat Enterprise Linux 5')
    """
    from tcms.management.models import Version

    p = pre_check_product(values=product)
    query = {'product': p}
    return Version.to_xmlrpc(query)
Example #54
0
def check_component(request, name, product):
    """
    Description: Looks up and returns a component by name.

    Params:      $name - String: name of the category.
                 $product - Integer/String
                            Integer: product_id of the product in the Database
                            String: Product name

    Returns:     Hash: Matching component object hash or error if not found.

    Example:
    # Get with product ID
    >>> Product.check_component('acpi', 61)
    # Get with product name
    >>> Product.check_component('acpi', 'Red Hat Enterprise Linux 5')
    """
    from tcms.management.models import Component

    p = pre_check_product(values=product)
    return Component.objects.get(name=name, product=p).serialize()
Example #55
0
def check_category(request, name, product):
    """
    Description: Looks up and returns a category by name.

    Params:      $name - String: name of the category.
                 $product - Integer/String
                            Integer: product_id of the product in the Database
                            String: Product name

    Returns:     Hash: Matching Category object hash or error if not found.

    Example:
    # Get with product ID
    >>> Product.check_category('Feature', 61)
    # Get with product name
    >>> Product.check_category('Feature', 'Red Hat Enterprise Linux 5')
    """
    from tcms.testcases.models import TestCaseCategory

    p = pre_check_product(values=product)
    return TestCaseCategory.objects.get(name=name, product=p).serialize()
Example #56
0
def add_component(request, product, name, initial_owner_id=None, initial_qa_contact_id=None):
    """
    Description: Add component to selected product.


    Params:      $product - Integer/String
                            Integer: product_id of the product in the Database
                            String: Product name
                 $name    - String: Component name
                 [$initial_owner_id] - Integer: (OPTIONAL) The numeric ID or the login of the author.
                                    Defaults to logged in user.
                 [$initial_qa_contact_id] - Integer: (OPTIONAL) The numeric ID or the login of the author.
                                         Defaults to logged in user.


    Returns:     Hash: Component object hash.

    Example:
    >>> Product.add_component(71, 'JPBMM')
    """
    from tcms.management.models import Component

    product = pre_check_product(values=product)

    if User.objects.filter(pk=initial_owner_id).exists():
        _initial_owner_id = initial_owner_id
    else:
        _initial_owner_id = request.user.pk

    if User.objects.filter(pk=initial_qa_contact_id).exists():
        _initial_qa_contact_id = initial_qa_contact_id
    else:
        _initial_qa_contact_id = request.user.pk

    return Component.objects.create(
        name=name,
        product=product,
        initial_owner_id=_initial_owner_id,
        initial_qa_contact_id=_initial_qa_contact_id,
    ).serialize()
Example #57
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)
Example #58
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)
Example #59
0
def add_component(request, product, name, initial_owner_id=None, initial_qa_contact_id=None):
    """Add component to selected product.

    :param product: product ID or name.
    :type product: int or str
    :param str name: Component name
    :param int initial_owner_id: optional initial owner ID. Defaults to current
        logged in user.
    :param int initial_qa_contact_id: optional initial QA contact ID. Defaults
        to current logged in user.
    :return: a mapping of new :class:`Component`.
    :rtype: dict

    Example::

        >>> Product.add_component(71, 'JPBMM')
    """
    from tcms.management.models import Component

    product = pre_check_product(values=product)

    if User.objects.filter(pk=initial_owner_id).exists():
        _initial_owner_id = initial_owner_id
    else:
        _initial_owner_id = request.user.pk

    if User.objects.filter(pk=initial_qa_contact_id).exists():
        _initial_qa_contact_id = initial_qa_contact_id
    else:
        _initial_qa_contact_id = request.user.pk

    return Component.objects.create(
        name=name,
        product=product,
        initial_owner_id=_initial_owner_id,
        initial_qa_contact_id=_initial_qa_contact_id,
    ).serialize()
Example #60
0
 def test_pre_check_product_with_name(self):
     product = U.pre_check_product("World Of Warcraft")
     self.assertEqual(product.name, "World Of Warcraft")