forked from mtusi2026/mtusi2026lab2
fixes
This commit is contained in:
@@ -8,6 +8,7 @@ import time
|
||||
import unittest
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
@@ -33,11 +34,15 @@ def compose(*args):
|
||||
)
|
||||
|
||||
|
||||
def http(method, path, token=None, expected=None):
|
||||
def http(method, path, token=None, expected=None, body=None):
|
||||
headers = {'Accept': 'application/json'}
|
||||
if token:
|
||||
headers['Authorization'] = 'Bearer ' + token
|
||||
req = urllib.request.Request(BASE + path, headers=headers, method=method)
|
||||
data = None
|
||||
if body is not None:
|
||||
data = json.dumps(body).encode('utf-8')
|
||||
headers['Content-Type'] = 'application/json'
|
||||
req = urllib.request.Request(BASE + path, data=data, headers=headers, method=method)
|
||||
try:
|
||||
response = urllib.request.urlopen(req, timeout=5)
|
||||
except urllib.error.HTTPError as error:
|
||||
@@ -105,6 +110,21 @@ class DependencyFailureTests(unittest.TestCase):
|
||||
self.assertEqual(code, 503)
|
||||
self.assertEqual(payload['error']['code'], 'unavailable')
|
||||
|
||||
def test_postgres_down_registration_returns_unavailable(self):
|
||||
compose('stop', 'postgres')
|
||||
code, payload = http(
|
||||
'POST',
|
||||
'/api/v1/users',
|
||||
expected=503,
|
||||
body={
|
||||
'username': 'u_down_' + uuid.uuid4().hex[:12],
|
||||
'display_name': 'Database unavailable',
|
||||
'password': 'T3st-' + uuid.uuid4().hex,
|
||||
},
|
||||
)
|
||||
self.assertEqual(code, 503)
|
||||
self.assertEqual(payload['error']['code'], 'unavailable')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -2,11 +2,32 @@
|
||||
"""Sanity checks for track 2 evidence artifacts."""
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
EVIDENCE = ROOT / 'evidence' / 'track2'
|
||||
sys.path.insert(0, str(ROOT / 'scripts'))
|
||||
from track2_backup_restore import snapshot # noqa: E402
|
||||
|
||||
|
||||
class SnapshotSerializationTests(unittest.TestCase):
|
||||
def test_snapshot_preserves_multiline_message_text(self):
|
||||
expected_sample = [{
|
||||
'id': 'message-id',
|
||||
'chat_id': 'chat-id',
|
||||
'text': 'первая строка\nвторая строка',
|
||||
}]
|
||||
with patch(
|
||||
'track2_backup_restore.subprocess.check_output',
|
||||
side_effect=['2\n', '1\n', json.dumps(expected_sample, ensure_ascii=False)],
|
||||
) as check_output:
|
||||
result = snapshot('postgres', ['docker', 'compose'], 'messenger')
|
||||
|
||||
self.assertEqual(result['sample'], expected_sample)
|
||||
self.assertIn('json_agg(json_build_object(', check_output.call_args_list[2].args[0][-1])
|
||||
|
||||
|
||||
@unittest.skipUnless(
|
||||
|
||||
Reference in New Issue
Block a user