def test_simple_projection(self, analyses): """Test simple projection of 2 simple arguments.""" projection = ['ecosystem', 'package'] # pypi has order 1 expected = {'ecosystem': 'npm', 'package': 'arrify'} returned = do_projection(projection, analyses[0]) assert expected == returned
def test_combined_projection(self, analyses): """Combining simple fields with nested fields.""" projection = ['analyses.digests', 'analyses.a', 'package'] expected = {'analyses': {'a': 'b', 'digests': { 'details': [{'artifact': True, 'sha1': '6be7ae55bae2372c7be490321bbe5ead278bb51b'}]}}, 'package': 'flexmock'} result = do_projection(projection, analyses[1]) assert expected == result
def test_nested_projection(self, analyses): """Test whether filtering of nested JSON returns just desired field.""" projection = ['analyses.digests'] expected = {'analyses': {'digests': {'details': [{'artifact': True, 'sha1': '6be7ae55bae2372c7be490321bbe5ead278bb51b'}]}}} result = do_projection(projection, analyses[1]) assert expected == result
def test_three_level_fields(self, analyses): """Testing third level of nested JSON""" projection = ['analyses.digests.details', 'audit.audit.audit'] expected = {'audit': {'audit': {'audit': 'audit'}}, 'analyses': {'digests': {'details': [{'artifact': True, 'sha1': '6be7ae55bae2372c7be490321bbe5ead278bb51b'}]}}} result = do_projection(projection, analyses[2]) assert expected == result
def test_empty_projection(self, analyses): """Test that no fields are returned for empty projection.""" projection = [] expected = {} result = do_projection(projection, analyses[0]) assert expected == result
def test_none_projection(self, analyses): """Check that original model is returned if projection is None.""" projection = None returned = do_projection(projection, analyses[0]) expected = analyses[0].to_dict() assert expected == returned
def test_none_projection(self, analyses): """If projection is None original model should be returned""" projection = None returned = do_projection(projection, analyses[0]) expected = analyses[0].to_dict() assert expected == returned
def test_empty_projection(self, analyses): """In this case no fields should be returned""" projection = [] expected = {} result = do_projection(projection, analyses[0]) assert expected == result