コード例 #1
0
    def test_new_versions_to_existing_browser(self):
        """When order matters, new items update the parent item."""
        browser = Browser(id='_b', slug='browser', versions=['u'])
        v_1 = Version(id='1.0', version='1.0', browser='_b')
        self.orig_col.add(browser)
        self.orig_col.add(v_1)

        browser_new = Browser(id='_b',
                              slug='browser',
                              versions=['u', '1.0', '2.0'])
        v_unknown = Version(id='u', version=None, browser='_b')
        v_1_same = Version(id='1.0', version='1.0', browser='_b')
        v_2 = Version(id='2.0', version='2.0', browser='_b')
        self.new_col.add(browser_new)
        self.new_col.add(v_unknown)
        self.new_col.add(v_1_same)
        self.new_col.add(v_2)
        cc = CollectionChangeset(self.orig_col, self.new_col)
        expected_order = OrderedDict([
            (('versions', 'browser', ''), v_unknown),
            (('versions', 'browser', '2.0'), v_2),
        ])
        expected = {
            'new': expected_order,
            'same': OrderedDict([
                (('versions', 'browser', '1.0'), v_1_same),
            ]),
            'changed': OrderedDict([
                (('browsers', 'browser'), browser_new),
            ]),
            'deleted': OrderedDict(),
        }
        self.assertEqual(expected_order.keys(), cc.changes['new'].keys())
        self.assertEqual(expected, cc.changes)
コード例 #2
0
 def test_new_browser_with_ordered_versions(self):
     """When order matters, creation order is sort order."""
     browser = Browser(id='_b',
                       slug='browser',
                       versions=['u', '1.0', '2.0'])
     v_unknown = Version(id='u', version=None, browser='_b')
     v_1 = Version(id='1.0', version='1.0', browser='_b')
     v_2 = Version(id='2.0', version='2.0', browser='_b')
     self.new_col.add(browser)
     self.new_col.add(v_1)
     self.new_col.add(v_unknown)
     self.new_col.add(v_2)
     cc = CollectionChangeset(self.orig_col, self.new_col)
     expected_order = OrderedDict([
         (('browsers', 'browser'), browser),
         (('versions', 'browser', ''), v_unknown),
         (('versions', 'browser', '1.0'), v_1),
         (('versions', 'browser', '2.0'), v_2),
     ])
     expected = {
         'new': expected_order,
         'same': OrderedDict(),
         'changed': OrderedDict(),
         'deleted': OrderedDict(),
     }
     self.assertEqual(expected_order.keys(), cc.changes['new'].keys())
     self.assertEqual(expected, cc.changes)
コード例 #3
0
 def test_get_data_id_null_version(self):
     version = Version(id='254', version=None, browser='2')
     browser = Browser(id='2', slug='the_browser')
     collection = Collection()
     collection.add(version)
     collection.add(browser)
     self.assertEqual(('versions', 'the_browser', ''),
                      version.get_data_id())
コード例 #4
0
 def test_get_data_id_null_version(self):
     version = Version(id="254", version=None, browser="2")
     browser = Browser(id="2", slug="the_browser")
     collection = Collection()
     collection.add(version)
     collection.add(browser)
     self.assertEqual(
         ('versions', 'the_browser', ''), version.get_data_id())
コード例 #5
0
 def test_get_data_id_null_version(self):
     version = Version(id='254', version=None, browser='2')
     browser = Browser(id='2', slug='the_browser')
     collection = Collection()
     collection.add(version)
     collection.add(browser)
     self.assertEqual(
         ('versions', 'the_browser', ''), version.get_data_id())
コード例 #6
0
 def test_get_data_id_null_version(self):
     version = Version(id="254", version=None, browser="2")
     browser = Browser(id="2", slug="the_browser")
     collection = Collection()
     collection.add(version)
     collection.add(browser)
     self.assertEqual(
         ('versions', 'the_browser', ''), version.get_data_id())
コード例 #7
0
 def test_filter_by_property(self):
     browser = Browser(id='_firefox', slug='firefox')
     version1 = Version(version='1.0', browser='_firefox')
     version2 = Version(version='2.0', browser='_firefox')
     self.col.add(browser)
     self.col.add(version1)
     self.col.add(version2)
     versions = self.col.filter('versions', version='1.0')
     self.assertEqual([version1], versions)
コード例 #8
0
 def test_filter_link_is_none(self):
     browser = Browser(id='_firefox', slug='firefox')
     version1 = Version(version=None, browser='_firefox')
     version2 = Version(version='1.0')
     self.col.add(browser)
     self.col.add(version1)
     self.col.add(version2)
     versions = self.col.filter('versions', browser=None)
     self.assertEqual([version2], versions)
コード例 #9
0
 def test_filter_link(self):
     browser = Browser(id='_firefox', slug='firefox')
     version1 = Version(version=None, browser='_firefox')
     version2 = Version(version='1.0', browser='_firefox')
     self.col.add(browser)
     self.col.add(version1)
     self.col.add(version2)
     versions = self.col.filter('versions', browser='_firefox')
     self.assertEqual(2, len(versions))
     self.assertTrue(version1 in versions)
     self.assertTrue(version2 in versions)
コード例 #10
0
    def test_load_by_json(self):
        rep = {
            "versions": {
                "id": "2",
                "version": "0.2",
                "release_day": None,
                "retirement_day": None,
                "status": "unknown",
                "release_notes_uri": None,
                "note": None,
                "order": 1,
                "links": {
                    "browser": "1",
                    "supports": [
                        "1120", "1119", "1118", "1117", "1116", "1115", "1114",
                        "1113", "1112", "1111", "1110", "1109",
                    ],
                    "history": ["2"],
                    "history_current": "2"
                }
            },
        }
        version = Version()
        self.assertIsNone(version.id)
        self.assertIsNone(version.version)
        self.assertIsNone(version.release_day)
        self.assertIsNone(version.retirement_day)
        self.assertIsNone(version.status)
        self.assertIsNone(version.release_notes_uri)
        self.assertIsNone(version.note)
        self.assertIsNone(version.supports)
        self.assertIsNone(version.history)
        self.assertIsNone(version.history_current)

        version.from_json_api(rep)
        self.assertIsInstance(version.id, Link)
        self.assertEqual("2", version.id.id)
        self.assertEqual("0.2", version.version)
        self.assertIsNone(version.release_day)
        self.assertIsNone(version.retirement_day)
        self.assertEqual('unknown', version.status)
        self.assertIsNone(version.release_notes_uri)
        self.assertIsNone(version.note)
        self.assertIsInstance(version.supports, LinkList)
        self.assertEqual(
            ['1120', '1119', '1118', '1117', '1116', '1115', '1114', '1113',
             '1112', '1111', '1110', '1109'],
            version.supports.ids)
        self.assertIsInstance(version.history_current, Link)
        self.assertEqual("2", version.history_current.id)
        self.assertIsInstance(version.history, LinkList)
        self.assertEqual(["2"], version.history.ids)
コード例 #11
0
    def test_load_by_json(self):
        rep = {
            "versions": {
                "id": "2",
                "version": "0.2",
                "release_day": None,
                "retirement_day": None,
                "status": "unknown",
                "release_notes_uri": None,
                "note": None,
                "order": 1,
                "links": {
                    "browser": "1",
                    "supports": [
                        "1120", "1119", "1118", "1117", "1116", "1115", "1114",
                        "1113", "1112", "1111", "1110", "1109",
                    ],
                    "history": ["2"],
                    "history_current": "2"
                }
            },
        }
        version = Version()
        self.assertIsNone(version.id)
        self.assertIsNone(version.version)
        self.assertIsNone(version.release_day)
        self.assertIsNone(version.retirement_day)
        self.assertIsNone(version.status)
        self.assertIsNone(version.release_notes_uri)
        self.assertIsNone(version.note)
        self.assertIsNone(version.supports)
        self.assertIsNone(version.history)
        self.assertIsNone(version.history_current)

        version.from_json_api(rep)
        self.assertIsInstance(version.id, Link)
        self.assertEqual("2", version.id.id)
        self.assertEqual("0.2", version.version)
        self.assertIsNone(version.release_day)
        self.assertIsNone(version.retirement_day)
        self.assertEqual('unknown', version.status)
        self.assertIsNone(version.release_notes_uri)
        self.assertIsNone(version.note)
        self.assertIsInstance(version.supports, LinkList)
        self.assertEqual(
            ['1120', '1119', '1118', '1117', '1116', '1115', '1114', '1113',
             '1112', '1111', '1110', '1109'],
            version.supports.ids)
        self.assertIsInstance(version.history_current, Link)
        self.assertEqual("2", version.history_current.id)
        self.assertIsInstance(version.history, LinkList)
        self.assertEqual(["2"], version.history.ids)
コード例 #12
0
    def test_load_by_json(self):
        rep = {
            'versions': {
                'id': '2',
                'version': '0.2',
                'release_day': None,
                'retirement_day': None,
                'status': 'unknown',
                'release_notes_uri': None,
                'note': None,
                'order': 1,
                'links': {
                    'browser': '1',
                    'supports': [
                        '1120', '1119', '1118', '1117', '1116', '1115', '1114',
                        '1113', '1112', '1111', '1110', '1109',
                    ],
                    'history': ['2'],
                    'history_current': '2'
                }
            },
        }
        version = Version()
        self.assertIsNone(version.id)
        self.assertIsNone(version.version)
        self.assertIsNone(version.release_day)
        self.assertIsNone(version.retirement_day)
        self.assertIsNone(version.status)
        self.assertIsNone(version.release_notes_uri)
        self.assertIsNone(version.note)
        self.assertIsNone(version.supports)
        self.assertIsNone(version.history)
        self.assertIsNone(version.history_current)

        version.from_json_api(rep)
        self.assertIsInstance(version.id, Link)
        self.assertEqual('2', version.id.id)
        self.assertEqual('0.2', version.version)
        self.assertIsNone(version.release_day)
        self.assertIsNone(version.retirement_day)
        self.assertEqual('unknown', version.status)
        self.assertIsNone(version.release_notes_uri)
        self.assertIsNone(version.note)
        self.assertIsInstance(version.supports, LinkList)
        self.assertEqual(
            ['1120', '1119', '1118', '1117', '1116', '1115', '1114', '1113',
             '1112', '1111', '1110', '1109'],
            version.supports.ids)
        self.assertIsInstance(version.history_current, Link)
        self.assertEqual('2', version.history_current.id)
        self.assertIsInstance(version.history, LinkList)
        self.assertEqual(['2'], version.history.ids)
コード例 #13
0
 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())
コード例 #14
0
 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())
コード例 #15
0
 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())
コード例 #16
0
 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())
コード例 #17
0
 def setup_new(self):
     browser = Browser(id='_chrome', slug='chrome')
     version = Version(version='2.0', browser='_chrome')
     self.new_col.add(browser)
     self.new_col.add(version)
     resources = (browser, version)
     return resources, CollectionChangeset(self.orig_col, self.new_col)
コード例 #18
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)
コード例 #19
0
    def setup_matched(self):
        browser = Browser(id='1', slug='chrome')
        version = Version(
            id='1', version='2.0', browser='1', note={'en': 'Second Version'})
        self.orig_col.add(browser)
        self.orig_col.add(version)

        browser_same = Browser(id='_chrome', slug='chrome')
        version_diff = Version(
            id='_version', version='2.0', browser='_chrome',
            note=OrderedDict((
                ('en', 'Second Version'),
                ('es', 'Segunda Versión'))))
        self.new_col.add(version_diff)
        self.new_col.add(browser_same)
        resources = (version, browser_same, version_diff)
        return resources, CollectionChangeset(self.orig_col, self.new_col)
コード例 #20
0
 def setup_deleted(self, skip_deletes=False):
     browser = Browser(id='_chrome', slug='chrome')
     version = Version(id='_chrome_2', version='2.0', browser='_chrome')
     self.orig_col.add(browser)
     self.orig_col.add(version)
     resources = (browser, version)
     return resources, CollectionChangeset(self.orig_col, self.new_col,
                                           skip_deletes)
コード例 #21
0
 def test_get_resources_by_data_id(self):
     browser = Browser(id='1', slug='firefox')
     version = Version(version='1.0', browser='1')
     self.col.add(browser)
     self.col.add(version)
     versions = self.col.get_resources_by_data_id('versions')
     self.assertEqual({('versions', 'firefox', '1.0'): version}, versions)
     browsers = self.col.get_resources_by_data_id('browsers')
     self.assertEqual({('browsers', 'firefox'): browser}, browsers)
コード例 #22
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'))
コード例 #23
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'))
コード例 #24
0
    def test_load_by_json(self):
        rep = {
            'versions': {
                'id': '2',
                'version': '0.2',
                'release_day': None,
                'retirement_day': None,
                'status': 'unknown',
                'release_notes_uri': None,
                'note': None,
                'order': 1,
                'links': {
                    'browser':
                    '1',
                    'supports': [
                        '1120',
                        '1119',
                        '1118',
                        '1117',
                        '1116',
                        '1115',
                        '1114',
                        '1113',
                        '1112',
                        '1111',
                        '1110',
                        '1109',
                    ],
                    'history': ['2'],
                    'history_current':
                    '2'
                }
            },
        }
        version = Version()
        self.assertIsNone(version.id)
        self.assertIsNone(version.version)
        self.assertIsNone(version.release_day)
        self.assertIsNone(version.retirement_day)
        self.assertIsNone(version.status)
        self.assertIsNone(version.release_notes_uri)
        self.assertIsNone(version.note)
        self.assertIsNone(version.supports)
        self.assertIsNone(version.history)
        self.assertIsNone(version.history_current)

        version.from_json_api(rep)
        self.assertIsInstance(version.id, Link)
        self.assertEqual('2', version.id.id)
        self.assertEqual('0.2', version.version)
        self.assertIsNone(version.release_day)
        self.assertIsNone(version.retirement_day)
        self.assertEqual('unknown', version.status)
        self.assertIsNone(version.release_notes_uri)
        self.assertIsNone(version.note)
        self.assertIsInstance(version.supports, LinkList)
        self.assertEqual([
            '1120', '1119', '1118', '1117', '1116', '1115', '1114', '1113',
            '1112', '1111', '1110', '1109'
        ], version.supports.ids)
        self.assertIsInstance(version.history_current, Link)
        self.assertEqual('2', version.history_current.id)
        self.assertIsInstance(version.history, LinkList)
        self.assertEqual(['2'], version.history.ids)