def __init__(self):
        self.client = Client(key=config.STAFFJOY_API_KEY, url_base=config.STAFFJOY_URL_BASE)
        self.default_tz = pytz.timezone(config.DEFAULT_TZ)

        # To be defined later
        self.org = None
        self.loc = None
        self.role = None
        self.sched = None
        self.demand = None
Beispiel #2
0
    def __init__(self):
        self.client = Client(key=config.STAFFJOY_API_KEY,
                             env=config.ENV,
                             url_base="https://suite.bhstaffjoy.com/api/v2/")
        self.default_tz = pytz.timezone(config.DEFAULT_TZ)

        # To be defined later
        self.org = None
        self.loc = None
        self.role = None
        self.sched = None
        self.demand = None
Beispiel #3
0
 def __init__(self):
     self.client = Client(key=config.STAFFJOY_API_KEY, url_base=config.STAFFJOY_URL_BASE)
     self.default_tz = pytz.timezone(config.DEFAULT_TZ)
Beispiel #4
0
 def __init__(self):
     self.client = Client(key=config.STAFFJOY_API_KEY, env=config.ENV)
     self.default_tz = pytz.timezone(config.DEFAULT_TZ)
Beispiel #5
0
    def setUp(self):
        """
        Prepares for a specific test - sets up an organization, location, role,
        and worker with an admin, manager. There is an API Key available for
        sudo, admin, manager, and worker

        It is expected that all tasks done in the setup are done by sudo
        Do NOT change the permissions in setup here, nor in children setups
        """

        self.root_client = Client(key=self.ROOT_API_KEY,
                                  env=os.environ.get("ENV", "dev"))

        # Create an org
        self.organization = self.root_client.create_organization(
            name="Test Org %s" % datetime.datetime.utcnow().isoformat(), )

        self.organization.patch(active=True, )

        # Create a location
        self.location = self.organization.create_location(
            name="San Francisco", )

        # Create a role
        self.role = self.location.create_role(name="Tester", )

        # Add an admin
        self.admin = self.organization.create_admin(email=ADMIN_EMAIL, )

        # Add a manager
        self.manager = self.location.create_manager(email=MANAGER_EMAIL)

        # Add a worker
        self.worker = self.role.create_worker(email=WORKER_EMAIL,
                                              min_hours_per_workweek=20,
                                              max_hours_per_workweek=40)

        # Create necessary API Keys
        admin_resource = self.root_client.get_user(id=self.admin.get_id())
        manager_resource = self.root_client.get_user(id=self.manager.get_id())
        worker_resource = self.root_client.get_user(id=self.worker.get_id())

        # The user needs these attributes to access the api!
        admin_resource.patch(active=True, confirmed=True)
        manager_resource.patch(active=True, confirmed=True)
        worker_resource.patch(active=True, confirmed=True)

        admin_api_key_resource = admin_resource.create_apikey(
            name="admin smoke test key")
        manager_api_key_resource = manager_resource.create_apikey(
            name="manager smoke test key")
        worker_api_key_resource = worker_resource.create_apikey(
            name="worker smoke test key")

        self.admin_api_key = admin_api_key_resource.data.get("key")
        self.manager_api_key = manager_api_key_resource.data.get("key")
        self.worker_api_key = worker_api_key_resource.data.get("key")

        # for testing managers who can only control certain locations
        self.other_location = self.organization.create_location(
            name="Sacramento")

        self.other_role = self.other_location.create_role(name="Drivers")

        self.other_worker = self.other_role.create_worker(
            email=OTHER_WORKER_EMAIL,
            min_hours_per_workweek=20,
            max_hours_per_workweek=40)
        other_worker_resource = self.root_client.get_user(
            id=self.other_worker.get_id())
        other_worker_resource.patch(active=True, confirmed=True)

        # finally, run cron so that schedules are created for the recently created entities
        self.root_client.cron()
Beispiel #6
0
def test_org_crud():
    c = Client(key=KEY, env=ENV)

    # Just some basic stuff
    assert len(c.get_plans()) > 0

    logger.debug("Fetching organization")
    o = c.get_organization(TEST_ORG)

    assert o.get_id() == TEST_ORG

    location_count = len(o.get_locations())

    logger.debug("Changing organization name")
    o.patch(name="[In Progress] Continuous integration test")

    logger.debug("Creating a location")
    l = o.create_location(name="El Farolito", timezone="America/Los_Angeles")
    l_id = l.get_id()
    logger.debug("Location id {}".format(l_id))

    assert l.data.get("name") == "El Farolito"
    logger.debug("Changing location name")
    l.patch(name="La Taqueria")

    logger.debug("Checking that location is created")
    new_location_count = len(o.get_locations())
    assert new_location_count == (location_count + 1)
    del l

    logger.debug("Fetching location by ID")
    l = o.get_location(l_id)
    assert l.data.get("name") == "La Taqueria"

    logger.debug("Testing role crud")
    r = l.create_role(name="Kitchen")
    r.patch(name="Cocina")
    logger.debug("Adding worker")
    r.get_workers()
    r.create_worker(email=TEST_WORKER,
                    min_hours_per_workweek=30,
                    max_hours_per_workweek=40)

    logger.debug("Deleting worker")
    r.delete()

    logger.debug("Deleting location")
    l.delete()
    del l
    logger.debug("Making sure location has been archived")

    loc = o.get_location(l_id)
    assert loc.data.get("archived")

    logger.debug("Finishing up")
    o.patch(name="Continuous integration test")
    all_locations = o.get_locations()
    for location in all_locations:
        if not location.data.get("archived"):
            location.delete()

    for location in o.get_locations():
        assert location.data.get("archived")