示例#1
0
    def setUp(self):
        self.graph = Graph()
        self.config = Config(working_dir)
        self.loader = Loader(self.config, self.graph)
        self.changelog = self.loader.changelog
        self.changelog_abspath = self.loader.path.get_changelog_abspath()

        
        data = dict(username="******", name="James Thornton")
        james = self.graph.people.get_or_create("username", "james", data)
        cache.put('username:james', james.eid)        

        self.last_updated = int(time.time())
示例#2
0
class LoaderTestCase(unittest.TestCase):

    def setUp(self):
        self.graph = Graph()
        self.config = Config(working_dir)
        self.loader = Loader(self.config, self.graph)
        self.changelog = self.loader.changelog
        self.changelog_abspath = self.loader.path.get_changelog_abspath()

        
        data = dict(username="******", name="James Thornton")
        james = self.graph.people.get_or_create("username", "james", data)
        cache.put('username:james', james.eid)        

        self.last_updated = int(time.time())

    def test_init(self):
        eid = cache.get('username:james')
        assert type(eid) == int

    def test_update_all_entries(self):
        self.loader.update_all_entries()

        entry1 = self.graph.entries.index.lookup(slug="lightbulb").next()
        assert entry1.title == title
        assert entry1.subtitle == subtitle

        # TODO: Index lookups like this "anotherdir/another-file" break on Neo4j 
        entry2 = self.graph.entries.index.lookup(slug="another-file").next()
        assert entry2.title == "Another Title"
        assert entry2.subtitle == "Another subtitle here."

    def test_update_changed_entries(self):
        remove_git_repo(self.changelog, self.changelog_abspath)

        # Set last updated time before changelog update to simulate a new changelog
        now = int(time.time())
        self.loader.set_last_updated(now)
        time.sleep(2)

        add_git_repo(self.changelog, self.changelog_abspath)
        
        self.changelog.update()

        self.changelog._execute("git commit -m test commit")

        # Changes need to be made
        update_count = self.loader.update_changed_entries()
        assert update_count == 2

        # Remove test repo and changelog
        self.changelog._execute("rm -rf %s" % git_dir)
        self.changelog._execute("rm %s" % self.changelog_abspath)


    def test_no_update(self):
        remove_git_repo(self.changelog, self.changelog_abspath)
        add_git_repo(self.changelog, self.changelog_abspath)
        
        self.changelog.update()

        self.changelog._execute("git commit -m test commit")

        # Set last updated time after changelog update to simulate an old changelog
        time.sleep(2)
        now = int(time.time())
        self.loader.set_last_updated(now)

        # Changes need to be made
        update_count = self.loader.update_changed_entries()
        assert update_count == 0


    def test_set_and_get_last_updated(self):
        self.loader.set_last_updated(self.last_updated)
        last_updated = self.loader.get_last_updated()

        assert last_updated == self.last_updated