def test_int_date_time_field_update_time_set_value(self): now = time_util.now() self.simple_txn.update_time = time_util.now() self.assertEqual(now.int_timestamp, self.simple_txn.update_time.int_timestamp) self.assertIsInstance(self.simple_txn.update_time, DateTime)
def setUp(self): self.now = time_util.now() self.simple_txn, _ = Transaction.objects.get_or_create( symbol='a', price=1000, amount=100, transaction_time=time_util.now().subtract(days=10))
def pre_save(self, model_instance, add): if self.auto_now or (self.auto_now_add and add): now = time_util.now() setattr(model_instance, self.attname, now) return now return super().pre_save(model_instance, add)
def test_int_date_time_field_update_time_value(self): current = time_util.now() self.assertIsNotNone(self.simple_txn.update_time) self.assertLess(self.simple_txn.update_time, current) self.simple_txn.symbol = 'b' self.simple_txn.save() self.assertGreaterEqual(self.simple_txn.update_time, current)
def test_int_date_time_field_default_value(self): now = time_util.now() txn, _ = Transaction.objects.get_or_create( symbol='x', price=99, amount=3, ) self.assertAlmostEqual(now.int_timestamp, txn.transaction_time.int_timestamp, delta=10)
def init_portfolio(self): # add a few deposits Transaction.objects.get_or_create( symbol=DEPOSIT_SYMBOL, price=self.fake.random.randint(30000, 100000), amount=1, transaction_time=time_util.now().subtract(days=40), ) Transaction.objects.get_or_create( symbol=DEPOSIT_SYMBOL, price=self.fake.random.randint(30000, 100000), amount=1, transaction_time=time_util.now().subtract( days=self.fake.pyint(0, 30)), ) buys = [ Transaction.objects.get_or_create( symbol=self.fake.tld().upper(), price=self.fake.random.randint(2000, 30000), amount=self.fake.random.randint(100, 1000), fee=self.fake.random.randint(1000, 5000), transaction_time=time_util.now().subtract( days=self.fake.pyint(0, 30)), )[0] for _ in range(0, 10) ] for buy in buys: for i in range(0, self.fake.random.randint(0, 2)): holding = Holding.objects.get(symbol=buy.symbol) if holding.amount > 0: Transaction.objects.get_or_create( symbol=buy.symbol, type=TransactionType.SELL, price=self.fake.pyint(2000, 30000), amount=(self.fake.pyint(1, holding.amount)), fee=self.fake.pyint(1000, 5000), transaction_time=min( time_util.now(), buy.transaction_time.add( days=self.fake.pyint(0, 10))), )