def test_graph_key_error(mocker, tmpdir): """Test unhappy path for graph command.""" mocked_requests = mocker.patch('requests.get') mocked_requests.return_value = mock.Mock() mocked_requests.return_value.json = mock.Mock(return_value=[{}]) mocked_alembic = mocker.patch( 'pdt_client.commands.generate_migration_graph') mocked_alembic.return_value = "Hello" fp = tmpdir.join('test.dot') graph(url='http://example.com', username='******', password='******', filename=str(fp), alembic_config='some_config', verbose=False) mocked_requests.assert_called_with( 'http://example.com/api/migrations/', headers={'content-type': 'application/json'}, auth=('user', 'password')) assert fp.read() == "Hello"
def test_graph_key_error(mocker, tmpdir): """Test unhappy path for graph command.""" mocked_requests = mocker.patch('requests.get') mocked_requests.return_value = mock.Mock() mocked_requests.return_value.json = mock.Mock(return_value=[{}]) mocked_alembic = mocker.patch('pdt_client.commands.generate_migration_graph') mocked_alembic.return_value = "Hello" fp = tmpdir.join('test.dot') graph( url='http://example.com', username='******', password='******', filename=str(fp), alembic_config='some_config', verbose=False ) mocked_requests.assert_called_with( 'http://example.com/api/migrations/', headers={'content-type': 'application/json'}, auth=('user', 'password')) assert fp.read() == "Hello"
def test_graph(mocker, tmpdir, capsys): """Test graph command.""" mocked_requests = mocker.patch('requests.get') mocked_alembic = mocker.patch('pdt_client.commands.generate_migration_graph') mocked_alembic.return_value = "Hello" fp = tmpdir.join('test.dot') graph( url='http://example.com', username='******', password='******', filename=str(fp), alembic_config='some_config', verbose=True ) mocked_requests.assert_called_with( 'http://example.com/api/migrations/', headers={'content-type': 'application/json'}, auth=('user', 'password')) assert fp.read() == "Hello" out, err = capsys.readouterr() assert out == "Done\nTo generate an image use: dot -Tpng -O {0}\n".format(fp) assert err == ""
def test_graph(mocker, tmpdir, capsys): """Test graph command.""" mocked_requests = mocker.patch('requests.get') mocked_alembic = mocker.patch( 'pdt_client.commands.generate_migration_graph') mocked_alembic.return_value = "Hello" fp = tmpdir.join('test.dot') graph(url='http://example.com', username='******', password='******', filename=str(fp), alembic_config='some_config', verbose=True) mocked_requests.assert_called_with( 'http://example.com/api/migrations/', headers={'content-type': 'application/json'}, auth=('user', 'password')) assert fp.read() == "Hello" out, err = capsys.readouterr() assert out == "Done\nTo generate an image use: dot -Tpng -O {0}\n".format( fp) assert err == ""