Best Python code snippet using hypothesis
models.py
Source: models.py
...755 created_at = DateTimeField(default=datetime.now)756 unread = BooleanField(required=True, default=True)757 msg_type = StringField(max_length=7, required=True, choices=message_type_choices)758 @classmethod # signal pre_save (asociar em cada modelo)759 def pre_save(cls, sender, document, **kwargs):760 document.created_at = datetime.now()761 meta = {762 'collection': 'messages',763 }764signals.pre_save.connect(Message.pre_save, sender=Message)765# #### LOGS766class ExtractLog(DynamicDocument):767 meta = {768 'max_size': 104857600, # 100 MB (104857600 Bytes)769 'max_documents': 100000,770 'collection': 'extract_log',771 'db_alias': config.OPAC_PROC_LOG_MONGODB_NAME,772 }773class TransformLog(DynamicDocument):...
tests.py
Source: tests.py
1import sys2from StringIO import StringIO3from django.test import TestCase4from django.db import models5from regressiontests.signals_regress.models import Author, Book6signal_output = []7def pre_save_test(signal, sender, instance, **kwargs):8 signal_output.append('pre_save signal, %s' % instance)9 if kwargs.get('raw'):10 signal_output.append('Is raw')11def post_save_test(signal, sender, instance, **kwargs):12 signal_output.append('post_save signal, %s' % instance)13 if 'created' in kwargs:14 if kwargs['created']:15 signal_output.append('Is created')16 else:17 signal_output.append('Is updated')18 if kwargs.get('raw'):19 signal_output.append('Is raw')20def pre_delete_test(signal, sender, instance, **kwargs):21 signal_output.append('pre_save signal, %s' % instance)22 signal_output.append('instance.id is not None: %s' % (instance.id != None))23def post_delete_test(signal, sender, instance, **kwargs):24 signal_output.append('post_delete signal, %s' % instance)25 signal_output.append('instance.id is not None: %s' % (instance.id != None))26class SignalsRegressTests(TestCase):27 """28 Testing signals before/after saving and deleting.29 """30 def get_signal_output(self, fn, *args, **kwargs):31 # Flush any existing signal output32 global signal_output33 signal_output = []34 fn(*args, **kwargs)35 return signal_output36 def setUp(self):37 # Save up the number of connected signals so that we can check at the end38 # that all the signals we register get properly unregistered (#9989)39 self.pre_signals = (len(models.signals.pre_save.receivers),40 len(models.signals.post_save.receivers),41 len(models.signals.pre_delete.receivers),42 len(models.signals.post_delete.receivers))43 models.signals.pre_save.connect(pre_save_test)44 models.signals.post_save.connect(post_save_test)45 models.signals.pre_delete.connect(pre_delete_test)46 models.signals.post_delete.connect(post_delete_test)47 def tearDown(self):48 models.signals.post_delete.disconnect(post_delete_test)49 models.signals.pre_delete.disconnect(pre_delete_test)50 models.signals.post_save.disconnect(post_save_test)51 models.signals.pre_save.disconnect(pre_save_test)52 # Check that all our signals got disconnected properly.53 post_signals = (len(models.signals.pre_save.receivers),54 len(models.signals.post_save.receivers),55 len(models.signals.pre_delete.receivers),56 len(models.signals.post_delete.receivers))57 self.assertEqual(self.pre_signals, post_signals)58 def test_model_signals(self):59 """ Model saves should throw some signals. """60 a1 = Author(name='Neal Stephenson')61 self.assertEqual(self.get_signal_output(a1.save), [62 "pre_save signal, Neal Stephenson",63 "post_save signal, Neal Stephenson",64 "Is created"65 ])66 b1 = Book(name='Snow Crash')67 self.assertEqual(self.get_signal_output(b1.save), [68 "pre_save signal, Snow Crash",69 "post_save signal, Snow Crash",70 "Is created"71 ])72 def test_m2m_signals(self):73 """ Assigning and removing to/from m2m shouldn't generate an m2m signal """74 b1 = Book(name='Snow Crash')75 self.get_signal_output(b1.save)76 a1 = Author(name='Neal Stephenson')77 self.get_signal_output(a1.save)78 self.assertEqual(self.get_signal_output(setattr, b1, 'authors', [a1]), [])...
signals.py
Source: signals.py
1"""App signals module"""2from django.db.models import Max3from django.db.models.signals import pre_save, post_save4from django.dispatch import receiver5from django.utils.text import slugify6from django.utils.timezone import now7from django.utils.translation import ugettext_lazy as _8from action.models import Action, Event, RecurrentAction, Note, Step, Log9#10# Receivers11#12@receiver(pre_save, sender=Action, dispatch_uid="action_pre_created")13@receiver(pre_save, sender=Event, dispatch_uid="event_pre_created")14@receiver(pre_save, sender=RecurrentAction, dispatch_uid="recurrent_action_pre_created")15def action_pre_created(sender, instance, raw, using, update_fields, **kwargs): # pylint: disable=unused-argument16 """Create name and slug"""17 if instance.pk: # Called only on creation18 return19 # from nose.tools import set_trace; set_trace()20 instance.name = "{} {} â {}".format(instance.priority[0], instance.project.name, instance.label)21 if not instance.slug:22 instance.slug = slugify(instance.project.name + "__" + instance.label)23@receiver(post_save, sender=Action, dispatch_uid="action_post_save")24@receiver(post_save, sender=Event, dispatch_uid="event_post_save")25@receiver(post_save, sender=RecurrentAction, dispatch_uid="recurrent_action_post_save")26def action_post_save(sender, instance, created, raw, using, update_fields,27 **kwargs): # pylint: disable=unused-argument,too-many-arguments28 """Create the first log when an action is created."""29 if not created:30 return31 Log.objects.create(action=instance, date=now(), content=_("Creation of the action"))32@receiver(pre_save, sender=Note, dispatch_uid="note_pre_created")33@receiver(pre_save, sender=Step, dispatch_uid="step_pre_created")34@receiver(pre_save, sender=Log, dispatch_uid="log_pre_created")35def inline_pre_created(sender, instance, raw, using, update_fields, **kwargs): # pylint: disable=unused-argument36 """Create number"""37 if instance.pk: # Called only on creation38 return39 # from nose.tools import set_trace; set_trace()...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.
How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.
Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.
Mobile application development is on the rise like never before, and it proportionally invites the need to perform thorough testing with the right mobile testing strategies. The strategies majorly involve the usage of various mobile automation testing tools. Mobile testing tools help businesses automate their application testing and cut down the extra cost, time, and chances of human error.
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!!