class FmuModelViewTest(APITestCase): """ Test FmuModelParameters View """ def setUp(self) -> None: self.test_user = User(name='test_user', email='*****@*****.**', password='******') self.test_user.save() self.token = Token.objects.create( user=self.test_user ) def test_Model_Initialization(self): self.client.force_login(user=self.test_user) data = { "model_name": "test", "step_size": "800", "final_time": "72.0" } response = self.client.post( '/init_model/', data=data, format='json', HTTP_AUTHORIZATION='Token ' + self.token.key ) self.assertEqual(response.status_code, 201)
def setUp(self) -> None: self.test_user = User(name='test_user', email='*****@*****.**', password='******') self.test_user.save() self.token = Token.objects.create(user=self.test_user)
def setUp(self) -> None: self.test_user = User(name='test_user', email='*****@*****.**', password='******') self.test_user.save() self.token = Token.objects.create(user=self.test_user) self.model = FmuModel(model_name="test_model", user=self.test_user, step_size=600, final_time=72.0) self.model.save()
class OutputViewTest(APITestCase): """ Test Output View """ def setUp(self) -> None: self.test_user = User(name='test_user', email='*****@*****.**', password='******') self.test_user.save() self.token = Token.objects.create( user=self.test_user ) self.model = FmuModel( model_name="test_model", user=self.test_user, step_size=600, final_time=72.0 ) self.model.save() def test_output_create(self): self.client.force_login(user=self.test_user) data = { 'user': self.test_user.email, 'fmu_model': self.model.model_name, "time_step": "800", "yshade": "2.4", "dry_bulb": "5.0", "troo": "7.0", "isolext": "4.01", "sout": "6.89", "zonesens": "9.111", "cool_rate": "18.9" } response = self.client.post( '/output/', data=data, format='json', HTTP_AUTHORIZATION='Token ' + self.token.key ) self.assertEqual(response.status_code, 201)
class InputViewTest(APITestCase): """ Test Input View """ def setUp(self) -> None: self.test_user = User(name='test_user', email='*****@*****.**', password='******') self.test_user.save() self.token = Token.objects.create( user=self.test_user ) self.model = FmuModel( model_name="test_model", user=self.test_user, step_size=600, final_time=72.0 ) self.model.save() def test_input_create(self): self.client.force_login(user=self.test_user) data = { 'user': self.test_user.email, 'fmu_model': self.model.model_name, 'time_step': 600, 'yshade': 1.0 } response = self.client.post( '/input/', data=data, format='json', HTTP_AUTHORIZATION='Token ' + self.token.key ) self.assertEqual(response.status_code, 201)
def create(self, validated_data): """""" user = User(email=validated_data['email'], name=validated_data['name']) user.set_password(validated_data['password']) user.save() return user
def create_user(): data = request.get_json() hashed_password = generate_password_hash(data['password'], method='sha256') new_user = User(public_id=str(uuid.uuid4()), name=data['name'], password=hashed_password, admin=False) db.session.add(new_user) db.session.commit() return jsonify({'massage': 'New user created!'})
def post(self): data_dict = request.json mobile = data_dict.get('mobile') nickname = data_dict.get('nickname') password = data_dict.get('password') if not [mobile, password]: return jsonify(code=400, msg="参数不完整") if not re.match('1[3456789]\\d{9}', mobile): return jsonify(code=400, msg="手机不正确") user = User() user.mobile = mobile user.nickname = nickname user.password = password try: db.session.add(user) db.session.commit() except Exception as e: return jsonify(code=400, msg='数据创建失败') return jsonify(code=200, msg='注册成功')
def create_initial_data(): from rest_api.models import User, UserProfile from rest_api.models import IdentityChoices from rest_api.models import Organization if not User.objects.filter(username='******').exists(): user = User(username='******') user.set_password('acm') user.save() profile = UserProfile(user=user, username=user.username, name='_kawaiiQ') profile.sex = 'MALE' profile.email = '*****@*****.**' profile.identities = { IdentityChoices.user_admin: True, IdentityChoices.org_admin: True } profile.save() if not User.objects.filter(username='******').exists(): user = User(username='******') user.set_password('acm') user.save() profile = UserProfile(user=user, username=user.username, name='Boss') profile.sex = 'MALE' profile.identities = { IdentityChoices.user_admin: True } profile.save() if not User.objects.filter(username='******').exists(): user = User(username='******') user.set_password('acm') user.save() profile = UserProfile(user=user, username=user.username, name='科大OJ某管理员') profile.sex = 'SECRET' profile.identities = { IdentityChoices.org_admin: True } profile.save()