コード例 #1
0
ファイル: test_tasks.py プロジェクト: BongoHive/magriculture
    def test_query_function_works(self):
        # Creating Crop Receipts
        days_4 = utils.create_crop_receipt(created_at=datetime.today() - timedelta(days=4))
        days_2 = utils.create_crop_receipt(created_at=datetime.today() - timedelta(days=2))

        crop_receipts = CropReceipt.objects.all()

        # Assert that all reconciled is false
        (self.assertEqual(obj.reconciled, False) for obj in crop_receipts)
        tasks.query_crop_receipt_for_old_crops.delay(3)

        days_4 = CropReceipt.objects.get(id=days_4.id)
        self.assertEqual(days_4.reconciled, True)

        days_2 = CropReceipt.objects.get(id=days_2.id)
        self.assertEqual(days_2.reconciled, False)

        # Getting and testing the messages
        message = Message.objects.all()
        self.assertEqual(message.count(), 1)

        crop = days_4.crop.name
        remaining = days_4.remaining_inventory()
        self.assertEqual(message[0].content,
                         (_("Sorry but %(remaining)s %(units)s of %(crop)s have not been sold") %
                          {'remaining': remaining, 'units': days_4.unit.name, 'crop': crop}))
        self.assertEqual(message[0].recipient,
                         days_4.farmer.actor)
        self.assertEqual(message[0].sender,
                         days_4.agent.actor)
コード例 #2
0
ファイル: test_tasks.py プロジェクト: BongoHive/magriculture
 def test_export_conversation_messages_unsorted(self):
     receipt = utils.create_crop_receipt(amount=150)
     transaction = utils.create_transaction(receipt)
     transaction2 = utils.create_transaction(receipt)
     self.assertEqual(receipt.id, transaction.crop_receipt.id)
     field_names = ['id', 'crop_receipt__farmer__actor__name', 'crop_receipt__farmer__gender',
                 'created_at', 'crop_receipt__crop', 'crop_receipt__unit', 'amount',
                 'total', 'crop_receipt__market', 'crop_receipt__agent__actor__name',
                 'crop_receipt__agent__actor__gender']
     labels = ['TransactionID', 'Farmer Name', 'Gender', 'Transaction Date', 'Crop', 'Unit', 'No of Units',
                 'Total Price Achieved', 'Market', 'Agent', 'Agent Gender']
     queryset = [transaction, transaction2]
     export_transactions(field_names, labels, queryset, self.user)
     [email] = mail.outbox
     self.assertEqual(
         email.recipients(), [self.user.email])
     self.assertEqual("LimaLinks Transaction export snapshot", email.subject)
     self.assertEqual("Please find the transactions attached.", email.body)
     fp = self.get_zipfile_attachment(
         email, 'transactions-export.zip', 'transactions-export.csv')
     reader = csv.DictReader(fp)
     transaction_ids = [row['TransactionID'] for row in reader]
     self.assertEqual(
         set(transaction_ids),
         set(['1','2']))
コード例 #3
0
ファイル: test_tasks.py プロジェクト: BongoHive/magriculture
    def test_query_function_works_with_day_is_one(self):
        # Creating Crop Receipts
        days_4 = utils.create_crop_receipt(created_at=datetime.today() - timedelta(days=4))
        days_2 = utils.create_crop_receipt(created_at=datetime.today() - timedelta(days=2))

        crop_receipts = CropReceipt.objects.all()

        # Assert that all reconciled is false
        (self.assertEqual(obj.reconciled, False) for obj in crop_receipts)
        tasks.query_crop_receipt_for_old_crops.delay(1)

        days_4 = CropReceipt.objects.get(id=days_4.id)
        self.assertEqual(days_4.reconciled, True)

        days_2 = CropReceipt.objects.get(id=days_2.id)
        self.assertEqual(days_2.reconciled, True)

        # Getting and testing the messages
        message = Message.objects.all()
        self.assertEqual(message.count(), 2)
コード例 #4
0
ファイル: test_tasks.py プロジェクト: BongoHive/magriculture
    def test_check_inventory_left_works(self):
        days_4 = utils.create_crop_receipt(created_at=datetime.today() - timedelta(days=4))
        self.assertEqual(days_4.reconciled, False)

        tasks.check_inventory_left(days_4)
        days_4 = CropReceipt.objects.get(id=days_4.id)
        self.assertEqual(days_4.reconciled, True)

        # Getting and testing the messages
        message = Message.objects.all()
        self.assertEqual(message.count(), 1)

        crop = days_4.crop.name
        # Not sure why the following is being cast into an integer in the message
        remaining = int(days_4.remaining_inventory())
        self.assertEqual(message[0].content,
                         (_("Sorry but %(remaining)s %(units)s of %(crop)s have not been sold") %
                          {'remaining': remaining, 'units': days_4.unit.name, 'crop': crop}))
        self.assertEqual(message[0].recipient,
                         days_4.farmer.actor)
        self.assertEqual(message[0].sender,
                         days_4.agent.actor)