Coder Social home page Coder Social logo

flask-warehouse's People

Contributors

amrawadk avatar augustjd avatar dependabot[bot] avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

amrawadk

flask-warehouse's Issues

Cubby content or attribute updates overwrite metadata

  • Flask Warehouse version: 0.1.6
  • Python version: 3.6.9
  • Operating System: Ubuntu 18 LTS

Description

Cubby content/attribute updates overwrite metadata

What I Did

Here's a test case to highlight that behaviour

@mock_s3
def test_s3_service_metadata_preservation(app):
    """Sample pytest test function with the pytest fixture as an argument.
    """
    app.config['WAREHOUSE_DEFAULT_SERVICE'] = 's3'
    app.config['WAREHOUSE_DEFAULT_LOCATION'] = 'us-west-1'

    warehouse = Warehouse(app)

    assert warehouse.service is not None
    assert warehouse.service.id == 's3'

    with app.app_context():
        cubby = warehouse('s3:///something/beautiful')
        cubby.store(bytes=b'12345')

        # setting meta data works
        assert cubby.metadata() == {}
        metadata = {"tag": "value"}
        assert cubby.set_metadata(metadata)
        assert cubby.metadata() == metadata

        # setting mimetype works
        assert cubby.mimetype() == None
        cubby.set_mimetype("application/octet-stream")
        assert cubby.mimetype() == 'application/octet-stream'

        # this fails, setting mimetype actually overwrites metadata
        assert cubby.metadata() == metadata

The last check raises the following exception:

>           assert cubby.metadata() == metadata
E           AssertionError: assert {} == {'tag': 'value'}
E             Right contains more items:
E             {'tag': 'value'}
E             Full diff:
E             - {}
E             + {'tag': 'value'}

if we replace cubby.set_metadata with a content update, the test fails at the same point as well:

@mock_s3
def test_s3_service_metadata_preservation(app):
    """Sample pytest test function with the pytest fixture as an argument.
    """
    app.config['WAREHOUSE_DEFAULT_SERVICE'] = 's3'
    app.config['WAREHOUSE_DEFAULT_LOCATION'] = 'us-west-1'

    warehouse = Warehouse(app)

    assert warehouse.service is not None
    assert warehouse.service.id == 's3'

    with app.app_context():
        cubby = warehouse('s3:///something/beautiful')
        cubby.store(bytes=b'12345')

        # setting meta data works
        assert cubby.metadata() == {}
        metadata = {"tag": "value"}
        assert cubby.set_metadata(metadata)
        assert cubby.metadata() == metadata

        # setting mimetype works
        cubby.store(bytes=b'123456')
        assert cubby.retrieve() == b'123456'

        # this fails, setting mimetype actually overwrites metadata
        assert cubby.metadata() == metadata

I think it would be tedious to explicitly pass in each property of the copy along with each request, perhaps the ExtraArgs should be built for all requests using a custom property, and the it's updated explicilty inside each set_* function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.