'''
@Title 文件名称: AttDaysController_test.gotest
@Description 描述: 测试APIAttDaysController
@Author 作者: leijianming 时间(2024-03-31 16:03:58)
@Update 作者: leijianming 时间(2024-03-31 16:03:58)
'''
import json, logging, unittest,datetime
from django.db import transaction
from base.dto import IcHandler
from urllib import request
from base.dto.IcHandler import IcHandler
import json
from urllib import error
from django.test import TestCase
from django.test import TransactionTestCase
from base.consts.consts import _const
import requests, os, django, kunlong
from datetime import datetime
#from base.utils import KunlongUtils
base_url = _const.base_url_local #'http://127.0.0.1:8000/v1'
base_url_entity = base_url + "/attdays"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_tagify.settings") # project_name 项目名称
os.environ.setdefault("INSTALLED_APPS", "kunlong") # project_name 项目名称
django.setup()
from kunlong.compute.model.attdaysmodel import AttDaysModel
from kunlong.compute.service.attdaysservice import AttDaysService
class TestAttDaysController(unittest.TestCase): # TransactionTestCase TestCase会自动删除数据
logger = logging.getLogger(__name__)
# class TestDefault(TestCase): # TransactionTestCase TestCase
@classmethod
def setUpClass(cls):
pass
#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_tagify.settings")
#os.environ.setdefault("INSTALLED_APPS", "kunlong")
# django.setup()
@classmethod
def tearDownClass(cls):
pass
def tearDown(self) -> None:
pass
def setUp(self):
pass # 设置配置
# settings.IGNORE_WECHAT_SIGNATURE = True
#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_tagify.settings")
#os.environ.setdefault("INSTALLED_APPS", "kunlong")
#django.setup()
# settings.configure()
# @transaction.atomic
# def post(self, request):
# # 设置事务保存点
# s1 = transaction.savepoint() # 可以设置多个保存点
#
# # 数据库操作。。。
#
# # 事务回滚 (如果发生异常,就回滚事务)
# transaction.savepoint_rollback(s1) # 可以回滚到指定的保存点
#
# # 提交事务 (如果没有异常,就提交事务)
# transaction.savepoint_commit(s1)
def insert(self):
entity = AttDaysModel() #entity.createdAt = datetime.now()
entity.ini(False)
# KunlongUtils.transDatetime2Str(entity)
entity.transDatetime2Str()
#entity.dirName = "etstDirrname"
entity.save()
# entity = IcDirModel.objects.create(dir_name="补助计算", tenant_id="租户1111", active=True, user_id=0,
# update_user_id=0, parent_dir_id=0, depth=1)
# result = IcDirModel.objects.filter(dir_id=entity.dir_id).values()
# transaction.savepoint_commit(savepoint1)
# print(IcHandler.IcHandler.dumps2json(result[0]))
return entity.daysId
#@transaction.atomic
def test0001_insert(self):
id = self.insert()
print(id)
def buildQueryParam(self):
dict_data = {}
dict_data['orderBys'] = "-daysId"
dict_data['start'] = 0
dict_data['limit'] = 3
param = {}
param['daysId'] = None
dict_data['param'] = param
return dict_data
def test0002_query_service(self): # def test0002_query_service(self):
id = self.insert() #body = '''{"orderBys":"-daysId","start":0,"limit":3,"param":{"daysId":id}} '''
result = AttDaysService.query(**self.buildQueryParam())
print(result.dumps2json())
def test0003_create(self):
entity = AttDaysModel() # entity.createdAt = datetime.now()
entity.ini(False)
entity.transDatetime2Str()
dict = entity.__dict__
del dict['baseModel']
del dict['_state']
e = AttDaysModel.objects.create(**dict)
print(str(e))
#用POST方法向Restful API发生消息
def test0004_save(self):
try:
create_url = base_url_entity + '/save' # the Restful api url
create_headers = {'cookie': 'the cookie'} # the request headers
body_data = ''' {
"daysId": null,
"active": true,
"createdAt": "2021-1-1",
"depth": 1,
"dirName": "补助2计算",
"parentDirId": 0,
"tenantId": "租户1lll",
"updatedAt": "2011-12-21 21:01:11",
"updateUserId": 0,
"userId": 0 } '''
entity = AttDaysModel() #entity.createdAt = datetime.now()
entity.ini(False)
#KunlongUtils.transDatetime2Str(entity)
entity.transDatetime2Str()
# entity.dirName="etstDirrname"
body_data = bytes(str(entity), 'utf8')
resp = requests.post(create_url, headers=create_headers, data=body_data)
result_dict = json.loads(resp.text)
#result = json.dumps(obj=result_dict, indent=4, ensure_ascii=False)
print(IcHandler.dumps2jsonPretty(result_dict)) # print(result_dict['data'])
r = self.findById(result_dict['data'])
print(IcHandler.dumps2jsonPretty(r))
except error.HTTPError as err:
error_body = err.file.read().decode()
print(json.loads(error_body))
def findById(self, id):
query_url_addr = base_url_entity + '/findById?id=' + str(id) # the Restful api url
query_headers = {'cookie': 'the cookie'} # the request headers
resp = requests.get(query_url_addr, headers=query_headers)
result_json = json.loads(resp.text) # the json object of response data
return result_json # json.dumps(obj=result_json, indent=4, ensure_ascii=False)
def test0005_findById(self):
id = self.insert()
r = self.findById(id)
#print(type(r))
print(IcHandler.dumps2jsonPretty(r))
def test0006_findByIds(self):
values = {}
values['id1'] = self.insert()
values['id2'] = self.insert()
url = base_url_entity + '/findByIds?ids={id1},{id2}' # the Restful api url
print("Start findByIds: " + url.format(**values))
create_headers = {'cookie': 'the cookie'} # the request headers
response = requests.get(url.format(**values), headers=create_headers)
result_json = json.loads(response.text)
print(IcHandler.dumps2jsonPretty(result_json))
print("End findByIds: " + url.format(**values))
#{"orderBys":"-dir_id","start":0,"limit":3,"param":{"dir_id":null}} #用POST方法向Restful API发生消息
def test0007_query(self):
id = self.insert()
print(id)
try:
url = base_url_entity + '/query' # the Restful api url
create_headers = {'cookie': 'the cookie'} # the request headers
#body = '''{"orderBys":"-daysId","start":0,"limit":3,"param":{"daysId":null}} '''
body_data = bytes(IcHandler.dumps2jsonPretty(self.buildQueryParam()), 'utf8')
req = request.Request(url, headers=create_headers, data=body_data, method='POST')
resp = request.urlopen(req)
result = resp.read().decode()
result_json = json.loads(result)
#result = json.dumps(obj=result_json, indent=4, ensure_ascii=False)
print(IcHandler.dumps2jsonPretty(result_json))
except error.HTTPError as err:
error_body = err.file.read().decode()
#print(json.loads(result))
def test0008_query(self):
id = self.insert()
print(id)
try:
url = base_url_entity
没有合适的资源?快使用搜索试试~ 我知道了~
gofactroy代码工厂生成python,go
共400个文件
go:277个
proto:41个
template:30个
需积分: 1 0 下载量 61 浏览量
2024-04-04
16:04:18
上传
评论
收藏 21.45MB ZIP 举报
温馨提示
go代码工厂
资源推荐
资源详情
资源评论
收起资源包目录
gofactroy代码工厂生成python,go (400个子文件)
pb.bat 148B
commit.bat 47B
btcd.exe 17.17MB
protoc-gen-go.exe 8.05MB
protoc-gen-micro.exe 6.71MB
golint.exe 6.28MB
protoc.exe 3.65MB
Dockerfile.factroy 885B
Dockerfile.factroy 876B
.gitignore 190B
cmsColumnProto.pb.go 59KB
tableName1Proto.pb.go 55KB
tableName1Proto.pb.go 55KB
tableName2Proto.pb.go 50KB
tableNameProto.pb.go 48KB
dbfactroy.go 22KB
godbfactroy.go 22KB
viewEmployee.go 22KB
employee.go 21KB
cmsColumn.go 21KB
multifactroy.go 18KB
bom.go 18KB
tableName1Srv_test.go 15KB
cmsColumnRpcController.go 15KB
employeeESSrv_test.go 15KB
employeeSrv_test.go 15KB
tableName1Srv_test.go 14KB
cmsColumnSrv_test.go 14KB
employeeSrv_test.go 14KB
departmentSrv_test.go 14KB
tableName1Srv_test.go 14KB
testentity.pb.go 14KB
cmsColumnESSrv_test.go 14KB
tableName1RpcController.go 13KB
tableName1.go 13KB
cmsVisit.go 12KB
cmsLayout.go 12KB
cmsColumnDao.go 12KB
tableName1Dao.go 12KB
utils.go 11KB
cmsLayoutItem.go 11KB
tableName2.go 11KB
employeeDao.go 11KB
tableName2Dao.go 10KB
cmsColumnRpc.go 10KB
tableNameDao.go 10KB
dbcontext.go 10KB
tableName1Srv_test.go 10KB
cmsLayoutDao.go 10KB
cmsLayoutTypeDao.go 10KB
natsTopicDao.go 9KB
cmsVisitDao.go 9KB
post.pb.go 9KB
departmentDao.go 9KB
topicDao.go 9KB
user.pb.go 9KB
tableName2Rpc.go 9KB
tableName1Rpc.go 9KB
tableName1Proto.pb.micro.go 8KB
tableName1Proto.pb.micro.go 8KB
cmsColumnProto.pb.micro.go 8KB
tableName.go 8KB
tableNameRpc.go 8KB
viewEmployeeDao.go 8KB
multiqueryEmployeeDptSrv_test.go 8KB
gofilefactroy.go 8KB
tableName1ESService.go 8KB
tableName1Service.go 8KB
main.go 8KB
tableName2Proto.pb.micro.go 8KB
cmsLayoutType.go 8KB
multiqueryEmployeeSrv_test.go 8KB
tableName1Controller_test.go 8KB
employeeDAO_test.go 8KB
tableName1DAO_test.go 8KB
natsTopicESService.go 8KB
tableNameESService.go 7KB
tableNameProto.pb.micro.go 7KB
natsTopicService.go 7KB
cmsColumnESService.go 7KB
godbcontext.go 7KB
cmsColumnService.go 7KB
tableNameService.go 7KB
tableName2ESService.go 7KB
department.go 7KB
tableName2Service.go 7KB
bomDao.go 7KB
multiqueryEmployeeDao.go 7KB
topicESService.go 7KB
topicService.go 7KB
rpcfactroy.go 7KB
filefactroy.go 7KB
modelfactroy.go 7KB
cmsLayoutTypeESService.go 7KB
cmsLayoutTypeService.go 7KB
modelfactroy.go 7KB
multiqueryEmployeeDto.go 7KB
cmsLayoutESService.go 7KB
cmsLayoutService.go 7KB
departmentESService.go 7KB
共 400 条
- 1
- 2
- 3
- 4
资源评论
leijmdas
- 粉丝: 1779
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Picasso_v3.1 2.ipa
- chromedriver-mac-arm64.zip
- 蓝zapro.apk
- chromedriver-linux64.zip
- UCAS研一深度学习实验-MNIST手写数字识别python源码+详细注释(高分项目)
- 基于Python和PyTorch框架完成的一个手写数字识别实验源码(带MINIST手写数字数据集)+详细注释(高分项目)
- 基于Matlab在MNIST数据集上利用CNN完成手写体数字识别任务,并实现单层CNN反向传播算法+源代码+文档说明(高分项目)
- NVIDIA驱动、CUDA和Pytorch及其依赖
- 基于SVM多特征融合的微表情识别python源码+项目说明+详细注释(高分课程设计)
- html动态爱心代码一(附源码)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功