Add PEP8-naming extension for flake

- Enforcing python naming checks
This commit is contained in:
Oliver Walters 2020-11-12 21:53:04 +11:00
parent 47cbf3071d
commit ae7fbd6112
22 changed files with 84 additions and 78 deletions

View File

@ -27,8 +27,7 @@ class APITests(APITestCase):
def setUp(self): def setUp(self):
# Create a user (but do not log in!) # Create a user (but do not log in!)
User = get_user_model() get_user_model().objects.create_user(self.username, 'user@email.com', self.password)
User.objects.create_user(self.username, 'user@email.com', self.password)
def basicAuth(self): def basicAuth(self):
# Use basic authentication # Use basic authentication

View File

@ -16,8 +16,7 @@ class ViewTests(TestCase):
def setUp(self): def setUp(self):
# Create a user # Create a user
User = get_user_model() get_user_model().objects.create_user(self.username, 'user@email.com', self.password)
User.objects.create_user(self.username, 'user@email.com', self.password)
self.client.login(username=self.username, password=self.password) self.client.login(username=self.username, password=self.password)

View File

@ -24,8 +24,8 @@ class BarcodeAPITest(APITestCase):
def setUp(self): def setUp(self):
# Create a user for auth # Create a user for auth
User = get_user_model() user = get_user_model()
User.objects.create_user('testuser', 'test@testing.com', 'password') user.objects.create_user('testuser', 'test@testing.com', 'password')
self.client.login(username='testuser', password='password') self.client.login(username='testuser', password='password')

View File

@ -267,17 +267,17 @@ class BuildTest(TestCase):
# New stock items should have been created! # New stock items should have been created!
self.assertEqual(StockItem.objects.count(), 4) self.assertEqual(StockItem.objects.count(), 4)
A = StockItem.objects.get(pk=self.stock_1_1.pk) a = StockItem.objects.get(pk=self.stock_1_1.pk)
# This stock item has been depleted! # This stock item has been depleted!
with self.assertRaises(StockItem.DoesNotExist): with self.assertRaises(StockItem.DoesNotExist):
StockItem.objects.get(pk=self.stock_1_2.pk) StockItem.objects.get(pk=self.stock_1_2.pk)
C = StockItem.objects.get(pk=self.stock_2_1.pk) c = StockItem.objects.get(pk=self.stock_2_1.pk)
# Stock should have been subtracted from the original items # Stock should have been subtracted from the original items
self.assertEqual(A.quantity, 900) self.assertEqual(a.quantity, 900)
self.assertEqual(C.quantity, 4500) self.assertEqual(c.quantity, 4500)
# And 10 new stock items created for the build output # And 10 new stock items created for the build output
outputs = StockItem.objects.filter(build=self.build) outputs = StockItem.objects.filter(build=self.build)

View File

@ -28,10 +28,10 @@ class BuildTestSimple(TestCase):
def setUp(self): def setUp(self):
# Create a user for auth # Create a user for auth
User = get_user_model() user = get_user_model()
User.objects.create_user('testuser', 'test@testing.com', 'password') user.objects.create_user('testuser', 'test@testing.com', 'password')
self.user = User.objects.get(username='testuser') self.user = user.objects.get(username='testuser')
g = Group.objects.create(name='builders') g = Group.objects.create(name='builders')
self.user.groups.add(g) self.user.groups.add(g)
@ -109,11 +109,11 @@ class TestBuildAPI(APITestCase):
def setUp(self): def setUp(self):
# Create a user for auth # Create a user for auth
User = get_user_model() user = get_user_model()
user = User.objects.create_user('testuser', 'test@testing.com', 'password') self.user = user.objects.create_user('testuser', 'test@testing.com', 'password')
g = Group.objects.create(name='builders') g = Group.objects.create(name='builders')
user.groups.add(g) self.user.groups.add(g)
for rule in g.rule_sets.all(): for rule in g.rule_sets.all():
if rule.name == 'build': if rule.name == 'build':
@ -185,11 +185,11 @@ class TestBuildViews(TestCase):
super().setUp() super().setUp()
# Create a user # Create a user
User = get_user_model() user = get_user_model()
user = User.objects.create_user('username', 'user@email.com', 'password') self.user = user.objects.create_user('username', 'user@email.com', 'password')
g = Group.objects.create(name='builders') g = Group.objects.create(name='builders')
user.groups.add(g) self.user.groups.add(g)
for rule in g.rule_sets.all(): for rule in g.rule_sets.all():
if rule.name == 'build': if rule.name == 'build':

View File

@ -18,9 +18,9 @@ class SettingsTest(TestCase):
def setUp(self): def setUp(self):
User = get_user_model() user = get_user_model()
self.user = User.objects.create_user('username', 'user@email.com', 'password') self.user = user.objects.create_user('username', 'user@email.com', 'password')
self.user.is_staff = True self.user.is_staff = True
self.user.save() self.user.save()

View File

@ -15,8 +15,8 @@ class CompanyTest(APITestCase):
def setUp(self): def setUp(self):
# Create a user for auth # Create a user for auth
User = get_user_model() user = get_user_model()
self.user = User.objects.create_user('testuser', 'test@testing.com', 'password') self.user = user.objects.create_user('testuser', 'test@testing.com', 'password')
perms = [ perms = [
'view_company', 'view_company',

View File

@ -27,8 +27,9 @@ class CompanyViewTestBase(TestCase):
super().setUp() super().setUp()
# Create a user # Create a user
User = get_user_model() user = get_user_model()
self.user = User.objects.create_user(
self.user = user.objects.create_user(
username='username', username='username',
email='user@email.com', email='user@email.com',
password='password' password='password'

View File

@ -23,8 +23,7 @@ class OrderTest(APITestCase):
def setUp(self): def setUp(self):
# Create a user for auth # Create a user for auth
User = get_user_model() get_user_model().objects.create_user('testuser', 'test@testing.com', 'password')
User.objects.create_user('testuser', 'test@testing.com', 'password')
self.client.login(username='testuser', password='password') self.client.login(username='testuser', password='password')
def doGet(self, url, options=''): def doGet(self, url, options=''):

View File

@ -120,12 +120,12 @@ class SalesOrderTest(TestCase):
# There should now be 4 stock items # There should now be 4 stock items
self.assertEqual(StockItem.objects.count(), 4) self.assertEqual(StockItem.objects.count(), 4)
Sa = StockItem.objects.get(pk=self.Sa.pk) sa = StockItem.objects.get(pk=self.Sa.pk)
Sb = StockItem.objects.get(pk=self.Sb.pk) sb = StockItem.objects.get(pk=self.Sb.pk)
# 25 units subtracted from each of the original items # 25 units subtracted from each of the original items
self.assertEqual(Sa.quantity, 75) self.assertEqual(sa.quantity, 75)
self.assertEqual(Sb.quantity, 175) self.assertEqual(sb.quantity, 175)
# And 2 items created which are associated with the order # And 2 items created which are associated with the order
outputs = StockItem.objects.filter(sales_order=self.order) outputs = StockItem.objects.filter(sales_order=self.order)
@ -134,8 +134,8 @@ class SalesOrderTest(TestCase):
for item in outputs.all(): for item in outputs.all():
self.assertEqual(item.quantity, 25) self.assertEqual(item.quantity, 25)
self.assertEqual(Sa.sales_order, None) self.assertEqual(sa.sales_order, None)
self.assertEqual(Sb.sales_order, None) self.assertEqual(sb.sales_order, None)
# And no allocations # And no allocations
self.assertEqual(SalesOrderAllocation.objects.count(), 0) self.assertEqual(SalesOrderAllocation.objects.count(), 0)

View File

@ -32,8 +32,7 @@ class OrderViewTestCase(TestCase):
super().setUp() super().setUp()
# Create a user # Create a user
User = get_user_model() user = get_user_model().objects.create_user('username', 'user@email.com', 'password')
user = User.objects.create_user('username', 'user@email.com', 'password')
# Ensure that the user has the correct permissions! # Ensure that the user has the correct permissions!
g = Group.objects.create(name='orders') g = Group.objects.create(name='orders')

View File

@ -29,8 +29,9 @@ class PartAPITest(APITestCase):
def setUp(self): def setUp(self):
# Create a user for auth # Create a user for auth
User = get_user_model() user = get_user_model()
self.user = User.objects.create_user(
self.user = user.objects.create_user(
username='testuser', username='testuser',
email='test@testing.com', email='test@testing.com',
password='password' password='password'
@ -269,8 +270,9 @@ class PartAPIAggregationTest(APITestCase):
def setUp(self): def setUp(self):
# Create a user for auth # Create a user for auth
User = get_user_model() user = get_user_model()
User.objects.create_user('testuser', 'test@testing.com', 'password')
user.objects.create_user('testuser', 'test@testing.com', 'password')
self.client.login(username='testuser', password='password') self.client.login(username='testuser', password='password')

View File

@ -165,14 +165,14 @@ class CategoryTest(TestCase):
self.assert_equal(p.get_default_location().pathstring, 'Office/Drawer_1') self.assert_equal(p.get_default_location().pathstring, 'Office/Drawer_1')
# Any part under electronics should default to 'Home' # Any part under electronics should default to 'Home'
R1 = Part.objects.get(name='R_2K2_0805') r1 = Part.objects.get(name='R_2K2_0805')
self.assertIsNone(R1.default_location) self.assertIsNone(r1.default_location)
self.assertEqual(R1.get_default_location().name, 'Home') self.assertEqual(r1.get_default_location().name, 'Home')
# But one part has a default_location set # But one part has a default_location set
R2 = Part.objects.get(name='R_4K7_0603') r2 = Part.objects.get(name='R_4K7_0603')
self.assertEqual(R2.get_default_location().name, 'Bathroom') self.assertEqual(r2.get_default_location().name, 'Bathroom')
# And one part should have no default location at all # And one part should have no default location at all
W = Part.objects.get(name='Widget') w = Part.objects.get(name='Widget')
self.assertIsNone(W.get_default_location()) self.assertIsNone(w.get_default_location())

View File

@ -54,10 +54,10 @@ class PartTest(TestCase):
] ]
def setUp(self): def setUp(self):
self.R1 = Part.objects.get(name='R_2K2_0805') self.r1 = Part.objects.get(name='R_2K2_0805')
self.R2 = Part.objects.get(name='R_4K7_0603') self.r2 = Part.objects.get(name='R_4K7_0603')
self.C1 = Part.objects.get(name='C_22N_0805') self.c1 = Part.objects.get(name='C_22N_0805')
Part.objects.rebuild() Part.objects.rebuild()
@ -78,18 +78,18 @@ class PartTest(TestCase):
self.assertEqual(str(p), "BOB | Bob | A2 - Can we build it?") self.assertEqual(str(p), "BOB | Bob | A2 - Can we build it?")
def test_metadata(self): def test_metadata(self):
self.assertEqual(self.R1.name, 'R_2K2_0805') self.assertEqual(self.r1.name, 'R_2K2_0805')
self.assertEqual(self.R1.get_absolute_url(), '/part/3/') self.assertEqual(self.r1.get_absolute_url(), '/part/3/')
def test_category(self): def test_category(self):
self.assertEqual(str(self.C1.category), 'Electronics/Capacitors - Capacitors') self.assertEqual(str(self.c1.category), 'Electronics/Capacitors - Capacitors')
orphan = Part.objects.get(name='Orphan') orphan = Part.objects.get(name='Orphan')
self.assertIsNone(orphan.category) self.assertIsNone(orphan.category)
self.assertEqual(orphan.category_path, '') self.assertEqual(orphan.category_path, '')
def test_rename_img(self): def test_rename_img(self):
img = rename_part_image(self.R1, 'hello.png') img = rename_part_image(self.r1, 'hello.png')
self.assertEqual(img, os.path.join('part_images', 'hello.png')) self.assertEqual(img, os.path.join('part_images', 'hello.png'))
def test_stock(self): def test_stock(self):
@ -100,12 +100,12 @@ class PartTest(TestCase):
self.assertEqual(r.available_stock, 0) self.assertEqual(r.available_stock, 0)
def test_barcode(self): def test_barcode(self):
barcode = self.R1.format_barcode() barcode = self.r1.format_barcode()
self.assertIn('InvenTree', barcode) self.assertIn('InvenTree', barcode)
self.assertIn(self.R1.name, barcode) self.assertIn(self.r1.name, barcode)
def test_copy(self): def test_copy(self):
self.R2.deep_copy(self.R1, image=True, bom=True) self.r2.deep_copy(self.r1, image=True, bom=True)
def test_match_names(self): def test_match_names(self):
@ -181,9 +181,9 @@ class PartSettingsTest(TestCase):
def setUp(self): def setUp(self):
# Create a user for auth # Create a user for auth
User = get_user_model() user = get_user_model()
self.user = User.objects.create_user( self.user = user.objects.create_user(
username='testuser', username='testuser',
email='test@testing.com', email='test@testing.com',
password='password', password='password',

View File

@ -23,8 +23,9 @@ class PartViewTestCase(TestCase):
super().setUp() super().setUp()
# Create a user # Create a user
User = get_user_model() user = get_user_model()
self.user = User.objects.create_user(
self.user = user.objects.create_user(
username='username', username='username',
email='user@email.com', email='user@email.com',
password='password' password='password'

View File

@ -617,10 +617,10 @@ class StockList(generics.ListCreateAPIView):
queryset = queryset.exclude(quantity__lte=0) queryset = queryset.exclude(quantity__lte=0)
# Filter by internal part number # Filter by internal part number
IPN = params.get('IPN', None) ipn = params.get('IPN', None)
if IPN is not None: if ipn is not None:
queryset = queryset.filter(part__IPN=IPN) queryset = queryset.filter(part__IPN=ipn)
# Does the client wish to filter by the Part ID? # Does the client wish to filter by the Part ID?
part_id = params.get('part', None) part_id = params.get('part', None)

View File

@ -621,12 +621,12 @@ class StockItem(MPTTModel):
return self.installedItemCount() > 0 return self.installedItemCount() > 0
@transaction.atomic @transaction.atomic
def installStockItem(self, otherItem, quantity, user, notes): def installStockItem(self, other_item, quantity, user, notes):
""" """
Install another stock item into this stock item. Install another stock item into this stock item.
Args Args
otherItem: The stock item to install into this stock item other_item: The stock item to install into this stock item
quantity: The quantity of stock to install quantity: The quantity of stock to install
user: The user performing the operation user: The user performing the operation
notes: Any notes associated with the operation notes: Any notes associated with the operation
@ -637,10 +637,10 @@ class StockItem(MPTTModel):
return False return False
# If the quantity is less than the stock item, split the stock! # If the quantity is less than the stock item, split the stock!
stock_item = otherItem.splitStock(quantity, None, user) stock_item = other_item.splitStock(quantity, None, user)
if stock_item is None: if stock_item is None:
stock_item = otherItem stock_item = other_item
# Assign the other stock item into this one # Assign the other stock item into this one
stock_item.belongs_to = self stock_item.belongs_to = self

View File

@ -22,8 +22,9 @@ class StockAPITestCase(APITestCase):
def setUp(self): def setUp(self):
# Create a user for auth # Create a user for auth
User = get_user_model() user = get_user_model()
self.user = User.objects.create_user('testuser', 'test@testing.com', 'password')
self.user = user.objects.create_user('testuser', 'test@testing.com', 'password')
# Add the necessary permissions to the user # Add the necessary permissions to the user
perms = [ perms = [

View File

@ -23,8 +23,9 @@ class StockViewTestCase(TestCase):
super().setUp() super().setUp()
# Create a user # Create a user
User = get_user_model() user = get_user_model()
self.user = User.objects.create_user(
self.user = user.objects.create_user(
username='username', username='username',
email='user@email.com', email='user@email.com',
password='password' password='password'

View File

@ -38,12 +38,12 @@ class StockTest(TestCase):
self.drawer3 = StockLocation.objects.get(name='Drawer_3') self.drawer3 = StockLocation.objects.get(name='Drawer_3')
# Create a user # Create a user
User = get_user_model() user = get_user_model()
User.objects.create_user('username', 'user@email.com', 'password') user.objects.create_user('username', 'user@email.com', 'password')
self.client.login(username='username', password='password') self.client.login(username='username', password='password')
self.user = User.objects.get(username='username') self.user = user.objects.get(username='username')
# Ensure the MPTT objects are correctly rebuild # Ensure the MPTT objects are correctly rebuild
Part.objects.rebuild() Part.objects.rebuild()
@ -221,21 +221,21 @@ class StockTest(TestCase):
def test_split_stock(self): def test_split_stock(self):
# Split the 1234 x 2K2 resistors in Drawer_1 # Split the 1234 x 2K2 resistors in Drawer_1
N = StockItem.objects.filter(part=3).count() n = StockItem.objects.filter(part=3).count()
stock = StockItem.objects.get(id=1234) stock = StockItem.objects.get(id=1234)
stock.splitStock(1000, None, self.user) stock.splitStock(1000, None, self.user)
self.assertEqual(stock.quantity, 234) self.assertEqual(stock.quantity, 234)
# There should be a new stock item too! # There should be a new stock item too!
self.assertEqual(StockItem.objects.filter(part=3).count(), N + 1) self.assertEqual(StockItem.objects.filter(part=3).count(), n + 1)
# Try to split a negative quantity # Try to split a negative quantity
stock.splitStock(-10, None, self.user) stock.splitStock(-10, None, self.user)
self.assertEqual(StockItem.objects.filter(part=3).count(), N + 1) self.assertEqual(StockItem.objects.filter(part=3).count(), n + 1)
stock.splitStock(stock.quantity, None, self.user) stock.splitStock(stock.quantity, None, self.user)
self.assertEqual(StockItem.objects.filter(part=3).count(), N + 1) self.assertEqual(StockItem.objects.filter(part=3).count(), n + 1)
def test_stocktake(self): def test_stocktake(self):
# Perform stocktake # Perform stocktake

View File

@ -18,6 +18,7 @@ django-import-export==2.0.0 # Data import / export for admin interface
django-cleanup==4.0.0 # Manage deletion of old / unused uploaded files django-cleanup==4.0.0 # Manage deletion of old / unused uploaded files
django-qr-code==1.2.0 # Generate QR codes django-qr-code==1.2.0 # Generate QR codes
flake8==3.8.3 # PEP checking flake8==3.8.3 # PEP checking
pep8-naming==0.11.1 # PEP naming convention extension
coverage==5.3 # Unit test coverage coverage==5.3 # Unit test coverage
coveralls==2.1.2 # Coveralls linking (for Travis) coveralls==2.1.2 # Coveralls linking (for Travis)
rapidfuzz==0.7.6 # Fuzzy string matching rapidfuzz==0.7.6 # Fuzzy string matching

View File

@ -7,5 +7,8 @@ ignore =
E501, E722, E501, E722,
# - C901 - function is too complex # - C901 - function is too complex
C901, C901,
# - N802 - function name should be lowercase (In the future, we should conform to this!)
N802,
N812,
exclude = .git,__pycache__,*/migrations/*,*/lib/*,*/bin/*,*/media/*,*/static/*,*ci_*.py* exclude = .git,__pycache__,*/migrations/*,*/lib/*,*/bin/*,*/media/*,*/static/*,*ci_*.py*
max-complexity = 20 max-complexity = 20