wbnews 1.55.8__py2.py3-none-any.whl → 1.55.10rc0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,10 +22,10 @@ class EmlContentParser:
22
22
  html = self.get_html(self.message)
23
23
  return html.decode(self.encoding) if html else None
24
24
 
25
- def get_html(cls, parsed: message.Message) -> bytes | None:
25
+ def get_html(self, parsed: message.Message) -> bytes | None:
26
26
  if parsed.is_multipart():
27
27
  for item in parsed.get_payload(): # type:message.Message
28
- if html := cls.get_html(item):
28
+ if html := self.get_html(item):
29
29
  return html
30
30
  elif parsed.get_content_type() == "text/html":
31
31
  return parsed.get_payload(decode=True)
wbnews/models/news.py CHANGED
@@ -81,7 +81,8 @@ class News(ImportMixin, WBModel):
81
81
  """
82
82
  tasks = []
83
83
  for sender, task_signature in create_news_relationships.send(sender=News, instance=self):
84
- assert isinstance(task_signature, Signature), self.errors["relationship_signal"].format(sender)
84
+ if not isinstance(task_signature, Signature):
85
+ raise AssertionError(self.errors["relationship_signal"].format(sender))
85
86
  tasks.append(task_signature)
86
87
  if tasks:
87
88
  res = chord(tasks, create_relationship.s(self.id))
@@ -1,5 +1,4 @@
1
- from unittest import mock
2
- from unittest.mock import patch, PropertyMock
1
+ from unittest.mock import PropertyMock, patch
3
2
 
4
3
  import pytest
5
4
 
@@ -7,19 +6,20 @@ from wbnews.import_export.parsers.emails.utils import EmlContentParser
7
6
 
8
7
 
9
8
  class TestEmlContentParser:
10
-
11
9
  @pytest.fixture
12
10
  def content_parser(self):
13
- parser = EmlContentParser(b'')
11
+ parser = EmlContentParser(b"")
14
12
  parser.message = {"From": "main@acme.com"}
15
13
  return parser
16
14
 
17
15
  @patch.object(EmlContentParser, "text", new_callable=PropertyMock)
18
16
  def test_source_from_in_text(self, mock_text, content_parser):
19
- mock_text.return_value = "some random email content with a From field From: source name <email@test.com> and the rest of the email"
17
+ mock_text.return_value = (
18
+ "some random email content with a From field From: source name <email@test.com> and the rest of the email"
19
+ )
20
20
  assert content_parser.source == {"title": "Source Name", "endpoint": "email@test.com", "type": "EMAIL"}
21
21
 
22
22
  @patch.object(EmlContentParser, "text", new_callable=PropertyMock)
23
- def test_source_from_in_text(self, mock_text, content_parser):
23
+ def test_source_from_in_text_alt(self, mock_text, content_parser):
24
24
  mock_text.return_value = "some random email content without a From field"
25
25
  assert content_parser.source == {"title": "Acme.Com", "endpoint": "main@acme.com", "type": "EMAIL"}
@@ -1,14 +1,15 @@
1
- from datetime import timedelta, datetime, timezone
2
- from django.utils import timezone as django_timezone
1
+ from datetime import timedelta, timezone
3
2
  from unittest.mock import patch
4
3
 
5
4
  import pytest
5
+ from django.utils import timezone as django_timezone
6
+ from faker import Faker
6
7
 
7
8
  from wbnews.models import News, NewsSource
8
- from faker import Faker
9
9
 
10
10
  fake = Faker()
11
11
 
12
+
12
13
  @pytest.mark.django_db
13
14
  class TestSource:
14
15
  @pytest.mark.parametrize("news_source__title", ["source1"])
@@ -19,17 +20,19 @@ class TestSource:
19
20
  ns1 = news_source_factory.create()
20
21
  ns2 = news_source_factory.create()
21
22
 
22
- assert NewsSource.source_dict_to_model({"id": ns1.id, "identifier": ns2.identifier}) == ns1 # priority to "id"
23
- assert NewsSource.source_dict_to_model({"endpoint": ns1.endpoint, "identifier": ns2.identifier}) == ns2 # priority to "identifier"
24
- assert NewsSource.source_dict_to_model({"endpoint": ns2.endpoint}) == ns2 # exact match on endpoint
23
+ assert NewsSource.source_dict_to_model({"id": ns1.id, "identifier": ns2.identifier}) == ns1 # priority to "id"
24
+ assert (
25
+ NewsSource.source_dict_to_model({"endpoint": ns1.endpoint, "identifier": ns2.identifier}) == ns2
26
+ ) # priority to "identifier"
27
+ assert NewsSource.source_dict_to_model({"endpoint": ns2.endpoint}) == ns2 # exact match on endpoint
25
28
 
26
29
  ns1.endpoint = ".*@test.com"
27
30
  ns1.save()
28
- assert NewsSource.source_dict_to_model({"endpoint": "abc@test.com"}) == ns1 # regex match on endpoint
31
+ assert NewsSource.source_dict_to_model({"endpoint": "abc@test.com"}) == ns1 # regex match on endpoint
29
32
 
30
33
  new_source = NewsSource.source_dict_to_model({"endpoint": "abc@main_source.com", "title": "New Source"})
31
34
  assert new_source not in [ns1, ns2]
32
- assert new_source.endpoint == ".*@main_source\.com"
35
+ assert new_source.endpoint == r".*@main_source\.com"
33
36
  assert new_source.title == "New Source"
34
37
  assert new_source.author == "Main Source"
35
38
 
@@ -45,24 +48,31 @@ class TestNews:
45
48
 
46
49
  def test_get_default_guid(self):
47
50
  assert News.get_default_guid("This is a title", None) == "this-is-a-title"
48
- assert News.get_default_guid("This is a title", "http://mylink.com") == "http://mylink.com" # link takes precendence
51
+ assert (
52
+ News.get_default_guid("This is a title", "http://mylink.com") == "http://mylink.com"
53
+ ) # link takes precendence
49
54
  assert News.get_default_guid("a" * 24, None, max_length=20) == "a" * 20
50
55
 
51
56
  def test_future_news(self, news_factory):
52
57
  # ensure a future datetime always default to now
53
58
  now = django_timezone.now()
54
59
  future_news = news_factory.create(datetime=now + timedelta(days=1))
55
- assert (future_news.datetime - now).seconds < 1 # we do that to account for clock difference
60
+ assert (future_news.datetime - now).seconds < 1 # we do that to account for clock difference
56
61
 
57
62
  @patch("wbnews.models.news.detect_near_duplicates")
58
63
  def test_handle_duplicates(self, mock_fct, news_factory):
59
64
  val_date = fake.date_time(tzinfo=timezone.utc)
60
- n0 = news_factory.create(datetime=val_date - timedelta(days=1)) # we exclude this news from the duplicate search
65
+ n0 = news_factory.create(
66
+ datetime=val_date - timedelta(days=1)
67
+ ) # we exclude this news from the duplicate search
61
68
  n1 = news_factory.create(datetime=val_date)
62
69
  n2 = news_factory.create(datetime=val_date)
63
70
  n3 = news_factory.create(datetime=val_date)
64
71
 
65
- mock_fct.return_value = [n0.id, n3.id] # n0 is considered as duplicate but does not fall within the specified daterange so it will not be marked
72
+ mock_fct.return_value = [
73
+ n0.id,
74
+ n3.id,
75
+ ] # n0 is considered as duplicate but does not fall within the specified daterange so it will not be marked
66
76
  News.handle_duplicates(val_date, val_date)
67
77
 
68
78
  n3.refresh_from_db()
wbnews/utils.py CHANGED
@@ -11,7 +11,7 @@ logger = logging.getLogger("news")
11
11
 
12
12
  def _get_similarity_matrix_df(data: dict[int, str]) -> pd.DataFrame:
13
13
  # Convert texts to TF-IDF vectors
14
- ids, texts = zip(*data.items())
14
+ ids, texts = zip(*data.items(), strict=False)
15
15
  vectorizer = TfidfVectorizer()
16
16
  tfidf_matrix = vectorizer.fit_transform(texts)
17
17
  # Compute pairwise cosine similarity...
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wbnews
3
- Version: 1.55.8
3
+ Version: 1.55.10rc0
4
4
  Summary: A workbench module for managing news.
5
5
  Author-email: Christopher Wittlinger <c.wittlinger@stainly.com>
6
6
  Requires-Dist: feedparser==6.*
@@ -7,7 +7,7 @@ wbnews/serializers.py,sha256=KihExQ_GS1fNZnojryEcfU32xlTiPn-K2WGO0Zc84Cw,4732
7
7
  wbnews/signals.py,sha256=eqipwffwJnDQWUZ9VTKr5Jp-OMXLmVSNwoIsawnCKvM,192
8
8
  wbnews/tasks.py,sha256=ce9JbXKnJnf7La74h0LPwm3yrygHNe1BKZju_4m1itw,384
9
9
  wbnews/urls.py,sha256=2Gs9RGU8x6tNOLJiuG17n_ik82QVb8jlw7bU07Lk_S4,1008
10
- wbnews/utils.py,sha256=LFB9vDP4j5DK040drwHeNHK5Dl8Mf4NvDOVrjPjTXhw,1941
10
+ wbnews/utils.py,sha256=h4TdMbUL0qQ2h3o3jEpGuGwT90TWiryVRtBXc7avLW0,1955
11
11
  wbnews/filters/__init__.py,sha256=FXJcPsLQePCU-fzjpIu44Dsdu9vCckLHr0Kr-8Z_-C4,59
12
12
  wbnews/filters/news.py,sha256=dUBe9H7gvkwOmHb6roCeu9b_0mZdhnRCvaHuUGGESTA,1725
13
13
  wbnews/fixtures/wbnews.yaml,sha256=cDu1UWYwIFxz-hdivW7rxLYsNOweBm4GdN1GDsycN90,173164
@@ -19,7 +19,7 @@ wbnews/import_export/handlers/news.py,sha256=cdrtWIP3XOU8NMYZKF8VLYH5qHmPLboUm_G
19
19
  wbnews/import_export/parsers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  wbnews/import_export/parsers/emails/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  wbnews/import_export/parsers/emails/news.py,sha256=8fSgjSPuSmdfGKV1IxLMWriqGhDAG-tiZUyAgWpjZ_M,1236
22
- wbnews/import_export/parsers/emails/utils.py,sha256=cdlq1hMbVYDzhB7qyXOvZNBPBeKhKwmuSHvfW18bWxM,2205
22
+ wbnews/import_export/parsers/emails/utils.py,sha256=k7R1HZx18FKXRq10COARFgHjjBadsWe1DY3AHCrwHRs,2207
23
23
  wbnews/import_export/parsers/rss/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
24
  wbnews/import_export/parsers/rss/news.py,sha256=H89avqOU_AUAyHiIXd_tfoMbcqy67GgDQ2-ucihDpks,2076
25
25
  wbnews/locale/de/LC_MESSAGES/django.mo,sha256=M70N6el-I7EymxHLw9n773Bimbztf8s8equWa9SydBs,1283
@@ -41,18 +41,18 @@ wbnews/migrations/0013_alter_news_datetime.py,sha256=q4Gbxo25jClsv9b1kfTqBLmpPNH
41
41
  wbnews/migrations/0014_newsrelationship_unique_news_relationship.py,sha256=aZUHLMKRMaXHJrrbnV9O2ZJRDVjbpkb9NjVPB7VKVW0,1073
42
42
  wbnews/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
43
43
  wbnews/models/__init__.py,sha256=KKIcQbpCPCVNJUPJs2MtpN9Q2Wb34Qdk-C7w6AAOy7w,99
44
- wbnews/models/news.py,sha256=PJFcG5WFBkEkfnxkLLMqyCz9cLq0fkwuPlgYVyK2i44,5165
44
+ wbnews/models/news.py,sha256=yRbOpVG69yssvJPzv9bZJGMoFcb9n2uLaG2mz2j8oxM,5203
45
45
  wbnews/models/relationships.py,sha256=bcQbRa-ObS9h67pIuIrodD63RnkzbaOaRT4L6ctBoI0,1841
46
46
  wbnews/models/sources.py,sha256=N3-rBg4myeGG_stHvKiNnSoH0yS-LS_Zr_UeKPMBr5s,2629
47
47
  wbnews/models/utils.py,sha256=1JQxV4WxmmFGl7MdVtJoEeao3vnqqVwCi7mhSToaUvM,600
48
48
  wbnews/models/llm/cleaned_news.py,sha256=PA0McsgMmR0TOZUNWs55sBnsCXGbaC61VtVFbJ8vx28,2226
49
49
  wbnews/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
50
  wbnews/tests/conftest.py,sha256=UEZOYH5Av-Cqqq5t8WQCR7QJdNnajhthBPpF8AnwQjY,186
51
- wbnews/tests/test_models.py,sha256=99npnSWhqfspxizaWa5Ay4JY84ziGy64_BnKj8Tmol8,3173
51
+ wbnews/tests/test_models.py,sha256=op79cYyz9f5dX1uRBztw-E0J4HYAY8K-7cz4kBCN0qk,3278
52
52
  wbnews/tests/test_utils.py,sha256=PsyHH_F_y-Uy3mdVgDINH19bPEd1bmZT_UQ7yu87BNU,278
53
53
  wbnews/tests/tests.py,sha256=OADY-vbKZBe0bjjVEO1KNzRYAP2JA9mWkO9pZuh1TSs,280
54
54
  wbnews/tests/parsers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
55
- wbnews/tests/parsers/test_emails.py,sha256=uFg9eErF3gzyc6zULnUq-3p6O3rg1HBAlb59Lw4CWSk,1072
55
+ wbnews/tests/parsers/test_emails.py,sha256=dStdTPI7Ns1jSw5PDbDEc84FJaoNPnBHC4BskWDDMxY,1073
56
56
  wbnews/viewsets/__init__.py,sha256=2OhRiJy0MVK9TdMpFmS9x9jl_gM-CjBxUoUHlZB3_8U,531
57
57
  wbnews/viewsets/buttons.py,sha256=6m_IdRYCQgTH4mD51DUoOa8Vx1y1-2zPQydUdvL_nF4,1788
58
58
  wbnews/viewsets/display.py,sha256=fwMZLlwxHcNHM4AppwYpYTOicLD_pXaQ4QeFeIl4whk,5315
@@ -60,6 +60,6 @@ wbnews/viewsets/endpoints.py,sha256=2slGDJin_SA2heWsIaMdNTUN46FqZJvusbY1jhAaeZM,
60
60
  wbnews/viewsets/menu.py,sha256=XTShfTIykN9t7oclosPfFVb1r6o46QyglEEe1C7QCMk,979
61
61
  wbnews/viewsets/titles.py,sha256=iMyiGBMBpzng8s2ySVLqEOwueHRnAoEuc75dt9nCPjc,1367
62
62
  wbnews/viewsets/views.py,sha256=SMCDT6bJMQblyqX5cQ7X3qDe0zxTVWh1q7Aqj0fBo2Q,6795
63
- wbnews-1.55.8.dist-info/METADATA,sha256=OJtbdn_uIlBNiF-D8vM-V1lLqG__8Vx4wq2gm5e8o8M,215
64
- wbnews-1.55.8.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
65
- wbnews-1.55.8.dist-info/RECORD,,
63
+ wbnews-1.55.10rc0.dist-info/METADATA,sha256=YC09A_gCfCr-QWF6MLLeF2wvCddlQA-XKMPtF4zBVlA,219
64
+ wbnews-1.55.10rc0.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
65
+ wbnews-1.55.10rc0.dist-info/RECORD,,