Skip to content

Commit

Permalink
tests: Add test for use-github-token
Browse files Browse the repository at this point in the history
  • Loading branch information
Injabie3 authored and sondrelg committed Dec 7, 2023
1 parent d8fcd36 commit c432357
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion main_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from asyncio import Semaphore
from copy import deepcopy
from datetime import datetime, timedelta, timezone
from unittest.mock import AsyncMock, Mock
from unittest.mock import ANY, AsyncMock, Mock

import pytest as pytest
from httpx import AsyncClient
Expand Down Expand Up @@ -375,6 +375,13 @@ async def test_dry_run(self, mocker, capsys, http_client):
mock_delete_package.assert_not_called()


def test_inputs_use_github_token_with_bad_image_names():
_create_inputs_model(image_names='a', use_github_token=True)
with pytest.raises(ValidationError, match='A single image name is required if use_github_token is set'):
_create_inputs_model(image_names='a*', use_github_token=True)
_create_inputs_model(image_names='a,b,c', use_github_token=True)


def test_inputs_bad_account_type():
# Account type
_create_inputs_model(account_type='personal')
Expand Down Expand Up @@ -473,6 +480,34 @@ async def test_main(mocker, ok_response):
)


async def test_main_with_use_github_token(mocker, ok_response):
mock_list_package = mocker.patch.object(main.GithubAPI, 'list_packages')
mock_filter_image_names = mocker.patch.object(main, 'filter_image_names')
mock_get_and_delete_old_versions = mocker.patch.object(main, 'get_and_delete_old_versions')
mocker.patch.object(AsyncClient, 'get', return_value=ok_response)
mocker.patch.object(AsyncClient, 'delete', return_value=ok_response)
await main_(
**{
'account_type': 'org',
'org_name': 'test',
'image_names': 'my-package',
'timestamp_to_use': 'updated_at',
'cut_off': '2 hours ago UTC',
'untagged_only': 'false',
'skip_tags': '',
'keep_at_least': '0',
'filter_tags': '',
'filter_include_untagged': 'true',
'token': 'test',
'use_github_token': 'true',
}
)

mock_list_package.assert_not_called()
mock_filter_image_names.assert_not_called()
mock_get_and_delete_old_versions.assert_called_with('my-package', ANY, ANY)


async def test_public_images_with_more_than_5000_downloads(mocker, capsys):
"""
The `response.is_error` block is set up to output errors when we run into them.
Expand Down

0 comments on commit c432357

Please sign in to comment.