:mod:`waeup.university.certificate` -- Certificates for WAeUP
*************************************************************

Components that represent and manage certificates.

:Test-Layer: unit

Because certificates make use of components registered with the Zope
Component Architecture (ZCA), we first have to grok the `waeup`
package. This happens automatically in real-world use:

    >>> import grok
    >>> grok.testing.grok('waeup')


Content Classes (models and containers)
=======================================


:class:`Certificate`
--------------------

.. class:: Certificate([code=u'NA',[ title=u'Unnamed Certificate',[ category=None,[ study_mode=None,[ start_level=None,[ end_level=None,[ application_category=None,[ m_prefix=u'',[  max_pass = u'']]]]]]]]])

   Create a certificate object with the given parameters.

   .. attribute:: grok.implements(ICertificate)

   All parameters are optional:

     >>> from waeup.university.certificate import Certificate
     >>> mycertificate = Certificate()

   Certificates have the attributes required by the `ICertificate` interface:

     >>> from waeup.interfaces import ICertificate
     >>> ICertificate.providedBy(mycertificate)
     True

     >>> from zope.interface.verify import verifyObject
     >>> verifyObject(ICertificate, mycertificate)
     True

   Beside the attributes, certificates are containers for
   certificate-courses (see :class:`CertificateCourse`). Each
   certificate course can be accessed by the code of the course it wraps.

   .. attribute:: title

      Each certificate has a title:

        >>> mycertificate.title
        u'Unnamed Certificate'

   .. attribute:: code

      Each certificate holds a code, which might be a shortcut or
      abbreviation of the real certificate name. By default the code
      is ``NA`` (=not assigned):

        >>> mycertificate.code
        u'NA'

   .. attribute:: review_state

      The review state can have one of the ``checking`` states defined
      in the WAeUP workflow. These are at least the states ``checked``
      and ``unchecked``. After a certificate is created, the review
      state is ``unchecked``:

        >>> mycertificate.review_state
        'unchecked'

      .. seealso::
         :meth:`Certificate.check` -- mark a certificate as ``checked``

   .. attribute:: category

      Each :class:`Certificate` instance has a category:

        >>> print mycertificate.category
        None

      .. XXX: This is not a proper description

   .. attribute:: study_mode

      Each :class:`Certificate` instance has a study mode:

        >>> print mycertificate.study_mode
        None

      .. XXX: This is not a proper description

   .. attribute:: start_level

      Each :class:`Certificate` instance has a start level:

        >>> print mycertificate.start_level
        None

      .. XXX: This is not a proper description

   .. attribute:: end_level

      Each :class:`Certificate` instance has a end level:

        >>> print mycertificate.end_level
        None

      .. XXX: This is not a proper description
   

   .. attribute:: application_category

      Each :class:`Certificate` instance has an application category:

        >>> print mycertificate.application_category
        None

      .. XXX: This is not a proper description

   
   .. attribute:: m_prefix

      Each :class:`Certificate` instance has an ``m_prefix``:

        >>> mycertificate.m_prefix
        u''

      .. XXX: This is not a proper description

   
   .. attribute:: max_pass

      Each :class:`Certificate` instance has a maximum number of passes:

        >>> mycertificate.max_pass
        u''

      .. XXX: This is not a proper description


   .. method:: check()

      Mark a certificate instance's review state as ``checked``:

        >>> mycertificate.review_state
        'unchecked'

        >>> mycertificate.check()
        >>> mycertificate.review_state
        'checked'

      We cannot uncheck a certificate:

        >>> mycertificate.review_state = 'init'
        Traceback (most recent call last):
	...
	InvalidTransitionError: Transition 'init' requires 'None' 
          as source state (is: 'checked')

   .. method:: addCourseRef(course[, level=100,[ core_or_elective=True]])

      Add a reference to a course. A course is an object implementing
      :class:`waeup.interfaces.ICourse`.

      Please don't be confused by the term 'reference'. This just
      means an ordinary :class:`waeup.university.course.Course` object
      in almost all cases. As this object will normaly be one stored
      in a department, the course here will simply become a reference
      to the 'real' one in the department container.

   .. method:: delCourseRef(code)

      Remove a course from a certificate.

      The course must be given by its code number.

:class:`CertificateCourse`
--------------------------

.. class:: CertificateCourse(course[, level=100[, core_or_elective=True]])

   Create a certificate course.

   A certificate-course is a course (:class:`Course`) which is part of
   a certificate. Normally, certificate-courses are held in
   certificates and refer to an existing :class:`Course` instance held
   elsewhere.

   A certificate can require several courses and one
   course can be required by several certificates.

   .. attribute:: course

      An instance of :class:`ICourse`.

   .. attribute:: level

      An integer telling the level to which this course applies.

   .. attribute:: core_or_elective

      A bool stating whether this course is required or optional to
      get the certificate.



Utilities
=========

:class:`CertificateFactory`
---------------------------

.. class:: CertificateFactory()

   .. attribute:: grok.name(u'waeup.Certificate')

   .. attribute:: grok.implements(IFactory)

   A named utility to deliver new instances of :class:`Certificate`
   without the need to import the implementation before:

     >>> from zope.component import createObject
     >>> mycertificate = createObject(u'waeup.Certificate')
     >>> mycertificate
     <waeup.university.certificate.Certificate object at 0x...>

Examples
========

Certificates
------------

We can create certificates:

    >>> from waeup.university.certificate import Certificate
    >>> mycertificate = Certificate()
    >>> mycertificate
    <waeup.university.certificate.Certificate object at 0x...>

Another way to create certificates is by asking for a factory called
``waeup.Certificate``. This way we can create a factory without
importing a class:

    >>> from zope.component import createObject
    >>> mycertificate = createObject(u'waeup.Certificate')
    >>> mycertificate
    <waeup.university.certificate.Certificate object at 0x...>

CertificateCourses
------------------

:class:`CertificateCourse` instances comply with the
:class:`ICertificateCourse` interface:

    >>> from waeup.interfaces import ICertificateCourse
    >>> from waeup.university.certificate import CertificateCourse
    >>> mycertcourse = CertificateCourse(None, 200, False)
    >>> ICertificateCourse.providedBy(mycertcourse)
    True

    >>> from zope.interface.verify import verifyObject
    >>> verifyObject(ICertificateCourse, mycertcourse)
    True

