-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add trademark search and alert system
Fixes #1025 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/OWASP-BLT/BLT/issues/1025?shareId=XXXX-XXXX-XXXX-XXXX).
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import requests | ||
from django.core.management.base import BaseCommand | ||
from django.core.mail import send_mail | ||
from website.models import Company, Domain | ||
from website.utils import search_uspto_database, send_email_alert | ||
|
||
class Command(BaseCommand): | ||
help = "Search the USPTO database for trademarks and alert companies if their brand name is at risk" | ||
|
||
def handle(self, *args, **options): | ||
companies = Company.objects.all() | ||
for company in companies: | ||
domains = Domain.objects.filter(company=company) | ||
for domain in domains: | ||
search_terms = [company.name, domain.name] | ||
for term in search_terms: | ||
results = search_uspto_database(term) | ||
if results: | ||
send_email_alert(company, results) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import unittest | ||
from unittest.mock import patch, MagicMock | ||
from django.core.management import call_command | ||
from django.core.mail import send_mail | ||
from website.models import Company, Domain | ||
from website.utils import search_uspto_database, send_email_alert | ||
|
||
class SearchTrademarksCommandTest(unittest.TestCase): | ||
|
||
@patch('website.utils.search_uspto_database') | ||
@patch('website.utils.send_email_alert') | ||
def test_handle(self, mock_send_email_alert, mock_search_uspto_database): | ||
# Setup mock data | ||
company = Company(name="TestCompany", email="[email protected]") | ||
domain = Domain(name="testdomain", company=company) | ||
company.save() | ||
domain.save() | ||
|
||
mock_search_uspto_database.return_value = [{"trademark": "TestTrademark"}] | ||
|
||
# Call the management command | ||
call_command('search_trademarks') | ||
|
||
# Assertions | ||
mock_search_uspto_database.assert_called_with("TestCompany") | ||
mock_search_uspto_database.assert_called_with("testdomain") | ||
mock_send_email_alert.assert_called_with(company, [{"trademark": "TestTrademark"}]) | ||
|
||
class UtilsTest(unittest.TestCase): | ||
|
||
@patch('requests.get') | ||
def test_search_uspto_database(self, mock_get): | ||
mock_response = MagicMock() | ||
mock_response.status_code = 200 | ||
mock_response.json.return_value = {"results": "test"} | ||
mock_get.return_value = mock_response | ||
|
||
result = search_uspto_database("test") | ||
self.assertEqual(result, {"results": "test"}) | ||
|
||
@patch('django.core.mail.send_mail') | ||
def test_send_email_alert(self, mock_send_mail): | ||
company = Company(name="TestCompany", email="[email protected]") | ||
results = {"results": "test"} | ||
|
||
send_email_alert(company, results) | ||
mock_send_mail.assert_called_with( | ||
"Trademark Alert for TestCompany", | ||
"Potential trademark matches found:\n\n{'results': 'test'}", | ||
"[email protected]", | ||
["[email protected]"] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters