示例#1
0
    def test_caps(self):

        cat = PartCategory(self.api, 6)
        self.assertEqual(cat.name, "Transceivers")
        parts = cat.getParts()

        n_parts = len(parts)

        for p in parts:
            self.assertEqual(p.category, cat.pk)

        # Create some new parts
        for i in range(10):

            name = f"Part_{cat.pk}_{n_parts + i}"

            prt = Part.create(
                self.api, {
                    "category": cat.pk,
                    "name": name,
                    "description": "A new part in this category",
                })

            self.assertIsNotNone(prt)

            self.assertEqual(prt.name, name)

        parts = cat.getParts()

        self.assertEqual(len(parts), n_parts + 10)
示例#2
0
    def test_part_delete(self):
        """
        Test we can create and delete a Part instance via the API
        """

        n = len(Part.list(self.api))

        # Create a new part
        # We do not specify 'active' value so it will default to True
        p = Part.create(
            self.api, {
                'name': 'Delete Me',
                'description': 'Not long for this world!',
                'category': 1,
            })

        self.assertIsNotNone(p)
        self.assertIsNotNone(p.pk)

        self.assertEqual(len(Part.list(self.api)), n + 1)

        # Cannot delete - part is 'active'!
        with self.assertRaises(requests.exceptions.HTTPError) as ar:
            response = p.delete()

        self.assertIn("is active: cannot delete", str(ar.exception))

        p.save(data={'active': False})
        response = p.delete()
        self.assertEqual(response.status_code, 204)

        # And check that the part has indeed been deleted
        self.assertEqual(len(Part.list(self.api)), n)
示例#3
0
    def test_part_list(self):
        """
        Check that we can list Part objects,
        and apply certain filters
        """

        parts = Part.list(self.api)
        self.assertTrue(len(parts) >= 19)

        parts = Part.list(self.api, category=5)

        n = len(parts)

        for i in range(5):
            prt = Part.create(
                self.api, {
                    "category": 5,
                    "name": f"Special Part {n+i}",
                    "description": "A new part in this category!",
                })

            self.assertEqual(prt.category, 5)
            cat = prt.getCategory()
            self.assertEqual(cat.pk, 5)

            parts = cat.getParts()

            self.assertGreaterEqual(len(parts), i + 1)
示例#4
0
def create_part(category_id: int,
                name: str,
                description: str,
                revision: str,
                image: str,
                keywords=None) -> int:
    ''' Create InvenTree part '''
    global inventree_api

    part = Part.create(
        inventree_api, {
            'name': name,
            'description': description,
            'category': category_id,
            'keywords': keywords,
            'revision': revision,
            'active': True,
            'virtual': False,
            'component': True,
            'purchaseable': True,
        })

    if part:
        return part.pk
    else:
        return 0
示例#5
0
    def test_supplier_part_create(self):
        """
        Test that we can create SupplierPart objects via the API
        """

        supplier = company.Company(self.api, 1)

        # Find a purchaseable part
        parts = Part.list(self.api, purchasable=True)

        if len(parts) > 0:
            prt = parts[0]
        else:
            prt = Part.create(
                self.api, {
                    'name': 'My purchaseable part',
                    'description':
                    'A purchasenable part we can use to make a SupplierPart',
                    'category': 1,
                    'purchaseable': True
                })

        n = len(company.SupplierPart.list(self.api))

        supplier_part = company.SupplierPart.create(self.api, {
            'supplier': supplier.pk,
            'SKU': f'SKU_TEST_{n}',
            'part': prt.pk,
        })

        self.assertIsNotNone(supplier_part)
        self.assertTrue(supplier_part.part, prt.pk)

        self.assertEqual(len(company.SupplierPart.list(self.api)), n + 1)
示例#6
0
    def test_default_values(self):
        """
        Test that the DRF framework will correctly insert the default values
        """

        n = len(Part.list(self.api))

        # Create a part without specifying 'active' and 'virtual' fields
        p = Part.create(
            self.api, {
                'name': f"Part_{n}_default_test",
                'category': 1,
                'description': "Some part thingy",
            })

        self.assertEqual(p.active, True)
        self.assertEqual(p.virtual, False)

        # Set both to false
        p = Part.create(
            self.api, {
                'name': f"Part_{n}_default_test_2",
                'category': 1,
                'description': 'Setting fields to false',
                'active': False,
                'virtual': False,
            })

        self.assertFalse(p.active)
        self.assertFalse(p.virtual)

        # Set both to true
        p = Part.create(
            self.api, {
                'name': f"Part_{n}_default_test_3",
                'category': 1,
                'description': 'Setting fields to true',
                'active': True,
                'virtual': True,
            })

        self.assertTrue(p.active)
        self.assertTrue(p.virtual)
def createITPart(part,ITCat):
    print("create part %s cat %s" % (part,ITCat.name))
    if len(part.description)==0:
        part.description=part.name
    np = Part.create(api, {
        'name' : part.name,
        'description' : part.description,
        'category' : ITCat.pk,
        'active' : True,
        'virtual' : False,
        'IPN' : part.IPN
    })
    return np
def create_inventree_part(dkpart: DigiPart):
    category = find_category()
    possible_parts = Part.list(API, name=dkpart.name, description=dkpart.description)
    if len(possible_parts) > 0:
        part_names = [p.name.lower() for p in possible_parts]
        if dkpart.name.lower() in part_names:
            print("Part already exists")
            return -1
    part = Part.create(API, {
        'name': dkpart.name,
        'description': dkpart.description,
        'category': category.pk,
        'active': True,
        'virtual': False,
        'component': True,
        'purchaseable': 1
        })
    upload_picture(dkpart, part)
    return part
    def test_internal_price_create(self):
        """
        Tests the ability to create an internal price
        """
        p = Part.create(self.api, {
            'name': 'Test Part',
            'description': 'Test Part',
            'category': 1,
            'revision': 1,
            'active': True,
        })

        self.assertIsNotNone(p)
        self.assertIsNotNone(p.pk)

        ip = InternalPrice.create(self.api, {
            'part': p.pk,
            'quantity': 1,
            'price': '1.00'
        })

        self.assertIsNotNone(ip)
示例#10
0
category = 6

packages = [
    '0402',
    '0603',
    '0805',
]

values = [
    # '100pF',
    '100nF',
    '1uF',
    '10uF',
]

for package in packages:
    for value in values:
        name = f"C_{value}_{package}"
        description = f"{value} in {package} SMD package"
        keywords = "cap smd ceramic"

        Part.create(api,
                    data={
                        'name': name,
                        'category': category,
                        'description': description,
                        'keywords': keywords,
                        'purchaseable': True,
                    })