def test_release_force(clone_from_github_mock,
                       check_output_mock,
                       open_mock,
                       date_mock,
                       expanduser_mock):
    repo_mock = Mock()
    repo_mock.latest_tag.return_value = '20.1.0'
    repo_mock.authors_since.return_value = ['*****@*****.**', '*****@*****.**']
    repo_mock.diff_name_status.return_value = [
        ('apis/foo/v1.ts', _git.Status.ADDED),
        ('apis/baz/v1.ts', _git.Status.UPDATED),
    ]
    side_effect = common.clone_from_github_mock_side_effect(repo_mock)
    clone_from_github_mock.side_effect = side_effect
    check_output_mock.return_value = '20.1.0'
    open_package_json_mock = mock_open(read_data=('{"version": "20.1.0"}'))
    open_changelog_md_mock = mock_open(read_data='...\n')
    open_npmrc_mock = mock_open()
    open_index_md_mock = mock_open(
        read_data=('...\n\n'
                   '### ...\n\n'
                   '* [v20.1.0 (latest)](...)\n'
                   '...\n'))
    open_mock.side_effect = [
        open_package_json_mock.return_value,
        open_package_json_mock.return_value,
        open_changelog_md_mock.return_value,
        open_changelog_md_mock.return_value,
        open_npmrc_mock.return_value,
        open_index_md_mock.return_value,
        open_index_md_mock.return_value
    ]
    date_mock.today.return_value.strftime.return_value = '1 September 2017'
    expanduser_mock.side_effect = lambda x: '/home/test' + x[1:]

    google_api_nodejs_client.release(
        '/tmp', common.GITHUB_ACCOUNT, _NPM_ACCOUNT, force=True)
    # We don't bother verifying all calls in this case, since we only want to
    # verify that the different authors check was passed.
    assert repo_mock.mock_calls == [
        call.latest_tag(),
        call.authors_since('20.1.0'),
        call.diff_name_status(rev='20.1.0'),
        call.commit('20.2.0', 'Alice', '*****@*****.**'),
        call.tag('20.2.0'),
        call.push(),
        call.push(tags=True),
        call.checkout('gh-pages'),
        call.add(['latest', '20.2.0']),
        call.commit('20.2.0', 'Alice', '*****@*****.**'),
        call.push(branch='gh-pages'),
        call.checkout('master')
    ]
Ejemplo n.º 2
0
 def test_set_labels (self):
     catalogue = collections.OrderedDict(
         [(sentinel.text1, sentinel.label1),
          (sentinel.text2, sentinel.label2),
          (sentinel.text3, sentinel.label1)])
     store = tacl.DataStore(':memory:')
     store._conn = MagicMock(spec_set=sqlite3.Connection)
     cursor = store._conn.execute.return_value
     store._conn.execute.return_value = cursor
     cursor.fetchone.return_value = {'token_count': 10}
     actual_labels = store._set_labels(catalogue)
     expected_labels = {sentinel.label1: 20, sentinel.label2: 10}
     connection_calls = [
         call.execute(tacl.constants.UPDATE_LABELS_SQL, ['']),
         call.execute(tacl.constants.UPDATE_LABEL_SQL,
                      [sentinel.label1, sentinel.text1]),
         call.execute(tacl.constants.SELECT_TEXT_TOKEN_COUNT_SQL,
                      [sentinel.text1]),
         call.execute(tacl.constants.UPDATE_LABEL_SQL,
                      [sentinel.label2, sentinel.text2]),
         call.execute(tacl.constants.SELECT_TEXT_TOKEN_COUNT_SQL,
                      [sentinel.text2]),
         call.execute(tacl.constants.UPDATE_LABEL_SQL,
                      [sentinel.label1, sentinel.text3]),
         call.execute(tacl.constants.SELECT_TEXT_TOKEN_COUNT_SQL,
                      [sentinel.text3]),
         call.commit()]
     for connection_call in connection_calls:
         self.assertIn(connection_call, store._conn.mock_calls)
     self.assertEqual(actual_labels, expected_labels)
Ejemplo n.º 3
0
 def test_set_labels(self):
     catalogue = collections.OrderedDict([(sentinel.text1, sentinel.label1),
                                          (sentinel.text2, sentinel.label2),
                                          (sentinel.text3, sentinel.label1)
                                          ])
     store = tacl.DataStore(':memory:')
     store._conn = MagicMock(spec_set=sqlite3.Connection)
     cursor = store._conn.execute.return_value
     store._conn.execute.return_value = cursor
     cursor.fetchone.return_value = {'token_count': 10}
     actual_labels = store._set_labels(catalogue)
     expected_labels = {sentinel.label1: 20, sentinel.label2: 10}
     connection_calls = [
         call.execute(tacl.constants.UPDATE_LABELS_SQL, ['']),
         call.execute(tacl.constants.UPDATE_LABEL_SQL,
                      [sentinel.label1, sentinel.text1]),
         call.execute(tacl.constants.SELECT_TEXT_TOKEN_COUNT_SQL,
                      [sentinel.text1]),
         call.execute(tacl.constants.UPDATE_LABEL_SQL,
                      [sentinel.label2, sentinel.text2]),
         call.execute(tacl.constants.SELECT_TEXT_TOKEN_COUNT_SQL,
                      [sentinel.text2]),
         call.execute(tacl.constants.UPDATE_LABEL_SQL,
                      [sentinel.label1, sentinel.text3]),
         call.execute(tacl.constants.SELECT_TEXT_TOKEN_COUNT_SQL,
                      [sentinel.text3]),
         call.commit()
     ]
     for connection_call in connection_calls:
         self.assertIn(connection_call, store._conn.mock_calls)
     self.assertEqual(actual_labels, expected_labels)
Ejemplo n.º 4
0
 def test_delete_text_ngrams (self):
     store = tacl.DataStore(':memory:')
     store._conn = MagicMock(spec_set=sqlite3.Connection)
     store._delete_text_ngrams(sentinel.text_id)
     expected_calls = [
         call.execute(tacl.constants.DELETE_TEXT_NGRAMS_SQL,
                      [sentinel.text_id]),
         call.execute(tacl.constants.DELETE_TEXT_HAS_NGRAMS_SQL,
                      [sentinel.text_id]),
         call.commit()]
     self.assertEqual(store._conn.mock_calls, expected_calls)
Ejemplo n.º 5
0
 def test_delete_text_ngrams(self):
     store = tacl.DataStore(':memory:')
     store._conn = MagicMock(spec_set=sqlite3.Connection)
     store._delete_text_ngrams(sentinel.text_id)
     expected_calls = [
         call.execute(tacl.constants.DELETE_TEXT_NGRAMS_SQL,
                      [sentinel.text_id]),
         call.execute(tacl.constants.DELETE_TEXT_HAS_NGRAMS_SQL,
                      [sentinel.text_id]),
         call.commit()
     ]
     self.assertEqual(store._conn.mock_calls, expected_calls)
Ejemplo n.º 6
0
 def test_add_text_size_ngrams (self):
     store = tacl.DataStore(':memory:')
     store._conn = MagicMock(spec_set=sqlite3.Connection)
     size = 1
     ngrams = collections.OrderedDict([('a', 2), ('b', 1)])
     store._add_text_size_ngrams(sentinel.text_id, size, ngrams)
     self.assertEqual(
         store._conn.mock_calls,
         [call.execute(tacl.constants.INSERT_TEXT_HAS_NGRAM_SQL,
                       [sentinel.text_id, size, len(ngrams)]),
          call.executemany(tacl.constants.INSERT_NGRAM_SQL,
                           [[sentinel.text_id, 'a', size, 2],
                            [sentinel.text_id, 'b', size, 1]]),
          call.commit()])
Ejemplo n.º 7
0
 def test_add_text_size_ngrams(self):
     store = tacl.DataStore(':memory:')
     store._conn = MagicMock(spec_set=sqlite3.Connection)
     size = 1
     ngrams = collections.OrderedDict([('a', 2), ('b', 1)])
     store._add_text_size_ngrams(sentinel.text_id, size, ngrams)
     self.assertEqual(store._conn.mock_calls, [
         call.execute(
             tacl.constants.INSERT_TEXT_HAS_NGRAM_SQL,
             [sentinel.text_id, size, len(ngrams)]),
         call.executemany(tacl.constants.INSERT_NGRAM_SQL,
                          [[sentinel.text_id, 'a', size, 2],
                           [sentinel.text_id, 'b', size, 1]]),
         call.commit()
     ])
    def test_save_must_save_the_model(self):
        #Arrange
        db_mock = Mock()
        repository = Repository()
        repository.set_db(db_mock)

        #Action
        repository.save('model')

        #Asserts
        db_mock_calls = db_mock.mock_calls
        self.assertEqual(4, len(db_mock_calls))
        db_mock.assert_has_calls([
            call.add('model'),
            call.commit(),
            call.refresh('model'),
            call.close(),
        ])
def test_release_force(clone_from_github_mock, check_output_mock, open_mock,
                       expanduser_mock, chmod_mock):
    repo_mock = Mock()
    repo_mock.latest_tag.return_value = '0.13.6'
    repo_mock.authors_since.return_value = ['*****@*****.**', '*****@*****.**']
    repo_mock.diff_name_status.return_value = [
        ('generated/google/apis/foo_v1.rb', _git.Status.ADDED),
        ('generated/google/apis/baz_v1.rb', _git.Status.UPDATED),
    ]
    side_effect = common.clone_from_github_mock_side_effect(repo_mock)
    clone_from_github_mock.side_effect = side_effect
    check_output_mock.return_value = 'google-api-client (0.13.6)'
    open_version_rb_mock = mock_open(
        read_data=('...\n'
                   'module Google\n'
                   '    module Apis\n'
                   '        # Client library version\n'
                   '        VERSION = \'0.13.6\'\n'
                   '    ...\n'))
    open_changelog_md_mock = mock_open(read_data='...\n')
    open_credentials_mock = mock_open()
    open_mock.side_effect = [
        open_version_rb_mock.return_value, open_version_rb_mock.return_value,
        open_changelog_md_mock.return_value,
        open_changelog_md_mock.return_value, open_credentials_mock.return_value
    ]
    expanduser_mock.side_effect = lambda x: '/home/test' + x[1:]

    google_api_ruby_client.release('/tmp',
                                   common.GITHUB_ACCOUNT,
                                   _RUBYGEMS_ACCOUNT,
                                   force=True)
    # We don't bother verifying all calls in this case, since we only want to
    # verify that the different authors check was passed.
    assert repo_mock.mock_calls == [
        call.latest_tag(),
        call.authors_since('0.13.6'),
        call.diff_name_status(rev='0.13.6'),
        call.commit('0.13.7', 'Alice', '*****@*****.**'),
        call.tag('0.13.7'),
        call.push(),
        call.push(tags=True),
    ]
Ejemplo n.º 10
0
    def test_normal(self):
        logger: Logger = Mock()
        connection: Connection = Mock()
        qe = NormalQueryExecutor(logger, connection)
        qe.execute_all(["sql1", "sql2"], stream="s")
        qe.commit()

        self.assertEqual([
            call.debug('Execute: %s (args=%s, stream=%s)', 'sql1',
                       (), {'stream': 's'}),
            call.debug('Execute: %s (args=%s, stream=%s)', 'sql2',
                       (), {'stream': 's'}),
            call.debug('Commit')
        ], logger.mock_calls)
        self.assertEqual([
            call.cursor(),
            call.cursor().execute('sql1', stream='s'),
            call.cursor().execute('sql2', stream='s'),
            call.commit()
        ], connection.mock_calls)
Ejemplo n.º 11
0
 def test_commit(self):
     self.executor.commit()
     self.assertEqual([call.debug('commit')], self.logger.mock_calls)
     self.assertEqual([call.cursor(), call.commit()],
                      self.connection.mock_calls)
Ejemplo n.º 12
0
def test_commandnode_teardown__commit(tmp_path):
    cmd_mock = _build_cmd_mock()
    node = CommandNode(cmd_mock)
    node._teardown(None, tmp_path)
    assert cmd_mock.mock_calls == [call.commit(tmp_path)]