Best Python code snippet using molecule_python
f49f6dc9b600_add__created_and__modified_fields_to_.py
Source: f49f6dc9b600_add__created_and__modified_fields_to_.py
1"""Add _created and _modified fields to all tables2Revision ID: f49f6dc9b6003Revises: ab732474a8294Create Date: 2018-04-26 23:21:25.3754255"""6from alembic import op7import sqlalchemy as sa8# revision identifiers, used by Alembic.9revision = 'f49f6dc9b600'10down_revision = 'ab732474a829'11branch_labels = None12depends_on = None13def upgrade():14 op.add_column('LabelSelections', sa.Column('_created', sa.DateTime(), server_default=sa.text('now()'), nullable=False))15 op.add_column('LabelSelections', sa.Column('_modified', sa.DateTime(), server_default=sa.text('now()'), nullable=False))16 op.add_column('Labels', sa.Column('_created', sa.DateTime(), server_default=sa.text('now()'), nullable=False))17 op.add_column('Labels', sa.Column('_modified', sa.DateTime(), server_default=sa.text('now()'), nullable=False))18 op.add_column('Roles', sa.Column('_created', sa.DateTime(), server_default=sa.text('now()'), nullable=False))19 op.add_column('Roles', sa.Column('_modified', sa.DateTime(), server_default=sa.text('now()'), nullable=False))20 op.add_column('ScanCategories', sa.Column('_created', sa.DateTime(), server_default=sa.text('now()'), nullable=False))21 op.add_column('ScanCategories', sa.Column('_modified', sa.DateTime(), server_default=sa.text('now()'), nullable=False))22 op.add_column('Scans', sa.Column('_created', sa.DateTime(), server_default=sa.text('now()'), nullable=False))23 op.add_column('Scans', sa.Column('_modified', sa.DateTime(), server_default=sa.text('now()'), nullable=False))24 op.add_column('Slices', sa.Column('_created', sa.DateTime(), server_default=sa.text('now()'), nullable=False))25 op.add_column('Slices', sa.Column('_modified', sa.DateTime(), server_default=sa.text('now()'), nullable=False))26 op.add_column('Users', sa.Column('_created', sa.DateTime(), server_default=sa.text('now()'), nullable=False))27 op.add_column('Users', sa.Column('_modified', sa.DateTime(), server_default=sa.text('now()'), nullable=False))28def downgrade():29 op.drop_column('Users', '_modified')30 op.drop_column('Users', '_created')31 op.drop_column('Slices', '_modified')32 op.drop_column('Slices', '_created')33 op.drop_column('Scans', '_modified')34 op.drop_column('Scans', '_created')35 op.drop_column('ScanCategories', '_modified')36 op.drop_column('ScanCategories', '_created')37 op.drop_column('Roles', '_modified')38 op.drop_column('Roles', '_created')39 op.drop_column('Labels', '_modified')40 op.drop_column('Labels', '_created')41 op.drop_column('LabelSelections', '_modified')...
1_7_decorator_demo01.py
Source: 1_7_decorator_demo01.py
1#!/usr/bin/python2# -*- encoding: utf-8 -*-3"""4è£
饰类5"""6import functools7import time8def sortable_by_creation_time(cls):9 """Given a class, augment the class to have its instances be sortable10 by the timestamp at which they were instantiated.11 """12 # Augment the class original `__init__` method to also store a 13 # `_created` attribute on the instance, which corresponds to when it14 # was instantiated.15 original_init = cls.__init__16 @functools.wraps(original_init)17 def new_init(self, *args, **kwargs):18 original_init(self, *args, **kwargs)19 self._created = time.time()20 cls.__init__ = new_init21 # Add `__lt__` and `__gt__` methods that return True or False based on22 # the created values in question.23 cls.__lt__ = lambda self, other: self._created < other._created24 cls.__gt__ = lambda self, other: self._created > other._created25 # Done; return the class object26 return cls27@sortable_by_creation_time28class Sortable(object):29 """docstring for Sortable"""30 def __init__(self, identifier):31 self.identifier = identifier32 def __repr__(self):33 return self.identifier34first = Sortable('1')35second = Sortable('2')36third = Sortable('3')37print(first._created)38print(second._created)39print(third._created)40sortables = [third, second, first]41print(sorted(sortables))...
create-providers.py
Source: create-providers.py
1from django.core.management.base import BaseCommand2from mce_django_app import constants3from mce_django_app.models.common import Provider4class Command(BaseCommand):5 help = 'Create or Update all providers'6 def _run_command(self):7 _created = 08 _updated = 09 for p in constants.Provider:10 provider, created = Provider.objects.update_or_create(name=p.value)11 if created:12 _created += 113 else:14 _updated += 115 return _created, _updated16 def handle(self, *args, **options):17 _created, _updated = self._run_command()18 msg = f"create provider - created[{_created}] - updated[{_updated}]"...
Check out the latest blogs from LambdaTest on this topic:
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
Most test automation tools just do test execution automation. Without test design involved in the whole test automation process, the test cases remain ad hoc and detect only simple bugs. This solution is just automation without real testing. In addition, test execution automation is very inefficient.
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
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!!