예제 #1
0
 def tearDown(self):
     Notification.wait()
     del os.environ["FREPPLE_TEST"]
     if os.path.exists("workbook.xlsx"):
         os.remove("workbook.xlsx")
     translation.activate(settings.LANGUAGE_CODE)
     super().tearDown()
예제 #2
0
    def test_follow_item(self):
        user = User.objects.create_user(
            username="******",
            email="*****@*****.**",
            password="******",
        )
        user.user_permissions.add(*Permission.objects.filter(
            codename__in=("view_item", "view_supplier", "view_purchaseorder")))
        Follower(
            user=user,
            content_type=ContentType.objects.get(model="item"),
            object_pk="test item",
        ).save()
        for _ in parseCSVdata(
                Item, [["name", "category"], ["test item", "test category"]],
                user=user):
            pass
        for _ in parseCSVdata(
                Item,
            [["name", "category"], ["test item", "new test category"]],
                user=user):
            pass
        for _ in parseCSVdata(Supplier, [["name"], ["test supplier"]],
                              user=user):
            pass
        for _ in parseCSVdata(
                ItemSupplier,
            [["supplier", "item"], ["test supplier", "test item"]],
                user=user,
        ):
            pass
        for _ in parseCSVdata(
                PurchaseOrder,
            [
                ["reference", "supplier", "item", "quantity", "enddate"],
                ["PO 1", "test supplier", "test item", "10", "2020-12-31"],
            ],
                user=user,
        ):
            pass
        item = Item.objects.get(name="test item")
        Comment(
            content_object=item,
            object_repr=str(item)[:200],
            user=user,
            comment="test comment",
            type="comment",
        ).save()

        # Check what notifications we got
        Notification.wait()
        # for x in Notification.objects.all():
        #    print(x)
        self.assertEqual(Notification.objects.count(), 4)
예제 #3
0
 def tearDown(self):
     rmtree(self.datafolder)
     Notification.wait()
     del os.environ["FREPPLE_TEST"]
예제 #4
0
 def tearDown(self):
     Notification.wait()
     del os.environ["FREPPLE_TEST"]
     super().tearDown()
예제 #5
0
    def test_performance(self):
        # Admin user follows all items
        user = User.objects.get(username="******")
        Follower(
            user=user,
            content_type=ContentType.objects.get(model="item"),
            object_pk="all",
            type=
            "M",  # The test email backend doesn't send email, so we can't check it
        ).save()

        items = [["item %s" % cnt] for cnt in range(1000)]

        # Create 2 users. Each user follows all 1000 items.
        for cnt in range(2):
            u = User.objects.create_user(
                username="******" % cnt,
                email="user%s" % cnt,
                password="******",
                pk=cnt + 10,
            )
            u.user_permissions.add(*Permission.objects.filter(
                codename__in=("view_item", "view_demand")))
            for i in items:
                Follower(
                    user=u,
                    content_type=ContentType.objects.get(model="item"),
                    object_pk=i[0],
                ).save()
        self.assertEqual(User.objects.count(), 3)
        self.assertEqual(Follower.objects.count(), 2001)

        # Upload CSV data with 1000 items
        # print("start items", datetime.now())
        errors = 0
        for _ in parseCSVdata(Item, chain([["name"]], items), user=user):
            errors += 1
        self.assertEqual(Item.objects.count(), 1000)

        # Upload CSV data with 1000 customers
        # print("start customers", datetime.now())
        customers = [["customer %s" % cnt, "test"] for cnt in range(1000)]
        for _ in parseCSVdata(Customer,
                              chain([["name", "category"]], customers),
                              user=user):
            errors += 1
        self.assertEqual(Customer.objects.count(), 1000)

        # Upload CSV data with 1000 locations
        # print("start locations", datetime.now())
        locations = [["location %s" % cnt, "test"] for cnt in range(1000)]
        for _ in parseCSVdata(Location,
                              chain([["name", "category"]], locations),
                              user=user):
            errors += 1
        self.assertEqual(Location.objects.count(), 1000)

        # Upload CSV data with 1000 demands
        # print("start demands", datetime.now())
        demands = [[
            "demand %s" % cnt,
            random.choice(items)[0],
            random.choice(customers)[0],
            random.choice(locations)[0],
            1,
            "2020-01-01",
        ] for cnt in range(1000)]
        for _ in parseCSVdata(
                Demand,
                chain([[
                    "name", "item", "customer", "location", "quantity", "due"
                ]], demands),
                user=user,
        ):
            errors += 1
        self.assertEqual(Demand.objects.count(), 1000)
        self.assertEqual(errors, 4)

        # The Loading is finished now, but the notifications aren't ready yet. It takes
        # longer to process all notifications and send emails by the worker.
        #
        # The real performance test is to run with and without the followers.
        # The load process should take the same time with or without the followers.
        # The time required for the notification worker instead grows with the number of
        # followers that need to be checked.
        # print("END DATA LOAD", datetime.now())
        Notification.wait()
        # print("END NOTIFICATON WORKERS", datetime.now())

        self.assertEqual(Comment.objects.count(), 4000)
        self.assertEqual(Notification.objects.count(), 6000)
예제 #6
0
파일: tests.py 프로젝트: wujianming/frepple
 def tearDown(self):
     Notification.wait()
     del os.environ["FREPPLE_TEST"]
     if os.path.exists("workbook.xlsx"):
         os.remove("workbook.xlsx")