def test_context_creation_and_retrieval(self):
        """ Context should be created and retrieved successfully.
        """
        tracer_id = "d551573a-01dc-41b2-b197-ea8afb7fbac1".replace("-", "")

        with new_context(tracer_id=tracer_id):
            context = get_context()
            nose.tools.eq_(tracer_id, str(context.tracer_id))
def main(argv):
    if len(argv) < 4:
        msg = "You must specify the environment, the external_user_id, " \
            "the external_product_id, and the impression date"
        log.error(msg)
        return {"success": False, "message": msg}
    try:
        # command-line arguments
        env = argv[0]
        user = argv[1]
        product = argv[2]
        impression_date = dateutil.parser.parse(argv[3])

        impression = {"external_user_id": user, "external_product_id": product, "created_at": impression_date}

        session = init_session(env)

        maintenance.process_impression(session, impression)

        return {"success": True}

    except Exception:
        log.exception('Exception on {0}:'.format(__name__))
        return {"success": False, "message": traceback.format_exc()}


if __name__ == '__main__':
    with new_context():
        print(main(sys.argv[1:]))
Exemple #3
0
 def work():
     env = args[0] if len(args) > 0 and is_valid_customer_identifier(args[0]) else None
     with new_context(tracer_id=self._get_tracer_id(), endpoint=self._get_endpoint_name(), environment=env):
         return method(*args)