# Path: pushmanager/core/db.py
# def UnsignedInteger():
# def init_db():
# def finalize_db():
# def execute_cb(query, callback_fn):
# def execute_transaction_cb(queries, callback_fn, condition=None):
# def prefix_insert_ignore(insert_ignore, compiler, **kw):
# def prefix_insert_ignore_sqlite(insert_ignore, compiler, **kw):
# class DatabaseError(Exception):
# class PushCheckList(Base):
# class PushPlans(Base):
# class PushPushContents(Base):
# class PushPushes(Base):
# class PushRemovals(Base):
# class PushRequests(Base):
# class InsertIgnore(Insert):
# 
# Path: pushmanager/testing/mocksettings.py

# 
# Path: tools/rename_tag.py
# def main():
# def convert_tag(old, new):
# def convert_tag_callback(oldtag, newtag, success, db_results):
# def check_db_results(success, db_results):


import os
import testify as T
from functools import partial
from mock import patch
from pushmanager.core import db
from pushmanager.testing import testdb
from pushmanager.testing.mocksettings import MockedSettings
from pushmanager.testing.testdb import FakeDataMixin
from tools import rename_tag

        # id, user, state, repo, branch, revision, *tags*, created, etc...
        tags = [result[6] for result in db_results.fetchall()]

        T.assert_not_in(oldtag, tags)
        T.assert_in(newtag, tags)

    @patch('tools.rename_tag.convert_tag')
    @patch('optparse.OptionParser.error')
    @patch('optparse.OptionParser.parse_args', return_value=[None, []])
    def test_main_noargs(self, parser, error, convert_tag):
        rename_tag.main()
        T.assert_equal(False, convert_tag.called)
        error.assert_called_once_with('Incorrect number of arguments')

    @patch('tools.rename_tag.convert_tag')
    @patch('optparse.OptionParser.error')
    @patch('optparse.OptionParser.parse_args', return_value=[None, ['oldtag', 'newtag']])
    def test_main_twoargs(self, parser, error, convert_tag):
        parser.return_value = [None, ['oldtag', 'newtag']]
        rename_tag.main()
        convert_tag.assert_called_once_with('oldtag', 'newtag')
        T.assert_equal(False, error.called)

    def test_convert_tag(self):
        rename_tag.convert_tag('search', 'not_search')
        cb = partial(self.verify_tag_rename, 'search', 'not_search')
        db.execute_cb(db.push_requests.select(), cb)

    def test_convert_notag(self):

# Path: pushmanager/core/db.py
# def UnsignedInteger():
# def init_db():
# def finalize_db():
# def execute_cb(query, callback_fn):
# def execute_transaction_cb(queries, callback_fn, condition=None):
# def prefix_insert_ignore(insert_ignore, compiler, **kw):
# def prefix_insert_ignore_sqlite(insert_ignore, compiler, **kw):
# class DatabaseError(Exception):
# class PushCheckList(Base):
# class PushPlans(Base):
# class PushPushContents(Base):
# class PushPushes(Base):
# class PushRemovals(Base):
# class PushRequests(Base):
# class InsertIgnore(Insert):
# 
# Path: pushmanager/testing/mocksettings.py

# 
# Path: tools/rename_tag.py
# def main():
# def convert_tag(old, new):
# def convert_tag_callback(oldtag, newtag, success, db_results):
# def check_db_results(success, db_results):


# Path: pushmanager/tests/test_rename_tag.py
import os
import testify as T
from functools import partial
from mock import patch
from pushmanager.core import db
from pushmanager.testing import testdb
from pushmanager.testing.mocksettings import MockedSettings
from pushmanager.testing.testdb import FakeDataMixin
from tools import rename_tag


        # id, user, state, repo, branch, revision, *tags*, created, etc...
        tags = [result[6] for result in db_results.fetchall()]

        T.assert_not_in(oldtag, tags)
        T.assert_in(newtag, tags)

    @patch('tools.rename_tag.convert_tag')
    @patch('optparse.OptionParser.error')
    @patch('optparse.OptionParser.parse_args', return_value=[None, []])
    def test_main_noargs(self, parser, error, convert_tag):
        rename_tag.main()
        T.assert_equal(False, convert_tag.called)
        error.assert_called_once_with('Incorrect number of arguments')

    @patch('tools.rename_tag.convert_tag')
    @patch('optparse.OptionParser.error')
    @patch('optparse.OptionParser.parse_args', return_value=[None, ['oldtag', 'newtag']])
    def test_main_twoargs(self, parser, error, convert_tag):
        parser.return_value = [None, ['oldtag', 'newtag']]
        rename_tag.main()
        convert_tag.assert_called_once_with('oldtag', 'newtag')
        T.assert_equal(False, error.called)

    def test_convert_tag(self):
        rename_tag.convert_tag('search', 'not_search')
        cb = partial(self.verify_tag_rename, 'search', 'not_search')
        db.execute_cb(db.push_requests.select(), cb)

    def test_convert_notag(self):

        rename_tag.convert_tag('nonexistent', 'random')