Best Python code snippet using localstack_python
test_submission.py
Source:test_submission.py
...41 with self.assertRaises(ValueError):42 submission.validate_name(" ")43 self.assertEqual(submission.validate_name(" abc "), "abc")44 self.assertEqual(submission.validate_name("ABC"), "ABC")45 def test_validate_priority(self):46 with self.assertRaises(ValueError):47 submission.validate_priority(None)48 with self.assertRaises(ValueError):49 submission.validate_priority("abc")50 with self.assertRaises(ValueError):51 submission.validate_priority(-1)52 self.assertEqual(submission.validate_priority(const.PRIORITY_0), const.PRIORITY_0)53 self.assertEqual(submission.validate_priority(const.PRIORITY_1), const.PRIORITY_1)54 self.assertEqual(submission.validate_priority(const.PRIORITY_2), const.PRIORITY_2)55 def test_init_simple(self):56 with self.assertRaises(ValueError):57 submission.Submission("", "")58 # simple init59 sub = submission.Submission("abc", "SPARK")60 self.assertNotEqual(sub.uid, None)61 self.assertEqual(sub.name, "abc")62 self.assertEqual(sub.system_code, "SPARK")63 self.assertEqual(sub.priority, const.PRIORITY_2)64 self.assertEqual(sub.is_deleted, False)65 self.assertEqual(sub.is_template, False)66 self.assertEqual(sub.status, const.SUBMISSION_PENDING)67 self.assertNotEqual(sub.createtime, None)68 self.assertNotEqual(sub.submittime, None)...
serializers.py
Source:serializers.py
...74# priority = serializers.IntegerField()75# description = serializers.CharField()76# creator = serializers.HiddenField(default=serializers.CurrentUserDefault())77#78# def validate_priority(self, value):79# if int(value) > 100 or int(value) < 1:80# raise serializers.ValidationError('Priority field must be in range 1-100')81# return value82#83# def update(self, instance, validated_data):84# instance.name = validated_data.get('name', instance.name)85# instance.block_id = validated_data.get('block_id', instance.block_id)86# instance.description = validated_data.get('description', instance.description)87# instance.priority = validated_data.get('priority', instance.priority)88# instance.save()89# return instance90#91# def validate_priority(self, value):92# if int(value) > 100 or int(value) < 1:93# raise serializers.ValidationError('Priority field must be in range 1-100')94# return value95class TaskFullSerializer(TaskShortSerializer):96 creator = serializers.HiddenField(default=serializers.CurrentUserDefault())97 class Meta(TaskShortSerializer.Meta):98 fields = TaskShortSerializer.Meta.fields + ('priority', 'description',)99 def validate_priority(self, value):100 if int(value) > 100 or int(value) < 1:101 raise serializers.ValidationError('Priority field must be in range 1-100')102 return value103 def validate_description(self, value):104 if len(value) >= 200 or len(value) <= 10:105 raise serializers.ValidationError('Description field must be in range 10-200 symbols')106 return value107class BlockNestedSerializer(serializers.ModelSerializer):108 id = serializers.IntegerField(read_only=True)109 tasks = TaskFullSerializer(many=True)110 class Meta:111 model = Block112 fields = '__all__'113 def create(self, validated_data):...
test_validations.py
Source:test_validations.py
...22 valid_numbers = [('123', '4567890'), ('1234', '567890')]23 invalid_numbers = [('11', '4567890'), ('10', '567890')]24 self.assertIsNone(validate_phone_numbers(valid_numbers))25 self.assertRaises(PhoneNumberLongSMSCError, validate_phone_numbers, invalid_numbers)26 def test_validate_priority(self):27 valid_priority = 528 invalid_priority = 829 self.assertIsNone(validate_priority(valid_priority))...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!