How to use adapt_date method in freezegun

Best Python code snippet using freezegun

clumper.py

Source:clumper.py Github

copy

Full Screen

...7User = models.get_model('auth', 'user')8# for portal9Comment = models.get_model('comments', 'comment')10ContentType = models.get_model('contenttypes', 'contenttype')11def adapt_date(b):12 date_fields = ('submit_date', 'modified', 'added',)13 return [getattr(b, d) for d in date_fields if hasattr(b, d)][0]14class Clumper():15 """Clumps stuff by thing.content_object"""16 stuff = None # don't make array here or it persists to other requests.17 items = None18 def __init__(self, *feeds, **kwargs):19 self.items = {}20 group_by = kwargs.get('group_by', None)21 for f in feeds:22 for item in f:23 parent = self.ClumpItem.parent_object(item, group_by)24 if parent in self.items:25 self.items[parent].append(item)26 else:27 self.items[parent] = self.ClumpItem(item,28 group_by=group_by)29 def __len__(self):30 # used to be each unclumped-item, but...why?31 return len(self.items)32 def __iter__(self):33 # will use ClumpItem.__cmp__34 return iter(sorted(self.items.values()))35 class ClumpItem():36 things = None37 primary_thing = None38 def __init__(self, thingie, primary=None, group_by=None):39 self.things = []40 self.things.append(thingie)41 self.primary = primary42 self.group_by = group_by43 def __cmp__(self, other):44 return self.order_by(self.things[0], other.things[0])45 def __unicode__(self):46 return unicode(self.things[0])47 def append(self, obj):48 if len(self.things) < 4:49 if obj not in self.things: # no dups50 self.things.append(obj)51 self.things.sort(self.order_by)52 @staticmethod53 def order_by(a, b):54 """newest first w/support for Comment and SherdNote, Project"""55 a_date = adapt_date(a)56 b_date = adapt_date(b)57 return cmp(b_date, a_date)58 @property59 def add_only(self):60 return (len(self.things) == 1 and isinstance(self.things[0],61 Asset))62 @classmethod63 def parent_object(cls, thingie, group_by=None):64 if hasattr(thingie, 'clump_parent'):65 return thingie.clump_parent(group_by)66 else:67 return getattr(thingie, 'content_object', None)68 @property69 def content_object(self):70 return self.parent_object(self.things[0], self.group_by)71 @property72 def href(self):73 if self.add_only or isinstance(self.content_object, Collaboration):74 parent = self.content_object.get_parent()75 if parent and isinstance(parent.content_object, Project):76 return parent.content_object.get_absolute_url()77 else:78 return getattr(self.things[0], 'get_parent_url',79 self.things[0].get_absolute_url)()80 else:81 return self.content_object.get_absolute_url()82 @property83 def title(self):84 if self.add_only:85 return self.things[0].title86 else:87 return self.content_object.title88 @property89 def type(self):90 return self.content_object.__class__.__name__.lower()91 @staticmethod92 def adapt_str(thing):93 if isinstance(thing, Project):94 return None95 if isinstance(thing, SherdNote):96 return None97 return getattr(thing, 'body',98 getattr(thing, 'comment', None) or getattr(thing,99 'title',100 None))101 @staticmethod102 def adapt_user(thing):103 return getattr(thing, 'author',104 getattr(thing, 'user', getattr(thing,105 'participant',106 None)))107 @staticmethod108 def adapt_action(thing):109 amap = {Comment: 'discussed',110 SherdNote: 'analyzed',111 Asset: 'added',112 Project: 'updated',113 DiscussionIndex: 'discussed', }114 return amap.get(type(thing), 'notes')115 def adapt_href(self, thing):116 if isinstance(thing, Comment):117 return None118 if isinstance(thing, SherdNote) and thing.range1 is None:119 return None120 if isinstance(self.content_object, Collaboration):121 if hasattr(thing.content_object, "get_top_ancestor"):122 parent = thing.content_object.get_top_ancestor()123 if parent and isinstance(parent.content_object, Project):124 return None125 if hasattr(thing, 'get_absolute_url'):126 return thing.get_absolute_url()127 return self.content_object.get_absolute_url()128 def __iter__(self):129 """returns strings for each interesting thingie"""130 return iter([{'user': self.adapt_user(i),131 'action': self.adapt_action(i),132 'href': self.adapt_href(i),133 'text': self.adapt_str(i),134 'date': adapt_date(i),135 }136 for i in self.things])137 def __getitem__(self, k):...

Full Screen

Full Screen

dbapi2.py

Source:dbapi2.py Github

copy

Full Screen

...21version_info = tuple([ int(x) for x in version.split('.') ])22sqlite_version_info = tuple([ int(x) for x in sqlite_version.split('.') ])23Binary = buffer24def register_adapters_and_converters():25 def adapt_date(val):26 return val.isoformat()27 def adapt_datetime(val):28 return val.isoformat(' ')29 def convert_date(val):30 return datetime.date(*map(int, val.split('-')))31 def convert_timestamp(val):32 datepart, timepart = val.split(' ')33 year, month, day = map(int, datepart.split('-'))34 timepart_full = timepart.split('.')35 hours, minutes, seconds = map(int, timepart_full[0].split(':'))36 if len(timepart_full) == 2:37 microseconds = int(timepart_full[1])38 else:39 microseconds = 0...

Full Screen

Full Screen

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 freezegun 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