def test_to_json(self): version = Version( id="2", version="0.2", status="unknown", supports=["1120", "1119"], browser="2") expected = { "versions": { "version": "0.2", "status": "unknown", "links": { "browser": "2" } } } self.assertEqual(expected, version.to_json_api())
def test_to_json(self): version = Version( id='2', version='0.2', status='unknown', supports=['1120', '1119'], browser='2') expected = { 'versions': { 'version': '0.2', 'status': 'unknown', 'links': { 'browser': '2' } } } self.assertEqual(expected, version.to_json_api())
def test_to_json(self): version = Version( id="2", version="0.2", status="unknown", supports=["1120", "1119"], browser="2") expected = { "versions": { "version": "0.2", "status": "unknown", "links": { "browser": "2" } } } self.assertEqual(expected, version.to_json_api())
def test_to_json(self): version = Version(id='2', version='0.2', status='unknown', supports=['1120', '1119'], browser='2') expected = { 'versions': { 'version': '0.2', 'status': 'unknown', 'links': { 'browser': '2' } } } self.assertEqual(expected, version.to_json_api())
def test_override_ids_to_match(self): # Setup collection resources browser = Browser(id='_chrome', slug='chrome', versions=['_version']) version = Version(id='_version', version='1.0', browser='_chrome') feature = Feature(id='_feature', slug='the-feature') support = Support(id='_support', feature='_feature', version='_version') maturity = Maturity(id='_maturity', slug='REC') specification = Specification(id='_spec', slug='css1', mdn_key='CSS1', maturity='_maturity') section = Section(id='_section', number={'en': '5.6.1'}, specification='_spec') self.col.add(browser) self.col.add(version) self.col.add(feature) self.col.add(support) self.col.add(maturity) self.col.add(specification) self.col.add(section) # JSON API representation changes expected = { 'versions': { 'version': '1.0', 'links': { 'browser': '_chrome', }, } } self.assertEqual(expected, version.to_json_api()) # Setup other collection with different IDs sync_browser = Browser(id='1', slug='chrome') sync_version = Version(id='2', version='1.0', browser='1') sync_feature = Feature(id='3', slug='the-feature') sync_support = Support(id='4', feature='3', version='2') sync_maturity = Maturity(id='5', slug='REC') sync_specification = Specification(id='6', slug='css1', mdn_key='CSS1', maturity='5') sync_section = Section(id='7', number={'en': '5.6.1'}, specification='6') sync_collection = Collection() sync_collection.add(sync_browser) sync_collection.add(sync_version) sync_collection.add(sync_feature) sync_collection.add(sync_support) sync_collection.add(sync_maturity) sync_collection.add(sync_specification) sync_collection.add(sync_section) # Lookup is by local ID self.assertEqual(browser, self.col.get('browsers', '_chrome')) self.assertEqual(None, self.col.get('browsers', '1')) # Synchronize IDs to the other collection self.col.override_ids_to_match(sync_collection) # Other IDs are now the same as original IDs self.assertEqual('1', browser.id.id) self.assertEqual('2', version.id.id) self.assertEqual('3', feature.id.id) self.assertEqual('4', support.id.id) self.assertEqual('5', maturity.id.id) self.assertEqual('6', specification.id.id) self.assertEqual('7', section.id.id) # Linked IDs are changed as well self.assertEqual('1', version.browser.id) self.assertEqual(['2'], browser.versions.ids) self.assertEqual('2', support.version.id) self.assertEqual('3', support.feature.id) self.assertEqual('5', specification.maturity.id) self.assertEqual('6', section.specification.id) # JSON API representation changes expected = { 'versions': { 'version': '1.0', 'links': { 'browser': '1', }, } } self.assertEqual(expected, version.to_json_api()) # Lookup is by original ID self.assertEqual(None, self.col.get('browsers', '_chrome')) self.assertEqual(browser, self.col.get('browsers', '1'))
def test_override_ids_to_match(self): # Setup collection resources browser = Browser( id='_chrome', slug='chrome', versions=['_version']) version = Version( id='_version', version='1.0', browser='_chrome') feature = Feature(id='_feature', slug='the-feature') support = Support( id='_support', feature='_feature', version='_version') maturity = Maturity(id='_maturity', slug='REC') specification = Specification( id='_spec', slug='css1', mdn_key='CSS1', maturity='_maturity') section = Section( id='_section', number={'en': '5.6.1'}, specification='_spec') self.col.add(browser) self.col.add(version) self.col.add(feature) self.col.add(support) self.col.add(maturity) self.col.add(specification) self.col.add(section) # JSON API representation changes expected = { "versions": { "version": "1.0", "links": { "browser": "_chrome", }, } } self.assertEqual(expected, version.to_json_api()) # Setup other collection with different IDs sync_browser = Browser(id='1', slug='chrome') sync_version = Version(id='2', version='1.0', browser='1') sync_feature = Feature(id='3', slug='the-feature') sync_support = Support(id='4', feature='3', version='2') sync_maturity = Maturity(id='5', slug='REC') sync_specification = Specification( id='6', slug='css1', mdn_key='CSS1', maturity='5') sync_section = Section( id='7', number={'en': '5.6.1'}, specification='6') sync_collection = Collection() sync_collection.add(sync_browser) sync_collection.add(sync_version) sync_collection.add(sync_feature) sync_collection.add(sync_support) sync_collection.add(sync_maturity) sync_collection.add(sync_specification) sync_collection.add(sync_section) # Lookup is by local ID self.assertEqual(browser, self.col.get('browsers', '_chrome')) self.assertEqual(None, self.col.get('browsers', '1')) # Synchronize IDs to the other collection self.col.override_ids_to_match(sync_collection) # Other IDs are now the same as original IDs self.assertEqual('1', browser.id.id) self.assertEqual('2', version.id.id) self.assertEqual('3', feature.id.id) self.assertEqual('4', support.id.id) self.assertEqual('5', maturity.id.id) self.assertEqual('6', specification.id.id) self.assertEqual('7', section.id.id) # Linked IDs are changed as well self.assertEqual('1', version.browser.id) self.assertEqual(['2'], browser.versions.ids) self.assertEqual('2', support.version.id) self.assertEqual('3', support.feature.id) self.assertEqual('5', specification.maturity.id) self.assertEqual('6', section.specification.id) # JSON API representation changes expected = { "versions": { "version": "1.0", "links": { "browser": "1", }, } } self.assertEqual(expected, version.to_json_api()) # Lookup is by original ID self.assertEqual(None, self.col.get('browsers', '_chrome')) self.assertEqual(browser, self.col.get('browsers', '1'))