123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- import unittest
- import base64
- from dataclasses import dataclass
- from pathlib import Path
- import requests
- url = 'http://localhost:8080'
- def send_request(image_path, image_type):
- with open(image_path, 'rb') as f:
- img_str: str = base64.encodebytes(f.read()).decode('utf-8')
- r = requests.post(f'{url}/ocr_system/schoolcert', json={'image': img_str, 'image_type': image_type})
- print(r.json())
- return r.json()
- @dataclass
- class ResultItem:
- status: str
- orientation: int
- name: str
- gender: str
- admission_time: str
- education_time: str
- education_level: str
- education_type: str
- learning_type: str
- school: str
- major: str
- number: str
- class TestSchoolCertOcr(unittest.TestCase):
- def _helper(self, image_path, item: ResultItem, image_type='1'):
- root = Path(__file__).parent
- image_path = str(root / image_path)
- r = send_request(image_path, image_type)
- self.assertEqual(item, ResultItem(status=r['status'],
- orientation=r['result']['orientation'],
- name=r['result']['name']['text'],
- gender=r['result']['gender']['text'],
- admission_time=r['result']['admission_time']['text'],
- education_time=r['result']['education_time']['text'],
- education_type=r['result']['education_type']['text'],
- education_level=r['result']['education_level']['text'],
- learning_type=r['result']['learning_type']['text'],
- school=r['result']['school']['text'],
- major=r['result']['major']['text'],
- number=r['result']['number']['text']
- ))
- def test_case_01_0(self):
- image_path = '../images/1/10045201A11学籍学历证明001.JPG'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='徐科',
- gender='男',
- admission_time='2010年09月01日',
- education_time='2013年06月30日',
- education_level='专科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='武汉职业技术学院',
- major='摄影摄像技术',
- number='108341201306417803'))
- def test_case_02_0(self):
- image_path = '../images/1/10047539A11学籍学历证明001.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='苏丽欢',
- gender='男',
- admission_time='2012年09月01日',
- education_time='2015年07月01日',
- education_level='专科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='广西民族师范学院',
- major='汉语',
- number='106041201506002280'))
- def test_case_03_0(self):
- image_path = '../images/1/10048160A11学籍学历证明001.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='罗建亮',
- gender='男',
- admission_time='2008年11月01日',
- education_time='2011年07月05日',
- education_level='专科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='百色职业学院',
- major='机电一体化技术',
- number='140681201106000733'))
- def test_case_04_0(self):
- image_path = '../images/1/10053240A11学籍学历证明001.jpg'
- self._helper(image_path, ResultItem(status='000',
- orientation=0,
- name='张广渊',
- gender='女',
- admission_time='2007年09月01日',
- education_time='2011年06月30日',
- education_level='本科',
- education_type='普通高等教育',
- learning_type='普通全日制',
- school='武汉工业学院工商学院',
- major='国际经济与贸易',
- number='132411201105872980'))
|