Example #1
0
def example(request, data):
    # This is a test fixture.  You will want to write your own, and
    # delete this one.  See the parallel
    # standard_yuixhr_test_template.js to see how to call fixtures
    # from your Javascript tests.
    #
    # A test fixture prepares the application for your test.  You can
    # do whatever you need here, including creating objects with an
    # object factory and logging the browser in as a given user.
    # You'll see an example below.
    #
    # Test fixtures can also return information back to your test.
    # Simply stuff the information you want into the "data" dict.  It
    # will be converted into JSON and sent back to the Javascript
    # caller.  Even Launchpad objects are converted, using the
    # standard lazr.restful mechanism.  This can be useful in several
    # ways.  Here are three examples.
    #
    # First, you can communicate information about the objects you
    # have created in the setup so that the Javascript knows what URLs
    # to use.  The code in this function has an example of this,
    # below.
    #
    # Second, you can return information about verifying some aspect
    # of the database state, so your Javascript test can easily assert
    # some fact that is not usually easily exposed to it.
    #
    # Finally, you can stash information that your teardown might
    # need.  You shouldn't usually need to clean anything up, because
    # the database and librarian are reset after every test, but if
    # you do set something up that needs an explicit teardown, you can
    # stash JSON-serializable information in "data" that the teardown
    # can use to know what to clean up.
    #
    # You can compose these setups and teardowns as well, using .extend.
    # There is a small example of this as well, below.
    #
    # As a full example, we will create an administrator and another
    # person; we will have the administrator create an object; we will
    # log the browser in as the other person; and we will stash
    # information about the object and the two people in the data
    # object.
    #
    # Again, this is a semi-random example.  Rip this whole fixture
    # out, and write the ones that you need.
    factory = LaunchpadObjectFactory()
    data['admin'] = factory.makeAdministrator()
    data['user'] = factory.makePerson()
    with person_logged_in(data['admin']):
        data['product'] = factory.makeProduct(owner=data['admin'])
    # This logs the browser in as a given person.  You need to use
    # this function for that purpose--the standard lp.testing login
    # functions are insufficient.
    login_as_person(data['user'])
    # Now we've done everything we said we would.  Let's imagine that
    # we had to also write some file to disk that would need to be
    # cleaned up at the end of the test.  We might stash information
    # about that in "data" too.
    data['some random data we might need for cleaning up'] = 'rutebega'
def setup(request, data):
    owner = factory.makePerson()
    with person_logged_in(owner):
        product = factory.makeProduct(name="my-test-project", owner=owner)
        product_series = factory.makeProductSeries(name="new-series",
                                                   product=product)
        data['product'] = product
        data['series_uri'] = canonical_url(product_series,
                                           path_only_if_possible=True)
        data['milestone_form_uri'] = (canonical_url(product_series) +
                                      '/+addmilestone/++form++')
    login_as_person(owner)
def setup(request, data):
    owner = factory.makePerson()
    with person_logged_in(owner):
        product = factory.makeProduct(name="my-test-project", owner=owner)
        product_series = factory.makeProductSeries(
            name="new-series", product=product)
        data['product'] = product
        data['series_uri'] = canonical_url(
            product_series, path_only_if_possible=True)
        data['milestone_form_uri'] = (
            canonical_url(product_series) + '/+addmilestone/++form++')
    login_as_person(owner)
def login_as_admin(request, data):
    data['user'] = factory.makeAdministrator()
    login_as_person(data['user'])
Example #5
0
def login_as_admin(request, data):
    data['user'] = factory.makeAdministrator()
    login_as_person(data['user'])