Exemplo n.º 1
0
    def setup_new_with_dependencies(self):
        parent = Feature(id='parent', slug='parent')
        child1 = Feature(id='child1', slug='child1', parent='parent')
        child2 = Feature(id='child2', slug='child2', parent='parent')
        child3 = Feature(id='child3', slug='child3', parent='parent')
        grandchild = Feature(id='gchild', slug='grandchild', parent='child2')

        self.new_col.add(child1)
        self.new_col.add(parent)
        self.new_col.add(child2)
        self.new_col.add(child3)
        self.new_col.add(grandchild)
        resources = (parent, child1, child2, child3, grandchild)
        return resources, CollectionChangeset(self.orig_col, self.new_col)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
 def test_to_json_no_parent(self):
     feature = Feature(id="1", slug="web", name={"en": "Web"})
     expected = {
         "features": {
             "slug": "web",
             "name": {"en": "Web"},
         }
     }
     self.assertEqual(expected, feature.to_json_api())
Exemplo n.º 5
0
 def test_to_json_no_parent(self):
     feature = Feature(id='1', slug='web', name={'en': 'Web'})
     expected = {
         'features': {
             'slug': 'web',
             'name': {
                 'en': 'Web'
             },
         }
     }
     self.assertEqual(expected, feature.to_json_api())
Exemplo n.º 6
0
 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())
Exemplo n.º 7
0
 def test_features_root(self):
     root = Feature(id='root', slug='root', parent=None)
     self.new_col.add(root)
     cc = CollectionChangeset(self.orig_col, self.new_col)
     expected = {
         'new': OrderedDict([
             (('features', 'root'), root),
         ]),
         'changed': OrderedDict(),
         'deleted': OrderedDict(),
         'same': OrderedDict(),
     }
     self.assertEqual(expected, cc.changes)
Exemplo n.º 8
0
 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())
Exemplo n.º 9
0
 def test_to_json_null_parent(self):
     feature = Feature(
         id="1", slug="web", name={"en": "Web"}, parent=None)
     expected = {
         "features": {
             "slug": "web",
             "name": {"en": "Web"},
             "links": {
                 "parent": None
             }
         }
     }
     self.assertEqual(expected, feature.to_json_api())
Exemplo n.º 10
0
 def test_to_json_null_parent(self):
     feature = Feature(id='1', slug='web', name={'en': 'Web'}, parent=None)
     expected = {
         'features': {
             'slug': 'web',
             'name': {
                 'en': 'Web'
             },
             'links': {
                 'parent': None
             }
         }
     }
     self.assertEqual(expected, feature.to_json_api())
Exemplo n.º 11
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'))