Skip to content

Commit

Permalink
Revert "test: add more unit tests for bridge package serving"
Browse files Browse the repository at this point in the history
This reverts commit 3fbd218096c0daf0bb2d35ff91a73b275480f308.
  • Loading branch information
allisonkarlitskaya committed Sep 6, 2023
1 parent 062c84b commit 8ba7054
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 86 deletions.
14 changes: 0 additions & 14 deletions test/pytest/mocktransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,3 @@ async def add_bus_match(self, path: str, iface: str, bus: Optional[str] = None)
if bus is None:
bus = await self.ensure_internal_bus()
self.send_json(bus, add_match={'path': path, 'interface': iface})

async def send_http(self, path: str, **kwargs: Any) -> str:
channel = await self.check_open('http-stream1', method='GET', path=path, **kwargs)
self.send_done(channel)
return channel

async def send_packages(self, path: str, language: str = '', **kwargs: Any) -> str:
headers = {
'X-Forwarded-Host': 'widget',
'X-Forwarded-Proto': 'https',
}
if language:
headers['Accept-Language'] = language
return await self.send_http(path, internal='packages', headers=headers, **kwargs)
72 changes: 0 additions & 72 deletions test/pytest/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import argparse
import json
from pathlib import Path
from typing import List

import pytest

from cockpit.bridge import Bridge
from cockpit.channel import Channel
from cockpit.packages import Packages, parse_accept_language

from .mocktransport import MockTransport


@pytest.mark.parametrize(("test_input", "expected"), [
('de-at, zh-CH, en,', ['de-at', 'zh-ch', 'en']),
Expand Down Expand Up @@ -164,69 +158,3 @@ def test_condition_hides_priority(pkgdir):
assert packages.packages['basic'].manifest['description'] == 'standard package'
assert packages.packages['basic'].manifest['requires'] == {'cockpit': "42"}
assert packages.packages['basic'].priority == 1


class TestMockResource:
@pytest.fixture
def resources(self, pytestconfig: pytest.Config) -> Path:
mock_resource = pytestconfig.rootpath / 'src' / 'bridge' / 'mock-resource'
return mock_resource

@pytest.fixture
def system(self, resources: Path) -> Path:
return resources / 'system' / 'cockpit'

@pytest.fixture
def home(self, resources: Path) -> Path:
return resources / 'home' / 'cockpit'

@pytest.fixture
def transport(self, monkeypatch: pytest.MonkeyPatch, resources: Path) -> MockTransport:
monkeypatch.setenv('XDG_DATA_DIRS', str(resources / 'system'))
monkeypatch.setenv('XDG_DATA_HOME', str(resources / 'home'))
transport = MockTransport(Bridge(argparse.Namespace(beipack=False, privileged=False)))
transport.init()
try:
yield transport
finally:
transport.stop()

@pytest.mark.asyncio
async def test_404(self, transport: MockTransport) -> None:
channel = await transport.send_packages('/no/file.html')
await transport.assert_msg(channel, status=404)

@pytest.mark.asyncio
async def test_serve(self, home: Path, transport: MockTransport) -> None:
channel = await transport.send_packages('/another/test.html')
await transport.assert_msg(channel, status=200)
await transport.assert_data(channel, (home / 'another-renamed/test.html').read_bytes())
await transport.assert_msg('', command='done', channel=channel)

@pytest.mark.asyncio
async def test_serve_large(self, system: Path, transport: MockTransport) -> None:
channel = await transport.send_packages('/test/sub/COPYING', flow_control=True)
await transport.assert_msg(channel, status=200)

# This file is larger than the flow control block size. Check it.
expected = (system / 'test/sub/COPYING').read_bytes()
await transport.assert_data(channel, expected[:Channel.BLOCK_SIZE])
await transport.assert_msg('', command='ping', sequence=Channel.BLOCK_SIZE)
await transport.assert_data(channel, expected[Channel.BLOCK_SIZE:])
await transport.assert_msg('', command='done', channel=channel)

@pytest.mark.asyncio
async def test_serve_manifests_json(self, transport: MockTransport) -> None:
channel = await transport.send_packages('/manifests.json')
await transport.assert_msg(channel, status=200)
payload = await transport.next_msg(channel)
assert set(payload) == {'another', 'incompatible', 'second', 'test'}
await transport.assert_msg('', command='done', channel=channel)

@pytest.mark.asyncio
async def test_serve_manifests_js(self, transport: MockTransport) -> None:
channel = await transport.send_packages('/manifests.js')
await transport.assert_msg(channel, status=200)
_, payload = await transport.next_frame()
assert b'function (root, data)' in payload
await transport.assert_msg('', command='done', channel=channel)

0 comments on commit 8ba7054

Please sign in to comment.