def test_it_creates_a_slide_deck_from_the_internal_template(
        do_gql_post, gql_query, mk_gql_variables, s3_client):
    # Create a mock bucket to store the ppt file.
    s3_client.create_bucket(
        Bucket=Env.SLIDE_DECKS_BUCKET_NAME(),
        CreateBucketConfiguration={'LocationConstraint': 'us-west-1'})

    gql_variables = mk_gql_variables()

    body = do_gql_post(gql_query, gql_variables).get('body')
    assert body.get('errors', None) is None
    jslide_deck = body['data']['createSlideDeck']['slideDeck']
    assert jslide_deck['url'] is not None
    assert Env.SLIDE_DECKS_BUCKET_NAME() in jslide_deck['url']
Exemplo n.º 2
0
def input_test():
    e = Env()

    inp1 = parse('(1 2)')
    assert show(inp1) == '(1 2 ())'

    inp2 = parse('(+ 1 2)')
    assert show(inp2) == '(+ 1 2 ())'
    assert eval_lisp(inp2, e) == 3

    inp3 = parse('(1 2 3 4)')
    assert show(inp3) == '(1 2 3 4 ())'

    inp4 = parse('(+ (+ 3 2) 3)')
    assert eval_lisp(inp4, e) == 8
    assert show(inp4) == '(+ (+ 3 2 ()) 3 ())'

    inp5 = parse('(1 (4 5))')
    assert show(inp5) == '(1 (4 5 ()) ())'

    eval_lisp(parse('(def a 10)'), e)
    assert eval_lisp(parse('(+ a 3)'), e) == 13

    eval_lisp(parse('(def b (lambda (x) (* x x)))'), e)
    assert eval_lisp(parse('(b 3)'), e) == 9

    print('input tests passed')
Exemplo n.º 3
0
def test_macro():
    e = Env()
    p = parse('(def t (macro (x) (+ x x)))')
    c = parse('(t (+ 1 2))')
    eval_lisp(p, e)
    assert eval_lisp(c, e) == 6

    print('macro passed')
Exemplo n.º 4
0
def test_quote():
    e = Env()
    p = parse('(defn a (x)'
              ' ((defn g (z) (+ z x)) (` g))'
              ')')
    eval_lisp(p, e)
    c = parse('((a 7) 3)')
    assert eval_lisp(c, e) == 10

    e = Env()
    p = parse('(defn a (x)'
              ' ((defn g (z) (+ z x)) `g)'
              ')')
    eval_lisp(p, e)
    c = parse('((a 7) 3)')
    assert eval_lisp(c, e) == 10

    print('quote passed')
Exemplo n.º 5
0
def test_high_order_func():
    e = Env()
    p = parse('(defn a (x)'
              ' ((defn g (z) (+ z x)) (` g))'
              ')')
    eval_lisp(p, e)
    c = parse('((a 7) 3)')
    assert eval_lisp(c, e) == 10

    e = Env()
    p = parse('(defn a (x)'
              ' ((defn g () (+ 3 x)) (` g))'
              ')')
    eval_lisp(p, e)
    c = parse('((a 1))')
    assert eval_lisp(c, e) == 4

    print('high order passed')
Exemplo n.º 6
0
def test_fib():
    e = Env()
    fib = parse('(def fib (lambda (n) ('
                'cond ((== n 1) 1)'
                ' ((== n 0) 0)'
                ' (else (+ (fib (- n 1)) (fib (- n 2)))))'
                '))')
    assert show(
        fib) == '(def fib (lambda (n ()) (cond ((== n 1 ()) (1 ())) ((== n 0 ()) (0 ())) (else (+ (fib (- n 1 ()) ()) (fib (- n 2 ()) ()) ()) ()) ()) ()) ())'
    eval_lisp(fib, e)
    exec_fib = parse('(fib 10)')
    assert eval_lisp(exec_fib, e) == 55
def test_it_creates_a_slide_deck_from_an_external_template(
        do_gql_post, gql_query, mk_gql_variables, s3_client):
    # Create a mock bucket to store the ppt file.
    s3_client.create_bucket(
        Bucket=Env.SLIDE_DECKS_BUCKET_NAME(),
        CreateBucketConfiguration={'LocationConstraint': 'us-west-1'})

    template_url = 'https://afakedomainname.com/file.pptx'
    gql_variables = mk_gql_variables()
    gql_variables['templateUrl'] = template_url

    with open('assets/template_ki_empty.pptx', 'rb') as f:
        pptx = f.read()

    with responses.RequestsMock() as rsps:
        rsps.add(responses.GET, template_url, body=pptx, status=200)

        body = do_gql_post(gql_query, gql_variables).get('body')
        assert body.get('errors', None) is None
        jslide_deck = body['data']['createSlideDeck']['slideDeck']
        assert jslide_deck['url'] is not None
        assert Env.SLIDE_DECKS_BUCKET_NAME() in jslide_deck['url']
Exemplo n.º 8
0
def env():
    '''Test Environment'''
    with patch.object(Env, 'db_connect'):
        return Env('test',
                   conf={
                       'pg_username': '******',
                       'pg_password': '',
                       'google_id': '',
                       'google_secret': '',
                       'cookie_secret': 'secret',
                       'path_attachments': '/tmp/attachments',
                       'search_lang': ['simple']
                   })
Exemplo n.º 9
0
def test_simple_coms():
    e = Env()

    emp = parse('(defn empty? (x) (and (== (car x) None) (== (cdr x) None)))')
    f = parse('(empty? (` (1 2)))')
    t = parse('(empty? ())')
    qua = parse(
        '(defn qua (x)('
        'if (empty? x)'
        '()'
        '(cons (* 2 (car x)) (qua (cdr x)))'
        '))'
    )
    q = parse('(qua (qua (` (1 3))))')
    eval_lisp(emp, e)
    eval_lisp(qua, e)
    assert not eval_lisp(f, e)
    assert eval_lisp(t, e)
    assert show(eval_lisp(q, e)) == '(4 12 ())'

    print('simple tests passed')
Exemplo n.º 10
0
def test_client():
    assert Synapse.client() is not None
    profile = Synapse.client().getUserProfile(refresh=True)
    assert profile['userName'] == Env.SYNAPSE_USERNAME()
Exemplo n.º 11
0
def test_core():
    l1 = cons(1, 2)
    l2 = cons(1, EmptyList())
    l3 = cons(cons(1, 2), cons(3, 4))
    l4 = cons(1, cons(2, EmptyList()))
    l5 = cons(BinOp('+'), cons(7, cons(4, EmptyList())))
    l6 = cons(PredOp('<'), cons(1, cons(2, EmptyList())))
    l7 = cons(PredOp('>'), cons(1, cons(2, EmptyList())))
    l8 = cons(PredOp('and'), cons(True, cons(True, EmptyList())))
    l9 = cons(PredOp('and'), cons(True, cons(False, EmptyList())))
    l10 = cons(PredOp('or'), cons(False, cons(False, EmptyList())))
    l11 = cons(PredOp('or'), cons(False, cons(True, EmptyList())))
    l12 = cons(PredOp('or'), cons(True, cons(False, EmptyList())))

    l13 = cons(BinOp('*'), cons(10, cons(cons(BinOp('+'), cons(2, cons(3, EmptyList()))), EmptyList())))

    l14 = cons(SpecialForm('def'), cons(Symbol('a'), cons(3, EmptyList())))
    l15 = cons(Symbol('a'), EmptyList())
    l16 = cons(SpecialForm('def'), cons(Symbol('a'), cons('asd', EmptyList())))
    l17 = cons(Symbol('a'), EmptyList())

    l18 = cons(BinOp('+'), cons(cons(BinOp('+'), cons(2, cons(3, EmptyList()))), cons(3, EmptyList())))

    pre1 = cons(PredOp('>'), cons(1, cons(2, cons(3, EmptyList()))))
    pre2 = cons(PredOp('>'), cons(2, cons(1, cons(3, EmptyList()))))
    pre3 = cons(PredOp('and'), cons(cons(PredOp('>'), cons(6, cons(2, EmptyList()))), cons(pre1, EmptyList())))

    assert show(l1) == '(1 2)', 'l1 Not passed'
    assert show(l2) == '(1 ())', 'l2 Not passed'
    assert show(l3) == '((1 2) (3 4))', 'l3 Not passed'
    assert show(l4) == '(1 2 ())', 'l4 Not passed'
    assert show(l5) == '(+ 7 4 ())', 'l5 Not passed'
    assert show(l6) == '(< 1 2 ())', 'l6 Not passed'
    assert show(l7) == '(> 1 2 ())', 'l7 Not passed'
    assert show(l8) == '(and True True ())', 'l8 Not passed'
    assert show(l9) == '(and True False ())', 'l9 Not passed'
    assert show(l10) == '(or False False ())', 'l10 Not passed'
    assert show(l11) == '(or False True ())', 'l11 Not passed'
    assert show(l12) == '(or True False ())', 'l12 Not passed'
    assert show(l13) == '(* 10 (+ 2 3 ()) ())', 'l13 Not passed'

    assert show(l14) == '(def a 3 ())', 'l14 Not passed'
    assert show(l16) == '(def a "asd" ())', 'l16 Not passed'

    assert show(l18) == '(+ (+ 2 3 ()) 3 ())', 'l18 Not passed'

    assert show(pre1) == '(> 1 2 3 ())', 'pre1 Not passed'
    assert show(pre2) == '(> 2 1 3 ())', 'pre2 Not passed'
    assert show(pre3) == '(and (> 6 2 ()) (> 1 2 3 ()) ())', 'pre3 Not passed'

    print('show tests passed')

    e = Env()
    assert eval_lisp(l5, e) == 11, 'eval l5 not passed'
    assert eval_lisp(l6, e), 'eval l6 not passed'
    assert not eval_lisp(l7, e), 'eval l7 not passed'
    assert eval_lisp(l8, e), 'eval l8 not passed'
    assert not eval_lisp(l9, e), 'eval l9 not passed'
    assert not eval_lisp(l10, e), 'eval l10 not passed'
    assert eval_lisp(l11, e), 'eval l11 not passed'
    assert eval_lisp(l12, e), 'eval l12 not passed'
    assert eval_lisp(l13, e) == 50, 'eval l13 not passed'
    assert eval_lisp(l14, e) == 'OK', 'eval l14 not passed'
    assert eval_lisp(l15, e) == 3, 'eval l15 not passed'
    assert eval_lisp(l16, e) == 'OK', 'eval l16 not passed'
    assert eval_lisp(l17, e) == 'asd', 'eval l17 not passed'
    assert eval_lisp(l18, e) == 8, 'eval l18 not passed'
    assert not eval_lisp(pre1, e), 'eval pre1 not passed'
    assert not eval_lisp(pre2, e), 'eval pre2 not passed'
    assert not eval_lisp(pre3, e), 'eval pre3 not passed'

    print('eval tests passed')
    print('core tests passed')
Exemplo n.º 12
0
def test_cond():
    e = Env()
    p = parse('(cond ((< 3 1) 1) ((< 2 3) 2))')
    assert eval_lisp(p, e) == 2

    print('cond test passed')
Exemplo n.º 13
0
def test_if():
    assert eval_lisp(parse('(if (< 3 5) (12) (22))'), Env()) == 12
Exemplo n.º 14
0
    def mutate(self,
               info,
               title,
               sprint_id,
               participants,
               end_date,
               sprint_questions,
               background,
               deliverables,
               key_findings,
               next_steps,
               value,
               **kwargs):
        template_url = kwargs.get('template_url', None)

        presentation = None

        if template_url and template_url != '':
            logger.debug('Fetching template file: {0}'.format(template_url))
            r = requests.get(template_url)
            logger.debug('Done fetching template file.')

            if r.status_code == 200:
                fd, tmp_filename = tempfile.mkstemp(suffix='.pptx')

                try:
                    with os.fdopen(fd, 'wb') as tmp:
                        tmp.write(r.content)

                    presentation = Presentation(tmp_filename)
                finally:
                    if os.path.isfile(tmp_filename):
                        os.remove(tmp_filename)
            else:
                raise Exception(
                    'Could not load template_url: {0}'.format(template_url))
        else:
            presentation = Presentation('assets/template_ki_empty.pptx')

        SLD_TITLE = 'Title Slide - Text Only'
        SLD_HEAD_COPY = 'Full Width Head'
        SLD_HEAD_BULLETS = 'Full Width Head + Bullets'
        # SLD_HEAD_SUBHEAD_COPY = 3
        # SLD_HEAD_ONLY = 7
        SLD_INSTRUCTIONS = 'INSTRUCTIONS'

        title_layout = presentation.slide_layouts.get_by_name(SLD_TITLE)
        plain_layout = presentation.slide_layouts.get_by_name(SLD_HEAD_COPY)
        bullet_layout = presentation.slide_layouts.get_by_name(SLD_HEAD_BULLETS)

        if title_layout is None or plain_layout is None or bullet_layout is None:
            raise Exception('Slide deck provided is not using the correct template')

        # deliverables

        slide = presentation.slides.add_slide(bullet_layout)
        shapes = slide.shapes
        title_shape = shapes.title
        body_shape = CreateSlideDeck.get_placeholder(slide, 'Text Placeholder 1')
        title_shape.text = 'Deliverables'
        tf = body_shape.text_frame
        for item in deliverables:
            p = tf.add_paragraph()
            p.text = item
            p.level = 1
        CreateSlideDeck.add_notes(slide)

        CreateSlideDeck.move_to_front(presentation)

        # questions

        slide = presentation.slides.add_slide(bullet_layout)
        shapes = slide.shapes
        title_shape = shapes.title
        body_shape = CreateSlideDeck.get_placeholder(slide, 'Text Placeholder 1')
        title_shape.text = 'Sprint Questions'
        tf = body_shape.text_frame
        for item in sprint_questions:
            p = tf.add_paragraph()
            p.text = item
            p.level = 1
        CreateSlideDeck.add_notes(slide)

        CreateSlideDeck.move_to_front(presentation)

        # value hypothesis

        slide = presentation.slides.add_slide(plain_layout)
        title_shape = CreateSlideDeck.get_placeholder(slide, 'Title 2')
        body_shape = CreateSlideDeck.get_placeholder(slide, 'Text Placeholder 1')
        title_shape.text = "Value Hypothesis"
        body_shape.text = value
        CreateSlideDeck.add_notes(slide)

        CreateSlideDeck.move_to_front(presentation)

        # background

        slide = presentation.slides.add_slide(plain_layout)
        title_shape = CreateSlideDeck.get_placeholder(slide, 'Title 2')
        body_shape = CreateSlideDeck.get_placeholder(slide, 'Text Placeholder 1')
        title_shape.text = "Background"
        body_shape.text = background
        CreateSlideDeck.add_notes(slide)

        CreateSlideDeck.move_to_front(presentation)

        # title slide

        slide = presentation.slides.add_slide(title_layout)
        title_shape = CreateSlideDeck.get_placeholder(slide, 'Title 1')
        body_shape1 = CreateSlideDeck.get_placeholder(slide, 'Text Placeholder 2')
        body_shape2 = CreateSlideDeck.get_placeholder(slide, 'Text Placeholder 3')
        title_shape.text = 'Rally {0}: {1}'.format(sprint_id, title)
        body_shape1.text = 'Completed {0}'.format(end_date)
        body_shape2.text = 'Rally participants {0}'.format(', '.join(participants))
        CreateSlideDeck.add_notes(slide)

        CreateSlideDeck.move_to_front(presentation)

        # data/methods/results are already part of the deck

        # key findings

        slide = presentation.slides.add_slide(bullet_layout)
        shapes = slide.shapes
        title_shape = shapes.title
        body_shape = CreateSlideDeck.get_placeholder(slide, 'Text Placeholder 1')
        title_shape.text = 'Key Findings'
        tf = body_shape.text_frame
        for item in key_findings:
            p = tf.add_paragraph()
            p.text = item
            p.level = 1
        CreateSlideDeck.add_notes(slide)

        # next steps

        slide = presentation.slides.add_slide(bullet_layout)
        shapes = slide.shapes
        title_shape = shapes.title
        body_shape = CreateSlideDeck.get_placeholder(slide, 'Text Placeholder 1')
        title_shape.text = 'Next Steps'
        tf = body_shape.text_frame
        items = next_steps
        for item in items:
            p = tf.add_paragraph()
            p.text = item
            p.level = 1
        CreateSlideDeck.add_notes(slide)

        # remove INSTRUCTIONS slide before saving

        slides = list(presentation.slides)
        slides2 = list(presentation.slides._sldIdLst)
        rm_idx = next((i for i in range(len(slides))
                       if slides[i].slide_layout.name == SLD_INSTRUCTIONS), None)
        if rm_idx != None:
            presentation.slides._sldIdLst.remove(slides2[rm_idx])

        timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S%f")
        ppt_file_name = 'Rally_{0}_report-out-{1}.pptx'.format(sprint_id, timestamp)
        ppt_file_path = os.path.join(tempfile.gettempdir(), ppt_file_name)

        presentation.save(ppt_file_path)

        # Store on S3
        try:
            logger.debug('Uploading SlideDeck to S3.')

            s3 = boto3.resource('s3')

            s3.meta.client.upload_file(ppt_file_path, Env.SLIDE_DECKS_BUCKET_NAME(), ppt_file_name)

            logger.debug('Finished uploading SlideDeck to S3.')

            # Generate a presigned URL that expires.
            presigned_url = s3.meta.client.generate_presigned_url(
                'get_object',
                Params={'Bucket': Env.SLIDE_DECKS_BUCKET_NAME(), 'Key': ppt_file_name},
                ExpiresIn=Env.SLIDE_DECKS_URL_EXPIRES_IN_SECONDS()
            )
        finally:
            if os.path.isfile(ppt_file_path):
                os.remove(ppt_file_path)

        new_slide_deck = SlideDeck(url=presigned_url)

        return CreateSlideDeck(slide_deck=new_slide_deck)
Exemplo n.º 15
0
def get_full(argv):
    from core import Env, db

    env = Env()

    parser, cmd = get_base(argv)
    cmd('sync')\
        .arg('-t', '--target', default='fast', choices=sync.choices)\
        .arg('-l', '--only', nargs='*', help='sync only these labels')\
        .arg('-d', '--disabled', action='store_true')\
        .arg('-u', '--username')\
        .exe(lambda a: (
            sync(Env(a.username), a.target, a.disabled, only=a.only))
        )

    cmd('parse')\
        .arg('-u', '--username')\
        .arg('-l', '--limit', type=int, default=1000)\
        .arg('-o', '--offset', type=int, default=0)\
        .arg('-w', '--where')\
        .exe(lambda a: parse(Env(a.username), a.limit, a.offset, a.where))

    cmd('thrids')\
        .arg('-u', '--username')\
        .arg('-c', '--clear', action='store_true')\
        .exe(lambda a: thrids(Env(a.username), a.clear))

    cmd('db-init')\
        .arg('username')\
        .arg('-r', '--reset', action='store_true')\
        .arg('-p', '--password')\
        .exe(lambda a: db.init(Env(a.username), a.password, a.reset))

    cmd('migrate')\
        .arg('-u', '--username')\
        .arg('-i', '--init', action='store_true')\
        .arg('-c', '--clean', action='store_true')\
        .exe(lambda a: migrate(Env(a.username), a.init, a.clean))

    cmd('shell').exe(lambda a: shell(env))
    cmd('run').exe(lambda a: run(env))
    cmd('web', add_help=False).exe(lambda a: grun('web', ' '.join(a)))
    cmd('async', add_help=False).exe(lambda a: grun('async', ' '.join(a)))

    cmd('test', add_help=False).exe(lambda a: (
        sh('py.test --ignore=node_modules --confcutdir=tests %s' % ' '.join(a))
    ))

    cmd('npm', help='update nodejs packages')\
        .exe(lambda a: npm())

    cmd('static', help='generate front')\
        .arg('-f', '--force', action='store_true')\
        .arg('-c', '--clean', action='store_true')\
        .exe(lambda a: front(env, a.force, a.clean))

    cmd('touch').exe(lambda a: sh(
        './manage.py static &&'
        'supervisorctl pid async web nginx | xargs kill -s HUP'
    ))
    return parser