コード例 #1
0
    def test_templates(self):
        """ Tests the user templates that are retrieved and saved in the db.
        """
        # Economia
        for i in range(1, dp.N_USR_ECONOMIA + 1):
            target = "u_eco_" + str(i)
            templates = ut.get_user_templates(self.session_context, target)
            template_idx = 0
            for template in templates:
                template_idx += 1
                if template_idx > dp.N_USR_ECONOMIA:
                    break
                nose.tools.eq_(template[1][:6], "u_eco_",
                               "A questionable template order was obtained " +
                               "for user %s: %s" % (target, templates))
            nose.tools.ok_(template_idx > 0, "No templates were generated")

        # Esportes
        for i in range(1, dp.N_USR_ESPORTES + 1):
            target = "u_esp_" + str(i)
            templates = ut.get_user_templates(self.session_context, target)
            template_idx = 0
            for template in templates:
                template_idx += 1
                if template_idx > dp.N_USR_ESPORTES:
                    break
                nose.tools.eq_(template[1][:6], "u_esp_",
                               "A questionable template order was obtained " +
                               "for user %s: %s" % (target, templates))
            nose.tools.ok_(template_idx > 0, "No templates were generated")

        # Música
        for i in range(1, dp.N_USR_MUSICA + 1):
            target = "u_mus_" + str(i)
            templates = ut.get_user_templates(self.session_context, target)
            template_idx = 0
            for template in templates:
                template_idx += 1
                if template_idx > dp.N_USR_MUSICA:
                    break
                nose.tools.eq_(template[1][:6], "u_mus_",
                               "A questionable template order was obtained " +
                               "for user %s: %s" % (target, templates))
            nose.tools.ok_(template_idx > 0, "No templates were generated")

        # Tecnologia
        for i in range(1, dp.N_USR_TECNOLOGIA + 1):
            target = "u_tec_" + str(i)
            templates = ut.get_user_templates(self.session_context, target)
            template_idx = 0
            for template in templates:
                template_idx += 1
                if template_idx > dp.N_USR_TECNOLOGIA:
                    break
                nose.tools.eq_(template[1][:6], "u_tec_",
                               "A questionable template order was obtained " +
                               "for user %s: %s" % (target, templates))
            nose.tools.ok_(template_idx > 0, "No templates were generated")
コード例 #2
0
def main(argv):
    if len(argv) < 2:
        msg = "You must specify the environment and the external user id"
        log.error(msg)
        return {"success": False, "message": msg}
    try:
        env = argv[0]
        user_id = argv[1]

        session = init_session(env)
        templates = [t for t in user_templates.get_user_templates(session, user_id)]

        return {"success": True, "user_id": user_id, "template_users": templates}

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