コード例 #1
0
ファイル: cache.py プロジェクト: gdgkyoto/kyoto-gtug
    def test_get_changes(self):
        t1 = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
        t2 = datetime(2002, 1, 1, 1, 1, 1, 0, utc)
        cursor = self.db.cursor()
        cursor.execute("INSERT INTO revision (rev,time,author,message) "
                       "VALUES (0,%s,'','')", (to_timestamp(t1),))
        cursor.execute("INSERT INTO revision (rev,time,author,message) "
                       "VALUES (1,%s,'joe','Import')", (to_timestamp(t2),))
        cursor.executemany("INSERT INTO node_change (rev,path,node_type,"
                           "change_type,base_path,base_rev) "
                           "VALUES ('1',%s,%s,%s,%s,%s)",
                           [('trunk', 'D', 'A', None, None),
                            ('trunk/README', 'F', 'A', None, None)])
        cursor.execute("UPDATE system SET value='1' WHERE name='youngest_rev'")

        repos = Mock(Repository, 'test-repos', None, self.log,
                     get_changeset=lambda x: None,
                     get_youngest_rev=lambda: 1,
                     get_oldest_rev=lambda: 0,
                     next_rev=lambda x: None,
                     normalize_rev=lambda rev: rev)
        cache = CachedRepository(self.db, repos, None, self.log)
        self.assertEqual('1', cache.youngest_rev)
        changeset = cache.get_changeset(1)
        self.assertEqual('joe', changeset.author)
        self.assertEqual('Import', changeset.message)
        self.assertEqual(t2, changeset.date)
        changes = changeset.get_changes()
        self.assertEqual(('trunk', Node.DIRECTORY, Changeset.ADD, None, None),
                         changes.next())
        self.assertEqual(('trunk/README', Node.FILE, Changeset.ADD, None, None),
                         changes.next())
        self.assertRaises(StopIteration, changes.next)
コード例 #2
0
    def test_get_changes(self):
        cursor = self.db.cursor()
        cursor.execute("INSERT INTO revision (rev,time,author,message) "
                       "VALUES (0,41000,'','')")
        cursor.execute("INSERT INTO revision (rev,time,author,message) "
                       "VALUES (1,42000,'joe','Import')")
        cursor.executemany("INSERT INTO node_change (rev,path,node_type,"
                           "change_type,base_path,base_rev) "
                           "VALUES ('1',%s,%s,%s,%s,%s)",
                           [('trunk', 'D', 'A', None, None),
                            ('trunk/README', 'F', 'A', None, None)])

        repos = Mock(Repository, 'test-repos', None, self.log,
                     get_changeset=lambda x: None,
                     get_youngest_rev=lambda: 1,
                     next_rev=lambda x: None, normalize_rev=lambda rev: rev)
        cache = CachedRepository(self.db, repos, None, self.log)
        self.assertEqual('1', cache.youngest_rev)
        changeset = cache.get_changeset(1)
        self.assertEqual('joe', changeset.author)
        self.assertEqual('Import', changeset.message)
        self.assertEqual(42000, changeset.date)
        changes = changeset.get_changes()
        self.assertEqual(('trunk', Node.DIRECTORY, Changeset.ADD, None, None),
                         changes.next())
        self.assertEqual(('trunk/README', Node.FILE, Changeset.ADD, None, None),
                         changes.next())
        self.assertRaises(StopIteration, changes.next)
コード例 #3
0
    def test_sync_changeset_if_not_exists(self):
        t = [
            datetime(2001, 1, 1, 1, 1, 1, 0, utc),  # r0
            datetime(2002, 1, 1, 1, 1, 1, 0, utc),  # r1
            datetime(2003, 1, 1, 1, 1, 1, 0, utc),  # r2
            datetime(2004, 1, 1, 1, 1, 1, 0, utc),  # r3
        ]
        self.preset_cache(
            (("0", to_utimestamp(t[0]), "joe", "**empty**"), []),
            (
                ("1", to_utimestamp(t[1]), "joe", "Import"),
                [("trunk", "D", "A", None, None), ("trunk/README", "F", "A", None, None)],
            ),
            # not exists r2
            (("3", to_utimestamp(t[3]), "joe", "Add COPYING"), [("trunk/COPYING", "F", "A", None, None)]),
        )
        repos = self.get_repos(get_changeset=lambda x: changesets[int(x)], youngest_rev=3)
        changes = [
            None,  # r0
            [
                ("trunk", Node.DIRECTORY, Changeset.ADD, None, None),  # r1
                ("trunk/README", Node.FILE, Changeset.ADD, None, None),
            ],
            [
                ("branches", Node.DIRECTORY, Changeset.ADD, None, None),  # r2
                ("tags", Node.DIRECTORY, Changeset.ADD, None, None),
            ],
            [("trunk/COPYING", Node.FILE, Changeset.ADD, None, None)],  # r3
        ]
        changesets = [
            Mock(Changeset, repos, 0, "**empty**", "joe", t[0], get_changes=lambda: []),
            Mock(Changeset, repos, 1, "Initial Import", "joe", t[1], get_changes=lambda: iter(changes[1])),
            Mock(Changeset, repos, 2, "Created directories", "john", t[2], get_changes=lambda: iter(changes[2])),
            Mock(Changeset, repos, 3, "Add COPYING", "joe", t[3], get_changes=lambda: iter(changes[3])),
        ]
        cache = CachedRepository(self.env, repos, self.log)
        self.assertRaises(NoSuchChangeset, cache.get_changeset, 2)
        cache.sync()
        self.assertRaises(NoSuchChangeset, cache.get_changeset, 2)

        self.assertEqual(None, cache.sync_changeset(2))
        cset = cache.get_changeset(2)
        self.assertEqual("john", cset.author)
        self.assertEqual("Created directories", cset.message)
        self.assertEqual(t[2], cset.date)
        cset_changes = cset.get_changes()
        self.assertEqual(("branches", Node.DIRECTORY, Changeset.ADD, None, None), cset_changes.next())
        self.assertEqual(("tags", Node.DIRECTORY, Changeset.ADD, None, None), cset_changes.next())
        self.assertRaises(StopIteration, cset_changes.next)

        rows = self.env.db_query("SELECT time,author,message FROM revision ORDER BY rev")
        self.assertEquals(4, len(rows))
        self.assertEquals((to_utimestamp(t[0]), "joe", "**empty**"), rows[0])
        self.assertEquals((to_utimestamp(t[1]), "joe", "Import"), rows[1])
        self.assertEquals((to_utimestamp(t[2]), "john", "Created directories"), rows[2])
        self.assertEquals((to_utimestamp(t[3]), "joe", "Add COPYING"), rows[3])
コード例 #4
0
 def test_get_changes(self):
     t1 = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
     t2 = datetime(2002, 1, 1, 1, 1, 1, 0, utc)
     self.preset_cache(
         (("0", to_utimestamp(t1), "", ""), []),
         (
             ("1", to_utimestamp(t2), "joe", "Import"),
             [("trunk", "D", "A", None, None), ("trunk/RDME", "F", "A", None, None)],
         ),
     )
     repos = self.get_repos()
     cache = CachedRepository(self.env, repos, self.log)
     self.assertEqual("1", cache.youngest_rev)
     changeset = cache.get_changeset(1)
     self.assertEqual("joe", changeset.author)
     self.assertEqual("Import", changeset.message)
     self.assertEqual(t2, changeset.date)
     changes = changeset.get_changes()
     self.assertEqual(("trunk", Node.DIRECTORY, Changeset.ADD, None, None), changes.next())
     self.assertEqual(("trunk/RDME", Node.FILE, Changeset.ADD, None, None), changes.next())
     self.assertRaises(StopIteration, changes.next)
コード例 #5
0
ファイル: cache.py プロジェクト: wiraqutra/photrackjp
 def test_get_changes(self):
     t1 = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
     t2 = datetime(2002, 1, 1, 1, 1, 1, 0, utc)
     self.preset_cache(
         (('0', to_utimestamp(t1), '', ''), []),
         (('1', to_utimestamp(t2), 'joe', 'Import'),
          [('trunk', 'D', 'A', None, None),
           ('trunk/RDME', 'F', 'A', None, None)]),
         )
     repos = self.get_repos()
     cache = CachedRepository(self.env, repos, self.log)
     self.assertEqual('1', cache.youngest_rev)
     changeset = cache.get_changeset(1)
     self.assertEqual('joe', changeset.author)
     self.assertEqual('Import', changeset.message)
     self.assertEqual(t2, changeset.date)
     changes = changeset.get_changes()
     self.assertEqual(('trunk', Node.DIRECTORY, Changeset.ADD, None, None),
                      changes.next())
     self.assertEqual(('trunk/RDME', Node.FILE, Changeset.ADD, None, None),
                      changes.next())
     self.assertRaises(StopIteration, changes.next)
コード例 #6
0
ファイル: cache.py プロジェクト: dammina/bloodhound
 def test_get_changes(self):
     t1 = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
     t2 = datetime(2002, 1, 1, 1, 1, 1, 0, utc)
     self.preset_cache(
         (('0', to_utimestamp(t1), '', ''), []),
         (('1', to_utimestamp(t2), 'joe', 'Import'),
          [('trunk', 'D', 'A', None, None),
           ('trunk/RDME', 'F', 'A', None, None)]),
         )
     repos = self.get_repos()
     cache = CachedRepository(self.env, repos, self.log)
     self.assertEqual('1', cache.youngest_rev)
     changeset = cache.get_changeset(1)
     self.assertEqual('joe', changeset.author)
     self.assertEqual('Import', changeset.message)
     self.assertEqual(t2, changeset.date)
     changes = changeset.get_changes()
     self.assertEqual(('trunk', Node.DIRECTORY, Changeset.ADD, None, None),
                      changes.next())
     self.assertEqual(('trunk/RDME', Node.FILE, Changeset.ADD, None, None),
                      changes.next())
     self.assertRaises(StopIteration, changes.next)
コード例 #7
0
ファイル: cache.py プロジェクト: ohanar/trac
    def test_sync_changeset_if_not_exists(self):
        t = [
            datetime(2001, 1, 1, 1, 1, 1, 0, utc),  # r0
            datetime(2002, 1, 1, 1, 1, 1, 0, utc),  # r1
            datetime(2003, 1, 1, 1, 1, 1, 0, utc),  # r2
            datetime(2004, 1, 1, 1, 1, 1, 0, utc),  # r3
        ]
        self.preset_cache(
            (('0', to_utimestamp(t[0]), 'joe', '**empty**'), []),
            (('1', to_utimestamp(t[1]), 'joe', 'Import'), [
                ('trunk', 'D', 'A', None, None),
                ('trunk/README', 'F', 'A', None, None)
            ]),
            # not exists r2
            (('3', to_utimestamp(t[3]), 'joe', 'Add COPYING'), [
                ('trunk/COPYING', 'F', 'A', None, None)
            ]),
        )
        repos = self.get_repos(get_changeset=lambda x: changesets[int(x)],
                               youngest_rev=3)
        changes = [
            None,  # r0
            [
                ('trunk', Node.DIRECTORY, Changeset.ADD, None, None),  # r1
                ('trunk/README', Node.FILE, Changeset.ADD, None, None)
            ],
            [
                ('branches', Node.DIRECTORY, Changeset.ADD, None, None),  # r2
                ('tags', Node.DIRECTORY, Changeset.ADD, None, None)
            ],
            [('trunk/COPYING', Node.FILE, Changeset.ADD, None, None)],  # r3
        ]
        changesets = [
            Mock(Changeset,
                 repos,
                 0,
                 '**empty**',
                 'joe',
                 t[0],
                 get_changes=lambda: []),
            Mock(Changeset,
                 repos,
                 1,
                 'Initial Import',
                 'joe',
                 t[1],
                 get_changes=lambda: iter(changes[1])),
            Mock(Changeset,
                 repos,
                 2,
                 'Created directories',
                 'john',
                 t[2],
                 get_changes=lambda: iter(changes[2])),
            Mock(Changeset,
                 repos,
                 3,
                 'Add COPYING',
                 'joe',
                 t[3],
                 get_changes=lambda: iter(changes[3])),
        ]
        cache = CachedRepository(self.env, repos, self.log)
        self.assertRaises(NoSuchChangeset, cache.get_changeset, 2)
        cache.sync()
        self.assertRaises(NoSuchChangeset, cache.get_changeset, 2)

        self.assertEqual(None, cache.sync_changeset(2))
        cset = cache.get_changeset(2)
        self.assertEqual('john', cset.author)
        self.assertEqual('Created directories', cset.message)
        self.assertEqual(t[2], cset.date)
        cset_changes = cset.get_changes()
        self.assertEqual(
            ('branches', Node.DIRECTORY, Changeset.ADD, None, None),
            cset_changes.next())
        self.assertEqual(('tags', Node.DIRECTORY, Changeset.ADD, None, None),
                         cset_changes.next())
        self.assertRaises(StopIteration, cset_changes.next)

        rows = self.env.db_query(
            "SELECT time,author,message FROM revision ORDER BY rev")
        self.assertEquals(4, len(rows))
        self.assertEquals((to_utimestamp(t[0]), 'joe', '**empty**'), rows[0])
        self.assertEquals((to_utimestamp(t[1]), 'joe', 'Import'), rows[1])
        self.assertEquals((to_utimestamp(t[2]), 'john', 'Created directories'),
                          rows[2])
        self.assertEquals((to_utimestamp(t[3]), 'joe', 'Add COPYING'), rows[3])
コード例 #8
0
ファイル: cache.py プロジェクト: thimalk/bloodhound
    def test_sync_changeset_if_not_exists(self):
        t = [
            datetime(2001, 1, 1, 1, 1, 1, 0, utc), # r0
            datetime(2002, 1, 1, 1, 1, 1, 0, utc), # r1
            datetime(2003, 1, 1, 1, 1, 1, 0, utc), # r2
            datetime(2004, 1, 1, 1, 1, 1, 0, utc), # r3
        ]
        self.preset_cache(
            (('0', to_utimestamp(t[0]), 'joe', '**empty**'), []),
            (('1', to_utimestamp(t[1]), 'joe', 'Import'),
             [('trunk', 'D', 'A', None, None),
              ('trunk/README', 'F', 'A', None, None)]),
            # not exists r2
            (('3', to_utimestamp(t[3]), 'joe', 'Add COPYING'),
             [('trunk/COPYING', 'F', 'A', None, None)]),
            )
        repos = self.get_repos(get_changeset=lambda x: changesets[int(x)],
                               youngest_rev=3)
        changes = [
            None,                                                       # r0
            [('trunk', Node.DIRECTORY, Changeset.ADD, None, None),      # r1
             ('trunk/README', Node.FILE, Changeset.ADD, None, None)],
            [('branches', Node.DIRECTORY, Changeset.ADD, None, None),   # r2
             ('tags', Node.DIRECTORY, Changeset.ADD, None, None)],
            [('trunk/COPYING', Node.FILE, Changeset.ADD, None, None)],  # r3
        ]
        changesets = [
            Mock(Changeset, repos, 0, '**empty**', 'joe', t[0],
                 get_changes=lambda: []),
            Mock(Changeset, repos, 1, 'Initial Import', 'joe', t[1],
                 get_changes=lambda: iter(changes[1])),
            Mock(Changeset, repos, 2, 'Created directories', 'john', t[2],
                 get_changes=lambda: iter(changes[2])),
            Mock(Changeset, repos, 3, 'Add COPYING', 'joe', t[3],
                 get_changes=lambda: iter(changes[3])),
            ]
        cache = CachedRepository(self.env, repos, self.log)
        self.assertRaises(NoSuchChangeset, cache.get_changeset, 2)
        cache.sync()
        self.assertRaises(NoSuchChangeset, cache.get_changeset, 2)

        self.assertEqual(None, cache.sync_changeset(2))
        cset = cache.get_changeset(2)
        self.assertEqual('john', cset.author)
        self.assertEqual('Created directories', cset.message)
        self.assertEqual(t[2], cset.date)
        cset_changes = cset.get_changes()
        self.assertEqual(('branches', Node.DIRECTORY, Changeset.ADD, None,
                          None),
                         cset_changes.next())
        self.assertEqual(('tags', Node.DIRECTORY, Changeset.ADD, None, None),
                         cset_changes.next())
        self.assertRaises(StopIteration, cset_changes.next)

        rows = self.env.db_query(
                "SELECT time,author,message FROM revision ORDER BY rev")
        self.assertEquals(4, len(rows))
        self.assertEquals((to_utimestamp(t[0]), 'joe', '**empty**'), rows[0])
        self.assertEquals((to_utimestamp(t[1]), 'joe', 'Import'), rows[1])
        self.assertEquals((to_utimestamp(t[2]), 'john', 'Created directories'),
                          rows[2])
        self.assertEquals((to_utimestamp(t[3]), 'joe', 'Add COPYING'), rows[3])