Пример #1
0
    def __init__(self, request):
        """
        :param request: This is the pyramid request object.

        The request is passed into the view which is using this API.

        """
        self.log = get_log("PyramidGymkhana")
        self._settings = request.registry.settings

        self.log.info("configuring Gymkhana instance.")
        strict_redis = redis_from_config(self._settings)

        self.log.info("request.gym now refers to the Gymkhana instance.")
        self.api = Gymkhana(strict_redis)
Пример #2
0
def test_gymkana_dump_and_load_single(log, redis_server):
    """Test I can load and dump and individual gymkhana competition.
    """
    cfg = {"gymkhana.redis.host": redis_server.hostname, "gymkhana.redis.port": redis_server.port}

    org_id = "org-user-2719963b00964c01b42b5d81c998fd05"

    org_setup = """\
... action
    ... view
        ... edit
            ... create
... anyone
    ... bob
... anything
    ... slots
        ... public
        ... private
... permissions
    *** deny anyone to action anything wt 10
    *** allow bob.sprocket to create slots wt 30
    *** allow anyone to view public wt 50
... aliases
    *** bob=user-2719963b00964c01b42b5d81c998fd05
    """

    strict_redis = redis_from_config(cfg)
    gym = gymkhana.Gymkhana(strict_redis)

    r = len(gym.list_competitions())
    assert r == 0

    gym.add_competition(org_id, org_setup)

    r = len(gym.list_competitions())
    assert r == 1

    dumped = gym.dump_competition(org_id)

    assert dumped == org_setup
Пример #3
0
def test_gymkana(log, redis_server):
    """Test the 'backend' of the gymkhana connecting to redis.
    """
    cfg = {"gymkhana.redis.host": redis_server.hostname, "gymkhana.redis.port": redis_server.port}

    org_id = "org-user-2719963b00964c01b42b5d81c998fd05"

    org_setup = """\
... action
    ... view
        ... edit
            ... create
... anyone
    ... bob
... anything
    ... slots
        ... public
        ... private
... permissions
    *** deny anyone to action anything wt 10
    *** allow bob.sprocket to create slots wt 30
    *** allow anyone to view public wt 50
... aliases
    *** bob=user-2719963b00964c01b42b5d81c998fd05
    """

    strict_redis = redis_from_config(cfg)

    # Configure the gymkhana redis set up, then recover it ready for testing:
    gym = gymkhana.Gymkhana(strict_redis)

    # Check we currently house no competitions:
    results = gym.list_competitions()
    assert len(results) == 0

    # Check the org_id is not present prior to loading:
    assert gym.has_competition(org_id) is False

    # A get on an unknown competition should be caught:
    with pytest.raises(gymkhana.CompetitionNotFoundError):
        gym.get_competition(org_id)

    # Load in the competition set up and check its now present:
    gym.add_competition(org_id, org_setup)
    assert gym.has_competition(org_id) is True

    # The organisation should now be present:
    results = gym.list_competitions()
    assert results == [org_id]

    # update the competition set up and check its now present:
    gym.update_competition(org_id, org_setup)
    assert gym.has_competition(org_id) is True

    # Test I can remove an organisation and that it is gone:
    gym.remove_competition(org_id)

    assert gym.has_competition(org_id) is False

    results = gym.list_competitions()
    assert results == []

    # calling remove again will not cause problems.
    gym.remove_competition(org_id)