Merge pull request #2074 from bookwyrm-social/pylint-tests-dir

Include test files in pylint
This commit is contained in:
Mouse Reeve 2022-04-08 14:39:44 -07:00 committed by GitHub
commit 300eea3b94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 56 additions and 33 deletions

View file

@ -24,5 +24,5 @@ jobs:
pip install pylint pip install pylint
- name: Analysing the code with pylint - name: Analysing the code with pylint
run: | run: |
pylint bookwyrm/ --ignore=migrations,tests --disable=E1101,E1135,E1136,R0903,R0901,R0902,W0707,W0511,W0406,R0401,R0801 pylint bookwyrm/ --ignore=migrations --disable=E1101,E1135,E1136,R0903,R0901,R0902,W0707,W0511,W0406,R0401,R0801

View file

@ -125,7 +125,7 @@ class ActivitypubFieldMixin:
"""model_field_name to activitypubFieldName""" """model_field_name to activitypubFieldName"""
if self.activitypub_field: if self.activitypub_field:
return self.activitypub_field return self.activitypub_field
name = self.name.split(".")[-1] name = self.name.rsplit(".", maxsplit=1)[-1]
components = name.split("_") components = name.split("_")
return components[0] + "".join(x.title() for x in components[1:]) return components[0] + "".join(x.title() for x in components[1:])

View file

@ -1 +1,2 @@
from . import * """ import ALL the tests """
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -4,7 +4,10 @@ from bookwyrm import models
class Author(TestCase): class Author(TestCase):
"""serialize author tests"""
def setUp(self): def setUp(self):
"""initial data"""
self.book = models.Edition.objects.create( self.book = models.Edition.objects.create(
title="Example Edition", title="Example Edition",
remote_id="https://example.com/book/1", remote_id="https://example.com/book/1",
@ -16,6 +19,7 @@ class Author(TestCase):
) )
def test_serialize_model(self): def test_serialize_model(self):
"""check presense of author fields"""
activity = self.author.to_activity() activity = self.author.to_activity()
self.assertEqual(activity["id"], self.author.remote_id) self.assertEqual(activity["id"], self.author.remote_id)
self.assertIsInstance(activity["aliases"], list) self.assertIsInstance(activity["aliases"], list)

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -38,7 +38,7 @@ class BaseModel(TestCase):
def test_remote_id(self): def test_remote_id(self):
"""these should be generated""" """these should be generated"""
self.test_model.id = 1 self.test_model.id = 1 # pylint: disable=invalid-name
expected = self.test_model.get_remote_id() expected = self.test_model.get_remote_id()
self.assertEqual(expected, f"https://{DOMAIN}/bookwyrmtestmodel/1") self.assertEqual(expected, f"https://{DOMAIN}/bookwyrmtestmodel/1")

View file

@ -162,6 +162,7 @@ class ModelFields(TestCase):
class TestActivity(ActivityObject): class TestActivity(ActivityObject):
"""real simple mock""" """real simple mock"""
# pylint: disable=invalid-name
to: List[str] to: List[str]
cc: List[str] cc: List[str]
id: str = "http://hi.com" id: str = "http://hi.com"

View file

@ -17,7 +17,7 @@ class User(TestCase):
"bookwyrm.activitystreams.populate_stream_task.delay" "bookwyrm.activitystreams.populate_stream_task.delay"
), patch("bookwyrm.lists_stream.populate_lists_task.delay"): ), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
self.user = models.User.objects.create_user( self.user = models.User.objects.create_user(
"mouse@%s" % DOMAIN, f"mouse@{DOMAIN}",
"mouse@mouse.mouse", "mouse@mouse.mouse",
"mouseword", "mouseword",
local=True, local=True,
@ -107,7 +107,7 @@ class User(TestCase):
def test_get_or_create_remote_server(self): def test_get_or_create_remote_server(self):
responses.add( responses.add(
responses.GET, responses.GET,
"https://%s/.well-known/nodeinfo" % DOMAIN, f"https://{DOMAIN}/.well-known/nodeinfo",
json={"links": [{"href": "http://www.example.com"}, {}]}, json={"links": [{"href": "http://www.example.com"}, {}]},
) )
responses.add( responses.add(
@ -124,7 +124,7 @@ class User(TestCase):
@responses.activate @responses.activate
def test_get_or_create_remote_server_no_wellknown(self): def test_get_or_create_remote_server_no_wellknown(self):
responses.add( responses.add(
responses.GET, "https://%s/.well-known/nodeinfo" % DOMAIN, status=404 responses.GET, f"https://{DOMAIN}/.well-known/nodeinfo", status=404
) )
server = models.user.get_or_create_remote_server(DOMAIN) server = models.user.get_or_create_remote_server(DOMAIN)
@ -136,7 +136,7 @@ class User(TestCase):
def test_get_or_create_remote_server_no_links(self): def test_get_or_create_remote_server_no_links(self):
responses.add( responses.add(
responses.GET, responses.GET,
"https://%s/.well-known/nodeinfo" % DOMAIN, f"https://{DOMAIN}/.well-known/nodeinfo",
json={"links": [{"href": "http://www.example.com"}, {}]}, json={"links": [{"href": "http://www.example.com"}, {}]},
) )
responses.add(responses.GET, "http://www.example.com", status=404) responses.add(responses.GET, "http://www.example.com", status=404)
@ -150,7 +150,7 @@ class User(TestCase):
def test_get_or_create_remote_server_unknown_format(self): def test_get_or_create_remote_server_unknown_format(self):
responses.add( responses.add(
responses.GET, responses.GET,
"https://%s/.well-known/nodeinfo" % DOMAIN, f"https://{DOMAIN}/.well-known/nodeinfo",
json={"links": [{"href": "http://www.example.com"}, {}]}, json={"links": [{"href": "http://www.example.com"}, {}]},
) )
responses.add(responses.GET, "http://www.example.com", json={"fish": "salmon"}) responses.add(responses.GET, "http://www.example.com", json={"fish": "salmon"})

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -64,8 +64,8 @@ class Signature(TestCase):
def send(self, signature, now, data, digest): def send(self, signature, now, data, digest):
"""test request""" """test request"""
c = Client() client = Client()
return c.post( return client.post(
urlsplit(self.rat.inbox).path, urlsplit(self.rat.inbox).path,
data=data, data=data,
content_type="application/json", content_type="application/json",

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -61,7 +61,7 @@ class InboxActivities(TestCase):
self.assertEqual(models.Notification.objects.count(), 0) self.assertEqual(models.Notification.objects.count(), 0)
activity = { activity = {
"type": "Announce", "type": "Announce",
"id": "%s/boost" % self.status.remote_id, "id": f"{self.status.remote_id}/boost",
"actor": self.remote_user.remote_id, "actor": self.remote_user.remote_id,
"object": self.status.remote_id, "object": self.status.remote_id,
"to": ["https://www.w3.org/ns/activitystreams#public"], "to": ["https://www.w3.org/ns/activitystreams#public"],
@ -94,7 +94,7 @@ class InboxActivities(TestCase):
self.assertEqual(models.Notification.objects.count(), 0) self.assertEqual(models.Notification.objects.count(), 0)
activity = { activity = {
"type": "Announce", "type": "Announce",
"id": "%s/boost" % self.status.remote_id, "id": f"{self.status.remote_id}/boost",
"actor": self.remote_user.remote_id, "actor": self.remote_user.remote_id,
"object": "https://remote.com/status/1", "object": "https://remote.com/status/1",
"to": ["https://www.w3.org/ns/activitystreams#public"], "to": ["https://www.w3.org/ns/activitystreams#public"],

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -1 +1,2 @@
from . import * # pylint: disable=missing-module-docstring
from . import * # pylint: disable=import-self

View file

@ -66,7 +66,7 @@ class AuthorViews(TestCase):
def test_author_page_edition_author(self): def test_author_page_edition_author(self):
"""there are so many views, this just makes sure it LOADS""" """there are so many views, this just makes sure it LOADS"""
view = views.Author.as_view() view = views.Author.as_view()
another_book = models.Edition.objects.create( models.Edition.objects.create(
title="Example Edition", title="Example Edition",
remote_id="https://example.com/book/1", remote_id="https://example.com/book/1",
parent_work=self.work, parent_work=self.work,

View file

@ -139,7 +139,7 @@ class ViewsHelpers(TestCase):
} }
responses.add( responses.add(
responses.GET, responses.GET,
"https://example.com/.well-known/webfinger?resource=acct:%s" % username, f"https://example.com/.well-known/webfinger?resource=acct:{username}",
json=wellknown, json=wellknown,
status=200, status=200,
) )

View file

@ -83,7 +83,7 @@ class UserViews(TestCase):
def test_user_page_domain(self): def test_user_page_domain(self):
"""when the user domain has dashes in it""" """when the user domain has dashes in it"""
with patch("bookwyrm.models.user.set_remote_server"): with patch("bookwyrm.models.user.set_remote_server"):
self.remote_user = models.User.objects.create_user( models.User.objects.create_user(
"nutria", "nutria",
"", "",
"nutriaword", "nutriaword",