Files
WoW-Hybrid-gateway/tests/owned_paladin_fixture_test.py
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

82 lines
4.7 KiB
Python

import copy
import ast
import json
import os
from pathlib import Path
import sys
import tempfile
import unittest
from unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'ops'))
import owned_paladin_fixture as fixture
def receipt():
return dict(schema=fixture.SCHEMA, guid=4600, account=513, race=1,
**{'class': 2}, name='Gatewaypal', creation_run='PaladinCreate1',
created_via_original_ui=True, source_guid_high_water_before=4599)
class PaladinFixtureTest(unittest.TestCase):
def test_exact_new_identity_and_source_row(self):
value = receipt()
self.assertEqual(fixture.first_profile(value), (4600, 513, 4, fixture.ACCOUNT_FIXTURE))
fixture.validate_source_row(value, ['4600', '513', '1', '2', '4761746577617970616C'])
for changed in ((0, '4514'), (1, '511'), (2, '2'), (3, '1'), (4, '4141')):
row = ['4600', '513', '1', '2', '4761746577617970616C'];row[changed[0]] = changed[1]
with self.assertRaises(ValueError):fixture.validate_source_row(value, row)
def test_existing_owner_other_account_or_unproved_creation_rejected(self):
for delta in ({'guid': 4514}, {'guid': 4526}, {'guid': 4599}, {'account': 511},
{'account': 514}, {'race': 2}, {'class': 1}, {'guid': True},
{'created_via_original_ui': False}, {'source_guid_high_water_before': 1},
{'name': 'bad name'}, {'creation_run': '../other'}, {'password': 'excluded'}):
with self.subTest(delta=delta), self.assertRaises(ValueError):
fixture.validate_receipt(dict(receipt(), **delta))
def test_context_admits_only_exact_guid_path_and_single_login(self):
value = receipt()
first = dict(guid=4600, account=513, original_rank=4, runtime_rank=4,
fixture=fixture.ACCOUNT_FIXTURE)
self.assertTrue(fixture.bound_context(value, first, None))
for delta in ({'guid': 4601}, {'guid': 4514}, {'account': 511}, {'original_rank': 0},
{'runtime_rank': 0}, {'fixture': '/tmp/account.json'}):
self.assertFalse(fixture.bound_context(value, dict(first, **delta), None))
self.assertFalse(fixture.bound_context(value, first, copy.deepcopy(first)))
def test_manager_profile_and_frontend_admit_exact_created_character(self):
root = Path(__file__).resolve().parents[1]
runners = root / 'runtime/continuation-20261113/codex/Z47-live'
def function(path, name, namespace):
tree = ast.parse(path.read_text())
node = next(n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name == name)
exec(compile(ast.Module(body=[node], type_ignores=[]), str(path), 'exec'), namespace)
return namespace[name]
with mock.patch.object(fixture, 'load_receipt', return_value=receipt()):
namespace = dict(Path=Path, R=root, PALADIN_RECEIPT=None, paladin_fixture=fixture)
select = function(runners / 'run-batch.private.py', 'acceptance_first_profile', namespace)
self.assertEqual(select('paladin'), (4600, 513, 4, fixture.ACCOUNT_FIXTURE))
self.assertEqual(namespace['PALADIN_RECEIPT'], receipt())
with tempfile.TemporaryDirectory() as directory:
temporary = Path(directory)
account = temporary / 'secrets/fixture/account.json';account.parent.mkdir(parents=True)
account.write_text(json.dumps(dict(account_id=513, username='TESTFIXTURE')))
(account.parent / 'password.txt').write_text('unused-test-only')
context_path = temporary / 'runtime/continuation-20261113/codex/Z47-live/context.json'
context_path.parent.mkdir(parents=True)
first = dict(guid=4600, account=513, original_rank=4, runtime_rank=4, fixture=str(account))
context = dict(first=first, second=None);context_path.write_text(json.dumps(context))
namespace = dict(ROOT=temporary, os=os, Path=Path, json=json, PALADIN_RECEIPT=receipt(),
paladin_fixture=fixture, validate_gm_bound_context=lambda first, second: None)
bind = function(runners / 'local-login-batch.private.py', 'bound_source_context', namespace)
with mock.patch.dict(os.environ, GW_OWNED_SOURCE_CONTEXT=str(context_path)), \
mock.patch.object(fixture, 'ACCOUNT_FIXTURE', account):
self.assertEqual(bind()['first']['guid'], 4600)
for guid in (4514, 4526, 4601):
context['first']['guid'] = guid;context_path.write_text(json.dumps(context))
with self.assertRaises(ValueError):bind()
if __name__ == '__main__':unittest.main()