Пример #1
0
 def test_convert_call_date_prefixes_operators(self):
     document = {
         'insert': {
             '$set': {
                 'date': '2017-10-26'
             },
             '$setOnInsert': {
                 'date': '2017-9-26'
             },
             '$addToSet': {
                 'date': '2017-8-26'
             }
         }
     }
     f = Fields(dates=['date'])
     f.convert_call(document, ['insert'])
     self.assertEqual(document, {
         'insert': {
             '$set': {
                 'date': datetime.date(2017, 10, 26)
             },
             '$setOnInsert': {
                 'date': datetime.date(2017, 9, 26)
             },
             '$addToSet': {
                 'date': datetime.date(2017, 8, 26)
             }
         }
     })
Пример #2
0
 def test_convert_call_date_time_prefixes_dotstring_operators11(self):
     document = {
         'update': {
             '$set': {
                 'roles.$.permissions.componentPermissions.foo.updatedAt': '2017-10-26T09:16:00+00:00'
             }
         }
     }
     f = Fields(date_times=[
         'createdAt',
         'updatedAt',
         'deletedAt',
         'roles.createdAt',
         'roles.updatedAt',
         'roles.deletedAt',
         'roles.owners.createdAt',
         'roles.owners.updatedAt',
         'roles.owners.deletedAt',
         'roles.members.createdAt',
         'roles.members.updatedAt',
         'roles.members.deletedAt',
         'members.createdAt',
         'members.updatedAt',
         'members.deletedAt',
         'components.createdAt',
         'components.updatedAt',
         'components.deletedAt'])
     f.convert_call(document, ['update'])
     self.assertEqual(document, {
         'update': {
             '$set': {
                 'roles.$.permissions.componentPermissions.foo.updatedAt': '2017-10-26T09:16:00+00:00'
             }
         }
     })
Пример #3
0
 def test_convert_call_date_object_list3(self):
     document = {
         'insert': {
             'dates': [
                 {
                     'date': {
                         'o': '2017-10-26'
                     }
                 },
                 {
                     'date': {
                         'o': '2017-10-26'
                     }
                 }
             ]
         }
     }
     f = Fields(dates=['insert.dates.date.o'])
     f.convert_call(document)
     self.assertEqual(document, {
         'insert': {
             'dates': [
                 {
                     'date': {
                         'o': datetime.date(2017, 10, 26)
                     }
                 },
                 {
                     'date': {
                         'o': datetime.date(2017, 10, 26)
                     }
                 }
             ]
         }
     })
Пример #4
0
 def test_convert_call_date_time_prefixes_existing(self):
     document = {
         'insert': {
             'date': '2017-10-26T09:16:00+00:00'
         },
         'inserts': {
             'date': '2017-10-26T09:16:00+00:00'
         },
         'insert2': {
             'date': '2017-10-26T09:16:00+00:00'
         }
     }
     f = Fields(date_times=['insert.date'])
     f.convert_call(document, ['insert', 'inserts'])
     self.assertEqual(document, {
         'insert': {
             'date': datetime.datetime(2017, 10, 26, 9, 16, tzinfo=pytz.utc)
         },
         'inserts': {
             'date': '2017-10-26T09:16:00+00:00'
         },
         'insert2': {
             'date': '2017-10-26T09:16:00+00:00'
         }
     })
Пример #5
0
 def test_convert_call_date_time_prefixes_operators2(self):
     document = {
         'insert': {
             '$insert': {
                 'date': '2017-10-26T09:16:00+00:00'
             },
             '$inserts': {
                 'date': '2017-9-26T09:16:00+00:00'
             },
             '$insert2': {
                 'date': '2017-8-26T09:16:00+00:00'
             }
         }
     }
     f = Fields(date_times=['date'])
     f.convert_call(document, ['insert'])
     self.assertEqual(document, {
         'insert': {
             '$insert': {
                 'date': '2017-10-26T09:16:00+00:00'
             },
             '$inserts': {
                 'date': '2017-9-26T09:16:00+00:00'
             },
             '$insert2': {
                 'date': '2017-8-26T09:16:00+00:00'
             }
         }
     })
Пример #6
0
 def test_convert_call_date_time_object_list2(self):
     document = {
         'dates': [
             {
                 'date': {
                     'o': '2017-10-26T09:16:00+00:00'
                 }
             },
             {
                 'date': {
                     'o': '2017-10-26T09:15:00+00:00'
                 }
             }
         ]
     }
     f = Fields(date_times=['dates.date.o'])
     f.convert_call(document)
     self.assertEqual(document, {
         'dates': [
             {
                 'date': {
                     'o': datetime.datetime(2017, 10, 26, 9, 16, tzinfo=pytz.utc)
                 }
             },
             {
                 'date': {
                     'o': datetime.datetime(2017, 10, 26, 9, 15, tzinfo=pytz.utc)
                 }
             }
         ]
     })
Пример #7
0
 def test_convert_call_date_prefixes_existing(self):
     document = {
         'insert': {
             'date': '2017-10-26'
         },
         'inserts': {
             'date': '2017-10-26'
         },
         'insert2': {
             'date': '2017-10-26'
         }
     }
     f = Fields(dates=['insert.date'])
     f.convert_call(document, ['insert', 'inserts'])
     self.assertEqual(document, {
         'insert': {
             'date': datetime.date(2017, 10, 26)
         },
         'inserts': {
             'date': '2017-10-26'
         },
         'insert2': {
             'date': '2017-10-26'
         }
     })
Пример #8
0
 def test_convert_call_date_time_prefixes_dotstring_operators13(self):
     document = {
         'filter': {
             'roles': {
                 '$elemMatch': {
                     'permissions.componentPermissions.foo': {
                         '$exists': False
                     }
                 }
             }
         }
     }
     f = Fields(date_times=[
         'roles.permissions.componentPermissions.foo.createdAt'
     ])
     self.maxDiff = None
     f.convert_call(document, ['filter', 'projection', 'update'])
     self.assertEqual(document, {
         'filter': {
             'roles': {
                 '$elemMatch': {
                     'permissions.componentPermissions.foo': {
                         '$exists': False
                     }
                 }
             }
         }
     })
Пример #9
0
 def test_convert_call_date_time_prefixes_operators(self):
     document = {
         'insert': {
             '$set': {
                 'date': '2017-10-26T09:16:00+00:00'
             },
             '$setOnInsert': {
                 'date': '2017-9-26T09:16:00+00:00'
             },
             '$addToSet': {
                 'date': '2017-8-26T09:16:00+00:00'
             }
         }
     }
     f = Fields(date_times=['date'])
     f.convert_call(document, ['insert'])
     self.assertEqual(document, {
         'insert': {
             '$set': {
                 'date': datetime.datetime(2017, 10, 26, 9, 16, tzinfo=pytz.utc)
             },
             '$setOnInsert': {
                 'date': datetime.datetime(2017, 9, 26, 9, 16, tzinfo=pytz.utc)
             },
             '$addToSet': {
                 'date': datetime.datetime(2017, 8, 26, 9, 16, tzinfo=pytz.utc)
             }
         }
     })
Пример #10
0
 def test_convert_call_date_time_nonexisting_key(self):
     document = {
         'date': '2017-10-26T09:16:00+00:00'
     }
     cdocument = deepcopy(document)
     f = Fields(date_times=['date2'])
     f.convert_call(cdocument)
     self.assertEqual(cdocument, document)
Пример #11
0
 def test_convert_call_date_time_prefixes_none(self):
     document = {
         'date': '2017-10-26T09:16:00+00:00'
     }
     cdocument = deepcopy(document)
     f = Fields(date_times=['date'])
     f.convert_call(cdocument, ['insert'])
     self.assertEqual(cdocument, document)
Пример #12
0
 def test_convert_call_date_time_prefixes_dotstring_operators6(self):
     document = {
         'update.$f.lol.o': '2017-10-26T09:16:00+00:00'
     }
     f = Fields(date_times=['update.lol'])
     f.convert_call(document, ['update'])
     self.assertEqual(document, {
         'update.$f.lol.o': '2017-10-26T09:16:00+00:00'
     })
Пример #13
0
 def test_convert_call_date_date(self):
     document = {
         'date': datetime.date(2017, 10, 26)
     }
     f = Fields(dates=['date'])
     f.convert_call(document)
     self.assertEqual(document, {
         'date': datetime.date(2017, 10, 26)
     })
Пример #14
0
 def test_convert_call_date_time_twice(self):
     document = {
         'date': '2017-10-26T09:16:00+00:00'
     }
     f = Fields(date_times=['date', 'date'])
     f.convert_call(document)
     self.assertEqual(document, {
         'date': datetime.datetime(2017, 10, 26, 9, 16, tzinfo=pytz.utc)
     })
Пример #15
0
 def test_convert_call_date_time_empty_field(self):
     document = {
         'date': '2017-10-26T09:16:00+00:00'
     }
     f = Fields(date_times=[])
     f.convert_call(document)
     self.assertEqual(document, {
         'date': '2017-10-26T09:16:00+00:00'
     })
Пример #16
0
 def test_convert_call_date_time_none(self):
     document = {
         'date': '2017-10-26T09:16:00+00:00',
         'f': '2017-10-26T09:15:00+00:00'
     }
     cdocument = deepcopy(document)
     f = Fields()
     f.convert_call(cdocument)
     self.assertEqual(cdocument, document)
Пример #17
0
    def test_datetime_conversion(self):
        tz = pytz.timezone('Pacific/Johnston')

        now_tz = datetime.datetime.now(tz)
        doc = {'createdAt': now_tz}
        f = Fields(date_times=['createdAt'])
        f.convert_call(doc)

        self.assertEqual(doc['createdAt'], now_tz)
        self.assertLess(now() - doc['createdAt'], datetime.timedelta(seconds=1))
Пример #18
0
 def test_convert_call_date_no_list(self):
     document = {
         'date': ['2017-10-26', '2017-10-26']
     }
     f = Fields(dates=['date'])
     f.convert_call(document)
     self.assertEqual(document, {
         'date': [datetime.date(2017, 10, 26),
                  datetime.date(2017, 10, 26)]
     })
Пример #19
0
 def test_convert_call_date_time_no_list(self):
     document = {
         'date': ['2017-10-26T09:16:00+00:00', '2017-10-26T09:15:00+00:00']
     }
     f = Fields(date_times=['date'])
     f.convert_call(document)
     self.assertEqual(document, {
         'date': [datetime.datetime(2017, 10, 26, 9, 16, tzinfo=pytz.utc),
                  datetime.datetime(2017, 10, 26, 9, 15, tzinfo=pytz.utc)]
     })
Пример #20
0
 def test_convert_call_date_no_conversion(self):
     document = {
         'date': '2017-10-26',
         'f': '2017-10-26'
     }
     f = Fields(dates=['date'])
     f.convert_call(document)
     self.assertEqual(document, {
         'date': datetime.date(2017, 10, 26),
         'f': '2017-10-26'
     })
Пример #21
0
 def test_convert_call_hashed3(self):
     for i in range(50):
         document = {
             'date': b'2017-10-26'
         }
         f = Fields(hashed='date')
         f.convert_call(document)
         self.assertEqual(document, {
             'date': b'2017-10-26',
             '__hashed__:date': 'OLiaieIaRIW2tk3SwD9zGAE4TGk-yxifRdI8xElZ7j8='
         })
Пример #22
0
 def test_convert_call_date_time_nested(self):
     document = {
         'date': '2017-10-26T09:16:00+00:00',
         'o': {
             'date2': '2017-9-26T09:16:00+00:00'
         }
     }
     f = Fields(date_times=['date', 'o.date2'])
     f.convert_call(document)
     self.assertEqual(document, {
         'date': datetime.datetime(2017, 10, 26, 9, 16, tzinfo=pytz.utc),
         'o': {
             'date2': datetime.datetime(2017, 9, 26, 9, 16, tzinfo=pytz.utc)
         }
     })
Пример #23
0
 def test_convert_call_date_overnested(self):
     document = {
         'date': '2017-10-26',
         'o': {
             'date2': '2017-9-26'
         }
     }
     f = Fields(dates=['o.o.date2'])
     f.convert_call(document)
     self.assertEqual(document, {
         'date': '2017-10-26',
         'o': {
             'date2': '2017-9-26'
         }
     })
Пример #24
0
 def test_convert_call_date_nested(self):
     document = {
         'date': '2017-10-26',
         'o': {
             'date2': '2017-9-26'
         }
     }
     f = Fields(dates=['date', 'o.date2'])
     f.convert_call(document)
     self.assertEqual(document, {
         'date': datetime.date(2017, 10, 26),
         'o': {
             'date2': datetime.date(2017, 9, 26)
         }
     })
Пример #25
0
 def test_convert_call_date_time_prefixes_operators_exists(self):
     document = {
         'filter': {
             'deletedAt': {
                 '$exists': False
             }
         }
     }
     f = Fields(date_times=['deletedAt'])
     f.convert_call(document, ['filter'])
     self.assertEqual(document, {
         'filter': {
             'deletedAt': {
                 '$exists': False
             }
         }
     })
Пример #26
0
 def test_convert_call_date_time_prefixes_operators_comparison(self):
     document = {
         'filter': {
             'deletedAt': {
                 '$lt': '2017-10-26T09:16:00+00:00'
             }
         }
     }
     f = Fields(date_times=['deletedAt'])
     f.convert_call(document, ['filter'])
     self.assertEqual(document, {
         'filter': {
             'deletedAt': {
                 '$lt': datetime.datetime(2017, 10, 26, 9, 16, tzinfo=pytz.utc)
             }
         }
     })
Пример #27
0
 def test_convert_call_date_time_prefixes_dotstring_operators3(self):
     document = {
         'update.$f': {
             'lol.$push': {
                 'date.$.o': '2017-10-26T09:16:00+00:00'
             }
         }
     }
     f = Fields(date_times=['update.lol.date.o'])
     f.convert_call(document, ['update'])
     self.assertEqual(document, {
         'update.$f': {
             'lol.$push': {
                 'date.$.o': datetime.datetime(2017, 10, 26, 9, 16, tzinfo=pytz.utc)
             }
         }
     })
Пример #28
0
 def test_convert_call_date_time_prefixes_dotstring_operators9(self):
     document = {
         '$set': {
             'roles': {
                 'createdAt': '2017-10-26T09:16:00+00:00'
             }
         }
     }
     f = Fields(date_times=['roles.createdAt'])
     f.convert_call(document, ['update'])
     self.assertEqual(document, {
         '$set': {
             'roles': {
                 'createdAt': '2017-10-26T09:16:00+00:00'
             }
         }
     })
Пример #29
0
 def test_convert_call_date_time4(self):
     document = {
         'update': {
             '$setOnInsert': {
                 'updatedAt': '2017-10-26T09:16:00+00:00',
                 'createdAt': '2017-10-26T09:16:00+00:00'
             }
         }
     }
     f = Fields(date_times=['updatedAt', 'createdAt'])
     f.convert_call(document, prefixes=['update'])
     self.assertEqual(document, {
         'update': {
             '$setOnInsert': {
                 'updatedAt': datetime.datetime(2017, 10, 26, 9, 16, tzinfo=pytz.utc),
                 'createdAt': datetime.datetime(2017, 10, 26, 9, 16, tzinfo=pytz.utc)
             }
         }
     })
Пример #30
0
 def test_convert_call_date_object_list(self):
     document = {
         'dates': [
             {
                 'date': '2017-10-26'
             },
             {
                 'date': '2017-10-26'
             }
         ]
     }
     f = Fields(dates=['dates.date'])
     f.convert_call(document)
     self.assertEqual(document, {
         'dates': [
             {
                 'date': datetime.date(2017, 10, 26)
             },
             {
                 'date': datetime.date(2017, 10, 26)
             }
         ]
     })