jarus / flask-testing

Unittest extensions for Flask
http://pythonhosted.org/Flask-Testing/
Other
501 stars 110 forks source link

404 when testing app #125

Closed Seluj78 closed 1 year ago

Seluj78 commented 6 years ago

I get a 404 not found using this code:

from flask import Flask
from flask_testing import LiveServerTestCase

class MyTest(LiveServerTestCase):

    def create_app(self):
        app = Flask(__name__)
        app.config['TESTING'] = True

        # Set to 0 to have the OS pick the port.
        app.config['LIVESERVER_PORT'] = 0

        return app

    def test_server_is_up_and_running(self):
        response = urllib2.urlopen(self.get_server_url())
        self.assertEqual(response.code, 200)

The error :

➜  instant-server git:(master) ✗ nosetests --verbose instant_server/tests/test_app.py
test_server_is_up_and_running (instant_server.tests.test_app.MyTest) ... ERROR

======================================================================
ERROR: test_server_is_up_and_running (instant_server.tests.test_app.MyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/seluj78/instant-server/instant_server/tests/test_app.py", line 17, in test_server_is_up_and_running
    response = urllib2.urlopen(self.get_server_url())
  File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 435, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 548, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 473, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 556, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 404: NOT FOUND
-------------------- >> begin captured logging << --------------------
pynamodb.settings: INFO: Override settings for pynamo not available /etc/pynamodb/global_default_settings.py
pynamodb.settings: INFO: Using Default settings value
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.session: DEBUG: Loading variable config_file from defaults.
botocore.session: DEBUG: Loading variable credentials_file from defaults.
botocore.session: DEBUG: Loading variable data_path from defaults.
botocore.loaders: DEBUG: Loading JSON file: /usr/local/lib/python2.7/dist-packages/boto3/data/s3/2006-03-01/resources-1.json
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.session: DEBUG: Loading variable region from defaults.
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.session: DEBUG: Loading variable ca_bundle from defaults.
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.session: DEBUG: Loading variable credentials_file from defaults.
botocore.session: DEBUG: Loading variable config_file from defaults.
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.session: DEBUG: Loading variable metadata_service_timeout from defaults.
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.session: DEBUG: Loading variable metadata_service_num_attempts from defaults.
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.credentials: DEBUG: Looking for credentials via: env
botocore.credentials: DEBUG: Looking for credentials via: assume-role
botocore.credentials: DEBUG: Looking for credentials via: shared-credentials-file
botocore.credentials: INFO: Found credentials in shared credentials file: ~/.aws/credentials
botocore.loaders: DEBUG: Loading JSON file: /usr/local/lib/python2.7/dist-packages/botocore/data/endpoints.json
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.hooks: DEBUG: Event choose-service-name: calling handler <function handle_service_name_alias at 0x7f08e97745f0>
botocore.loaders: DEBUG: Loading JSON file: /usr/local/lib/python2.7/dist-packages/botocore/data/s3/2006-03-01/service-2.json
botocore.hooks: DEBUG: Event creating-client-class.s3: calling handler <function add_generate_presigned_post at 0x7f08e97aeed8>
botocore.hooks: DEBUG: Event creating-client-class.s3: calling handler <function _handler at 0x7f08e96a7cf8>
botocore.hooks: DEBUG: Event creating-client-class.s3: calling handler <function add_generate_presigned_url at 0x7f08e97aecf8>
botocore.args: DEBUG: The s3 config key is not a dictionary type, ignoring its value of: None
botocore.endpoint: DEBUG: Setting s3 timeout as (60, 60)
botocore.loaders: DEBUG: Loading JSON file: /usr/local/lib/python2.7/dist-packages/botocore/data/_retry.json
botocore.client: DEBUG: Registering retry handlers for service: s3
botocore.client: DEBUG: Defaulting to S3 virtual host style addressing with path style addressing fallback.
boto3.resources.factory: DEBUG: Loading s3:s3
boto3.resources.factory: DEBUG: Loading s3:Bucket
boto3.resources.model: DEBUG: Renaming Bucket attribute name
botocore.hooks: DEBUG: Event creating-resource-class.s3.Bucket: calling handler <function _handler at 0x7f08d5335320>
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.session: DEBUG: Loading variable region from defaults.
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.session: DEBUG: Loading variable ca_bundle from defaults.
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.session: DEBUG: Loading variable api_versions from defaults.
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.hooks: DEBUG: Event choose-service-name: calling handler <function handle_service_name_alias at 0x7f08e97745f0>
botocore.hooks: DEBUG: Event creating-client-class.s3: calling handler <function add_generate_presigned_post at 0x7f08e97aeed8>
botocore.hooks: DEBUG: Event creating-client-class.s3: calling handler <function _handler at 0x7f08e96a7cf8>
botocore.hooks: DEBUG: Event creating-client-class.s3: calling handler <function add_generate_presigned_url at 0x7f08e97aecf8>
botocore.args: DEBUG: The s3 config key is not a dictionary type, ignoring its value of: None
botocore.endpoint: DEBUG: Setting s3 timeout as (60, 60)
botocore.client: DEBUG: Registering retry handlers for service: s3
botocore.client: DEBUG: Defaulting to S3 virtual host style addressing with path style addressing fallback.
rospy.topics: INFO: topicmanager initialized
pynamodb.connection.base: DEBUG: Calling Scan with arguments {'TableName': 'uai-scope-db', 'ReturnConsumedCapacity': 'TOTAL'}
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.session: DEBUG: Loading variable config_file from defaults.
botocore.session: DEBUG: Loading variable credentials_file from defaults.
botocore.session: DEBUG: Loading variable ca_bundle from defaults.
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.session: DEBUG: Loading variable api_versions from defaults.
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.session: DEBUG: Loading variable data_path from defaults.
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.session: DEBUG: Loading variable credentials_file from defaults.
botocore.session: DEBUG: Loading variable config_file from defaults.
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.session: DEBUG: Loading variable metadata_service_timeout from defaults.
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.session: DEBUG: Loading variable metadata_service_num_attempts from defaults.
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.credentials: DEBUG: Looking for credentials via: env
botocore.credentials: DEBUG: Looking for credentials via: assume-role
botocore.credentials: DEBUG: Looking for credentials via: shared-credentials-file
botocore.credentials: INFO: Found credentials in shared credentials file: ~/.aws/credentials
botocore.loaders: DEBUG: Loading JSON file: /usr/local/lib/python2.7/dist-packages/botocore/data/endpoints.json
botocore.session: DEBUG: Loading variable profile from defaults.
botocore.hooks: DEBUG: Event choose-service-name: calling handler <function handle_service_name_alias at 0x7f08e97745f0>
botocore.loaders: DEBUG: Loading JSON file: /usr/local/lib/python2.7/dist-packages/botocore/data/dynamodb/2012-08-10/service-2.json
botocore.hooks: DEBUG: Event creating-client-class.dynamodb: calling handler <function add_generate_presigned_url at 0x7f08e97aecf8>
botocore.args: DEBUG: The s3 config key is not a dictionary type, ignoring its value of: None
botocore.endpoint: DEBUG: Setting dynamodb timeout as (60, 60)
botocore.loaders: DEBUG: Loading JSON file: /usr/local/lib/python2.7/dist-packages/botocore/data/_retry.json
botocore.client: DEBUG: Registering retry handlers for service: dynamodb
botocore.hooks: DEBUG: Event before-parameter-build.dynamodb.Scan: calling handler <function generate_idempotent_uuid at 0x7f08e9774848>
botocore.hooks: DEBUG: Event request-created.dynamodb.Scan: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7f08d3884110>>
botocore.hooks: DEBUG: Event choose-signer.dynamodb.Scan: calling handler <function set_operation_specific_signer at 0x7f08e9774758>
botocore.auth: DEBUG: Calculating signature using v4 auth.
botocore.auth: DEBUG: CanonicalRequest:
POST
/

content-type:application/x-amz-json-1.0
host:dynamodb.us-east-1.amazonaws.com
x-amz-date:20180604T064524Z
x-amz-target:DynamoDB_20120810.Scan

content-type;host;x-amz-date;x-amz-target
857863cdd577036fc1f05583126f37d04c0b64af3e8841eb5a55e3d25134c89b
botocore.auth: DEBUG: StringToSign:
AWS4-HMAC-SHA256
20180604T064524Z
20180604/us-east-1/dynamodb/aws4_request
9d52e402a9a98a97d64ac0cf30dbfd44f2f4cda98416b2b7f630ddef379d5b37
botocore.auth: DEBUG: Signature:
720cd990be464a88479ec69d1940a272a224347291542a91caf65e75264439db
botocore.vendored.requests.packages.urllib3.connectionpool: INFO: Starting new HTTPS connection (1): dynamodb.us-east-1.amazonaws.com
botocore.vendored.requests.packages.urllib3.connectionpool: DEBUG: "POST / HTTP/1.1" 200 368
pynamodb.connection.base: DEBUG:  Scan consumed 0.5 units
pynamodb.models: DEBUG: Fetching first scan page
pynamodb.connection.base: DEBUG: Calling DescribeTable with arguments {'TableName': 'uai-scope-db'}
botocore.hooks: DEBUG: Event before-parameter-build.dynamodb.DescribeTable: calling handler <function generate_idempotent_uuid at 0x7f08e9774848>
botocore.hooks: DEBUG: Event request-created.dynamodb.DescribeTable: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7f08d3884110>>
botocore.hooks: DEBUG: Event choose-signer.dynamodb.DescribeTable: calling handler <function set_operation_specific_signer at 0x7f08e9774758>
botocore.auth: DEBUG: Calculating signature using v4 auth.
botocore.auth: DEBUG: CanonicalRequest:
POST
/

content-type:application/x-amz-json-1.0
host:dynamodb.us-east-1.amazonaws.com
x-amz-date:20180604T064525Z
x-amz-target:DynamoDB_20120810.DescribeTable

content-type;host;x-amz-date;x-amz-target
d29747b2bd844e5a7fa7adbb43bd20d1b859dd1e6c253955a9f818a6261484cd
botocore.auth: DEBUG: StringToSign:
AWS4-HMAC-SHA256
20180604T064525Z
20180604/us-east-1/dynamodb/aws4_request
d29bb910b87b25b29bdf443bf12bde2353af0d0a43ab07d8702d37045e32f703
botocore.auth: DEBUG: Signature:
0d1c0175a4fbf1ac867ad24cee37f7453484fa36b3a8162bfc3b93b2e98804db
botocore.vendored.requests.packages.urllib3.connectionpool: DEBUG: "POST / HTTP/1.1" 200 477
pynamodb.connection.base: DEBUG: Calling PutItem with arguments {'Item': {u'name': {u'S': u'admin'}, 'children': {'L': [{'S': u'Mecachrome'}, {'S': u'Simu'}]}}, 'TableName': 'uai-scope-db', 'ReturnConsumedCapacity': 'TOTAL'}
botocore.hooks: DEBUG: Event before-parameter-build.dynamodb.PutItem: calling handler <function generate_idempotent_uuid at 0x7f08e9774848>
botocore.hooks: DEBUG: Event request-created.dynamodb.PutItem: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7f08d3884110>>
botocore.hooks: DEBUG: Event choose-signer.dynamodb.PutItem: calling handler <function set_operation_specific_signer at 0x7f08e9774758>
botocore.auth: DEBUG: Calculating signature using v4 auth.
botocore.auth: DEBUG: CanonicalRequest:
POST
/

content-type:application/x-amz-json-1.0
host:dynamodb.us-east-1.amazonaws.com
x-amz-date:20180604T064525Z
x-amz-target:DynamoDB_20120810.PutItem

content-type;host;x-amz-date;x-amz-target
d885f736663979a2e9f8b7a5b5b16efd8aa9b8953286e3feb3b9c781879b2c3b
botocore.auth: DEBUG: StringToSign:
AWS4-HMAC-SHA256
20180604T064525Z
20180604/us-east-1/dynamodb/aws4_request
167845124c6cd61ddda44edcee92448f6438cb636566b8584a4f1d1e7f6ae926
botocore.auth: DEBUG: Signature:
d118922958d28cffe736701be3d0a07757f57c79eaf4ac884ec1652e166eac50
botocore.vendored.requests.packages.urllib3.connectionpool: DEBUG: "POST / HTTP/1.1" 200 69
pynamodb.connection.base: DEBUG:  PutItem consumed 1.0 units
pynamodb.connection.base: DEBUG: Calling PutItem with arguments {'Item': {u'name': {u'S': u'Simu'}, 'parent': {'S': u'admin'}, 'children': {'L': [{'S': u'simu_clement'}]}}, 'TableName': 'uai-scope-db', 'ReturnConsumedCapacity': 'TOTAL'}
botocore.hooks: DEBUG: Event before-parameter-build.dynamodb.PutItem: calling handler <function generate_idempotent_uuid at 0x7f08e9774848>
botocore.hooks: DEBUG: Event request-created.dynamodb.PutItem: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7f08d3884110>>
botocore.hooks: DEBUG: Event choose-signer.dynamodb.PutItem: calling handler <function set_operation_specific_signer at 0x7f08e9774758>
botocore.auth: DEBUG: Calculating signature using v4 auth.
botocore.auth: DEBUG: CanonicalRequest:
POST
/

content-type:application/x-amz-json-1.0
host:dynamodb.us-east-1.amazonaws.com
x-amz-date:20180604T064525Z
x-amz-target:DynamoDB_20120810.PutItem

content-type;host;x-amz-date;x-amz-target
e42f42662dbc19b6d48f8036fa3bddf99c8125bf8bf1ea05a117c153f118066c
botocore.auth: DEBUG: StringToSign:
AWS4-HMAC-SHA256
20180604T064525Z
20180604/us-east-1/dynamodb/aws4_request
7e070f1683e5bf45e03336d2998462c24a9dd12d28bf6af5a4fd6a93599b0f7d
botocore.auth: DEBUG: Signature:
0392d818b76b3a0d0a8db30990bc685740cd16224c774a112f116939d9418349
botocore.vendored.requests.packages.urllib3.connectionpool: DEBUG: "POST / HTTP/1.1" 200 69
pynamodb.connection.base: DEBUG:  PutItem consumed 1.0 units
--------------------- >> end captured logging << ---------------------

----------------------------------------------------------------------
Ran 1 test in 0.033s

FAILED (errors=1)

I've added a sleep(1000) to connect to the server and try the url but the views seems to not be loaded

AndrewFairbairn commented 6 years ago

I am also getting a 404 when following the basic LiveServerTestCase implementation. I can see that the server is starting up, and requests are being logged to and from the server, however all I get as responses are 404s, despite valid URLs being requested:

I am running on OS X with Python 3.6

ypgsh commented 5 years ago

@AndrewFairbairn the doc said only python 2.x supported

vackosar commented 5 years ago

@ypgsh no, python 3 support was added in 2004. Only some Twill is not supported

vackosar commented 5 years ago

I am also getting 404

vackosar commented 5 years ago

@AndrewFairbairn @Seluj78 try removing app.config['TESTING'] = True that worked for me.

i-am-nika commented 5 years ago

I get the same error. Removing app.config['TESTING'] = True doesn't work for me