How to use pre_save method in hypothesis

Best Python code snippet using hypothesis

models.py

Source: models.py Github

copy

Full Screen

...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):...

Full Screen

Full Screen

tests.py

Source: tests.py Github

copy

Full Screen

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]), [])...

Full Screen

Full Screen

signals.py

Source: signals.py Github

copy

Full Screen

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()...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Getting Rid of Technical Debt in Agile Projects

Technical debt was originally defined as code restructuring, but in today’s fast-paced software delivery environment, it has evolved. Technical debt may be anything that the software development team puts off for later, such as ineffective code, unfixed defects, lacking unit tests, excessive manual tests, or missing automated tests. And, like financial debt, it is challenging to pay back.

30 Top Automation Testing Tools In 2022

The sky’s the limit (and even beyond that) when you want to run test automation. Technology has developed so much that you can reduce time and stay more productive than you used to 10 years ago. You needn’t put up with the limitations brought to you by Selenium if that’s your go-to automation testing tool. Instead, you can pick from various test automation frameworks and tools to write effective test cases and run them successfully.

Continuous Integration explained with jenkins deployment

Continuous integration is a coding philosophy and set of practices that encourage development teams to make small code changes and check them into a version control repository regularly. Most modern applications necessitate the development of code across multiple platforms and tools, so teams require a consistent mechanism for integrating and validating changes. Continuous integration creates an automated way for developers to build, package, and test their applications. A consistent integration process encourages developers to commit code changes more frequently, resulting in improved collaboration and code quality.

27 Best Website Testing Tools In 2022

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.

Are Agile Self-Managing Teams Realistic with Layered Management?

Agile software development stems from a philosophy that being agile means creating and responding to change swiftly. Agile means having the ability to adapt and respond to change without dissolving into chaos. Being Agile involves teamwork built on diverse capabilities, skills, and talents. Team members include both the business and software development sides working together to produce working software that meets or exceeds customer expectations continuously.

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful