def test_get_data_id_without_subpath(self):
     maturity = Maturity(id='2')
     spec = Specification(id='22', maturity='2', mdn_key='SPEC')
     section = Section(id='_sec', specification='22')
     collection = Collection()
     collection.add(maturity)
     collection.add(spec)
     collection.add(section)
     self.assertEqual(('sections', 'SPEC', ''), section.get_data_id())
Exemple #2
0
 def test_get_data_id_with_empty_subpath(self):
     maturity = Maturity(id='2')
     spec = Specification(id='22', maturity='2', mdn_key='SPEC')
     section = Section(id='_sec', specification='22', subpath={})
     collection = Collection()
     collection.add(maturity)
     collection.add(spec)
     collection.add(section)
     self.assertEqual(('sections', 'SPEC', ''), section.get_data_id())
 def test_get_data_id_without_subpath(self):
     maturity = Maturity(id="2")
     spec = Specification(id="22", maturity="2", mdn_key="SPEC")
     feature = Feature(id="222")
     section = Section(id="_sec", specification="22", features=["222"])
     collection = Collection()
     collection.add(maturity)
     collection.add(spec)
     collection.add(feature)
     collection.add(section)
     self.assertEqual(('sections', 'SPEC', ''), section.get_data_id())
 def test_get_data_id_with_number(self):
     maturity = Maturity(id='2')
     spec = Specification(id='22', maturity='2', mdn_key='SPEC')
     section = Section(
         id='_sec', specification='22',
         number={'en': '1.2.3'}, subpath={'en': '#123'})
     collection = Collection()
     collection.add(maturity)
     collection.add(spec)
     collection.add(section)
     self.assertEqual(('sections', 'SPEC', '#123'), section.get_data_id())
 def test_get_data_id_without_subpath(self):
     maturity = Maturity(id="2")
     spec = Specification(id="22", maturity="2", mdn_key="SPEC")
     feature = Feature(id="222")
     section = Section(id="_sec", specification="22", features=["222"])
     collection = Collection()
     collection.add(maturity)
     collection.add(spec)
     collection.add(feature)
     collection.add(section)
     self.assertEqual(('sections', 'SPEC', ''), section.get_data_id())
Exemple #6
0
 def test_get_data_id_with_number(self):
     maturity = Maturity(id='2')
     spec = Specification(id='22', maturity='2', mdn_key='SPEC')
     section = Section(id='_sec',
                       specification='22',
                       number={'en': '1.2.3'},
                       subpath={'en': '#123'})
     collection = Collection()
     collection.add(maturity)
     collection.add(spec)
     collection.add(section)
     self.assertEqual(('sections', 'SPEC', '#123'), section.get_data_id())
 def test_without_number(self):
     section = Section(
         name={'en': 'section foo'}, subpath={'en': '/foo'},
         specification='_spec')
     expected = {
         "sections": {
             "name": {'en': 'section foo'},
             "subpath": {'en': '/foo'},
             "links": {
                 "specification": "_spec",
             }}}
     self.assertEqual(expected, section.to_json_api())
 def test_without_number(self):
     section = Section(
         name={'en': 'section foo'}, subpath={'en': '/foo'},
         specification='_spec')
     expected = {
         'sections': {
             'name': {'en': 'section foo'},
             'subpath': {'en': '/foo'},
             'links': {
                 'specification': '_spec',
             }}}
     self.assertEqual(expected, section.to_json_api())
 def test_without_number(self):
     section = Section(
         name={'en': 'section foo'}, subpath={'en': '/foo'},
         specification='_spec')
     expected = {
         "sections": {
             "name": {'en': 'section foo'},
             "subpath": {'en': '/foo'},
             "links": {
                 "specification": "_spec",
             }}}
     self.assertEqual(expected, section.to_json_api())
 def test_get_data_id_with_number(self):
     maturity = Maturity(id="2")
     spec = Specification(id="22", maturity="2", mdn_key="SPEC")
     feature = Feature(id="222")
     section = Section(
         id="_sec", specification="22", features=["222"],
         number={"en": "1.2.3"}, subpath={"en": "#123"})
     collection = Collection()
     collection.add(maturity)
     collection.add(spec)
     collection.add(feature)
     collection.add(section)
     self.assertEqual(('sections', 'SPEC', '#123'), section.get_data_id())
 def test_get_data_id_with_number(self):
     maturity = Maturity(id="2")
     spec = Specification(id="22", maturity="2", mdn_key="SPEC")
     feature = Feature(id="222")
     section = Section(
         id="_sec", specification="22", features=["222"],
         number={"en": "1.2.3"}, subpath={"en": "#123"})
     collection = Collection()
     collection.add(maturity)
     collection.add(spec)
     collection.add(feature)
     collection.add(section)
     self.assertEqual(('sections', 'SPEC', '#123'), section.get_data_id())
Exemple #12
0
    def test_get_all_by_data_id(self):
        browser = Browser(id='1', slug='chrome')
        self.col.add(browser)
        version = Version(id='2', version='1.0', browser='1')
        self.col.add(version)
        feature = Feature(id='3', slug='the-feature')
        self.col.add(feature)
        support = Support(id='4', feature='3', version='2')
        self.col.add(support)
        maturity = Maturity(id='5', slug='REC')
        self.col.add(maturity)
        specification = Specification(id='6',
                                      slug='css1',
                                      mdn_key='CSS1',
                                      maturity='5')
        self.col.add(specification)
        section = Section(id='7', subpath={'en': '#561'}, specification='6')
        self.col.add(section)

        index = self.col.get_all_by_data_id()
        expected = {
            ('browsers', 'chrome'): browser,
            ('versions', 'chrome', '1.0'): version,
            ('features', 'the-feature'): feature,
            ('supports', 'the-feature', 'chrome', '1.0'): support,
            ('maturities', 'REC'): maturity,
            ('specifications', 'CSS1'): specification,
            ('sections', 'CSS1', '#561'): section,
        }
        self.assertEqual(expected, index)
Exemple #13
0
 def test_new_reference_with_dependencies(self):
     feature = Feature(id='feature',
                       slug='feature',
                       name={'en': 'Feature'},
                       sections=['section'])
     reference = Reference(id='reference',
                           feature='feature',
                           section='section')
     section = Section(id='section', specification='spec')
     spec = Specification(id='spec',
                          mdn_key='SPEC',
                          slug='spec',
                          maturity='maturity')
     maturity = Maturity(id='maturity', slug='mat')
     self.new_col.add(feature)
     self.new_col.add(reference)
     self.new_col.add(section)
     self.new_col.add(spec)
     self.new_col.add(maturity)
     cc = CollectionChangeset(self.orig_col, self.new_col)
     expected_order = OrderedDict([
         (('maturities', 'mat'), maturity),
         (('specifications', 'SPEC'), spec),
         (('sections', 'SPEC', ''), section),
         (('features', 'feature'), feature),
         (('references', 'feature', 'SPEC', ''), reference),
     ])
     expected = {
         'new': expected_order,
         'same': OrderedDict(),
         'changed': OrderedDict(),
         'deleted': OrderedDict(),
     }
     self.assertEqual(expected_order.keys(), cc.changes['new'].keys())
     self.assertEqual(expected, cc.changes)
Exemple #14
0
 def test_without_number(self):
     section = Section(name={'en': 'section foo'},
                       subpath={'en': '/foo'},
                       specification='_spec')
     expected = {
         'sections': {
             'name': {
                 'en': 'section foo'
             },
             'subpath': {
                 'en': '/foo'
             },
             'links': {
                 'specification': '_spec',
             }
         }
     }
     self.assertEqual(expected, section.to_json_api())
Exemple #15
0
 def test_new_section_with_dependencies(self):
     section = Section(id='section', specification='spec')
     spec = Specification(id='spec',
                          mdn_key='SPEC',
                          slug='spec',
                          maturity='maturity')
     maturity = Maturity(id='maturity', slug='mat')
     self.new_col.add(section)
     self.new_col.add(spec)
     self.new_col.add(maturity)
     cc = CollectionChangeset(self.orig_col, self.new_col)
     expected_order = OrderedDict([
         (('maturities', 'mat'), maturity),
         (('specifications', 'SPEC'), spec),
         (('sections', 'SPEC', ''), section),
     ])
     expected = {
         'new': expected_order,
         'same': OrderedDict(),
         'changed': OrderedDict(),
         'deleted': OrderedDict(),
     }
     self.assertEqual(expected_order.keys(), cc.changes['new'].keys())
     self.assertEqual(expected, cc.changes)
Exemple #16
0
    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'))