Ejemplo n.º 1
0
 def test_3_address_only_letters(self):
     with self.app as app:
         response = app.post('/sms/address',
                             data={'Body': 'North Ave NW'},
                             follow_redirects=True)
         self.assertNotIn('counter', flask.session)
         self.assertEqual(response.status_code, 200)
Ejemplo n.º 2
0
 def test_3_too_many_images(self):
     with self.app as app:
         response = app.post('/sms',
                             data={'NumMedia': 2},
                             follow_redirects=True)
         self.assertNotIn('counter', flask.session)
         self.assertEqual(response.status_code, 200)
Ejemplo n.º 3
0
def test_wasted_time_route():
    rv = app.get('/time')
    check_content_type(rv.headers)
    resp = json.loads(rv.data)
    # make sure we get a response
    eq_(rv.status_code, 200)
    # make sure there are no users
    eq_(len(resp), 0)

    # create a user
    d = dict(
        first_name="User1First",
        last_name="User1Last",
        email="*****@*****.**"
    )
    rv = app.post('/users', data=d)
    check_content_type(rv.headers)
    eq_(rv.status_code, 201)

    # Verify we sent the right data back
    resp = json.loads(rv.data)
    eq_(resp["email"], "*****@*****.**")
    eq_(resp["first_name"], "User1First")
    eq_(resp["last_name"], "User1Last")

    # Get users again...should have one
    rv = app.get('/users')
    check_content_type(rv.headers)
    resp = json.loads(rv.data)
    # make sure we get a response
    eq_(rv.status_code, 200)
    eq_(len(resp), 1)

    # GET the user with specified ID
    rv = app.get('/users/%s' % resp[0]['id'])
    check_content_type(rv.headers)
    eq_(rv.status_code, 200)
    resp = json.loads(rv.data)
    eq_(resp["email"], "*****@*****.**")
    eq_(resp["first_name"], "User1First")
    eq_(resp["last_name"], "User1Last")

    # Try and add Duplicate User Email
    rv = app.post('/users', data=d)
    check_content_type(rv.headers)
    eq_(rv.status_code, 500)
Ejemplo n.º 4
0
 def test_1_address(self):
     with self.app as app:
         with app.session_transaction() as session:
             session['row_id'] = self.db.get_row_id()
         response = app.post('/sms/address',
                             data={'Body': '120 North Ave NW Atlanta, GA'},
                             follow_redirects=True)
         self.assertEqual(flask.session['counter'], 2)
         self.assertEqual(response.status_code, 200)
Ejemplo n.º 5
0
 def test_1_message_retrieval(self):
     with self.app as app:
         response = app.post('/sms',
                             data={
                                 'Body': 'RAT',
                                 'NumMedia': 0
                             },
                             follow_redirects=True)
         self.assertEqual(flask.session['counter'], 1)
         self.assertEqual(response.status_code, 200)
Ejemplo n.º 6
0
 def test_7_hole(self):
     with self.app as app:
         with app.session_transaction() as session:
             session['row_id'] = self.db.get_row_id()
         response = app.post('/sms/options',
                             data={'Body': 'G'},
                             follow_redirects=True)
         self.assertNotIn('counter', flask.session)
         self.assertNotIn('mistakes', flask.session)
         self.assertEqual(response.status_code, 200)
Ejemplo n.º 7
0
 def test_messages(self):
     """Ensure that a user can post messages."""
     self.login(app.app.config['USERNAME'], app.app.config['PASSWORD'])
     rv = app.post('/add',
                   data=dict(title='<Hello>',
                             text='<strong>HTML</strong> allowed here'),
                   follow_redirects=True)
     assert b'No entries here so far' not in rv.data
     assert b'&lt;Hello&gt;' in rv.data
     assert b'<strong>HTML</strong> allowed here' in rv.data
Ejemplo n.º 8
0
    def test_paymentSucess(self):

        paymentData = {
            'CreditCardNumber': '1234561234561234',
            'CardHolder': 'John De',
            'ExpirationDate': '2025-05-17 00:00:00',
            'SecurityCode': '123',
            'Amount': 100000
        }

        response = app.post('/args', paymentData)

        assert response == 200
Ejemplo n.º 9
0
    def test_amountInvalid():

        paymentData = {
            'CreditCardNumber': '1234561234561234',
            'CardHolder': 'John De',
            'ExpirationDate': '2025-05-17 00:00:00',
            'SecurityCode': '123',
            'Amount': -1
        }

        response = app.post('/args', paymentData)

        assert response == 400
Ejemplo n.º 10
0
    def test_url_generate_view(self, mocker, app):
        mocker.patch('lib.redis.Redis', return_value=FakeStrictRedis())
        payload = {
            'category': 'auto',
            'protocol': 'http',
            'origin': 'www.google.com'
        }
        response = app.post('/generate', data=payload)
        assert 'url' in response.get_json()
        assert response.mimetype == 'application/json'
        assert response.status_code == 200

        url = response.get_json()['url']
        shorten = url.split('/')[-1]
        payload = {
            'category': 'specific',
            'protocol': 'http',
            'origin': 'www.google.com',
            'specific': shorten
        }
        response = app.post('/generate', data=payload)
        assert response.mimetype == 'application/json'
        assert response.status_code == 409

        wanted = 'my-shorten-url'
        payload = {
            'category': 'specific',
            'protocol': 'http',
            'origin': 'www.google.com',
            'specific': wanted
        }
        response = app.post('/generate', data=payload)
        assert 'url' in response.get_json()
        url = response.get_json()['url']
        shorten = url.split('/')[-1]
        assert response.mimetype == 'application/json'
        assert response.status_code == 200
        assert shorten == wanted
Ejemplo n.º 11
0
 def test_redirect_view(self, mocker, app):
     mocker.patch('lib.redis.Redis', return_value=FakeStrictRedis())
     payload = {
         'category': 'auto',
         'protocol': 'http',
         'origin': 'www.google.com'
     }
     response = app.post('/generate', data=payload)
     url = response.get_json()['url']
     shorten = url.split('/')[-1]
     redirect = app.get('/%s' % shorten)
     location = redirect.headers.get('Location')
     assert redirect.status_code == 302
     assert location == '%s://%s' % (payload['protocol'], payload['origin'])
Ejemplo n.º 12
0
 def test_2_image_retrieval(self):
     with self.app as app:
         response = app.post(
             '/sms',
             data={
                 'NumMedia':
                 1,
                 'MessageSid':
                 'test',
                 'MediaUrl0':
                 'https://s3-external-1.amazonaws.com/media.twiliocdn.com/AC97a88511292ce1c17f84155aae5fdff5/45d0bd8624bc06dd74c042cd2fa3eff7'
             },
             follow_redirects=True)
         self.assertEqual(flask.session['counter'], 1)
         self.assertEqual(response.status_code, 200)
Ejemplo n.º 13
0
 def terminate(self, app):
     app.post("/update_timescale",
              data=json.dumps({'timescale': 0}),
              content_type='application/json')
Ejemplo n.º 14
0
def login(username, password):
    return app.post('users/', data=dict(
            name=username,
            password=password
            ), follow_redirects=True)
Ejemplo n.º 15
0
            status=400)
    finally:
        await mem_cache.set('agent', ag
                            )  #  in case agent state changes over process_post


@app.post('/api/v0/agent-nym-lookup')
@doc.summary('Lookup agent nym on ledger by DID')
@doc.consumes(openapi_model(agent, 'agent-nym-lookup'), location='body')
@doc.produces(dict)
@doc.tag('{} as Base Agent'.format(profile))
async def process_post_agent_nym_lookup(request):
    return await _process_post(request)


@cond_deco(app.post('/api/v0/agent-nym-send'), offers(agent, 'agent-nym-send'))
@cond_deco(doc.summary('Send agent nym to ledger'),
           offers(agent, 'agent-nym-send'))
@cond_deco(
    doc.consumes(openapi_model(agent, 'agent-nym-send'), location='body'),
    offers(agent, 'agent-nym-send'))
@cond_deco(doc.produces(dict), offers(agent, 'agent-nym-send'))
@cond_deco(
    doc.tag('{} as Trust Anchor{}'.format(
        profile, '' if is_native(agent, 'agent-nym-send') else ' by Proxy')),
    offers(agent, 'agent-nym-send'))
async def process_post_agent_nym_send(request):
    return await _process_post(request)


@app.post('/api/v0/agent-endpoint-lookup')