Repository: fidals/shopelectro

Issue:
Убери категорию из фида
Из фида gm.yml - убирай категорию https://www.shopelectro.ru/catalog/categories/usiliteli-zvuka-dlia-slaboslyshashchikh/
Убрать только из этого фида. 


Discussion:
seems we already have list for excluded staff - `15 mins`

Resolving patch:
diff --git a/shopelectro/management/commands/price.py b/shopelectro/management/commands/price.py
--- a/shopelectro/management/commands/price.py
+++ b/shopelectro/management/commands/price.py
@@ -1,3 +1,4 @@
+from collections import defaultdict
 import os
 
 from django.conf import settings
@@ -28,6 +29,10 @@ class Command(BaseCommand):
         'Радиоприёмники', 'Фонари', 'Отвертки', 'Весы электронные портативные',
     ]
 
+    IGNORED_CATEGORIES_BY_TARGET = defaultdict(list, {
+        'GM': ['Усилители звука для слабослышащих'],
+    })
+
     def create_prices(self):
         for target in self.TARGETS.items():
             self.generate_yml(*target)
@@ -71,6 +76,7 @@ def filter_categories(utm):
             categories_to_exclude = (
                 Category.objects
                 .filter(name__in=cls.IGNORED_CATEGORIES)
+                .filter(name__in=cls.IGNORED_CATEGORIES_BY_TARGET[utm])
                 .get_descendants(include_self=True)
             )
 


Test patch:
diff --git a/shopelectro/tests/tests_commands.py b/shopelectro/tests/tests_commands.py
--- a/shopelectro/tests/tests_commands.py
+++ b/shopelectro/tests/tests_commands.py
@@ -3,11 +3,13 @@
 
 Note: tests running pretty long.
 """
+from collections import defaultdict
 import glob
 import os
 import random
 import unittest
 import uuid
+from unittest import mock
 from xml.etree import ElementTree
 
 from django.conf import settings
@@ -135,7 +137,7 @@ class GeneratePrices(TestCase):
 
     @classmethod
     def setUpTestData(cls):
-        call_command('price')
+        cls.call_command_patched('price')
         super(GeneratePrices, cls).setUpTestData()
 
     @classmethod
@@ -144,6 +146,17 @@ def tearDownClass(cls):
             os.remove(cls.get_price_file_path(file_name))
         super(GeneratePrices, cls).tearDownClass()
 
+    @classmethod
+    def call_command_patched(self, name):
+        with mock.patch(
+            'shopelectro.management.commands.price.Command.IGNORED_CATEGORIES_BY_TARGET',
+            new_callable=mock.PropertyMock
+        ) as target:
+            target.return_value = defaultdict(list, {
+                'GM': ['Category #1 of #Category #0 of #Category #1']
+            })
+            call_command(name)
+
     @staticmethod
     def get_price_file_path(filename):
         return os.path.join(settings.ASSETS_DIR, filename)
@@ -185,6 +198,22 @@ def test_categories_in_yandex_price(self):
             Category.objects.get_categories_tree_with_pictures().count()
         )
 
+    def test_categories_excluded_by_utm(self):
+        def find_category(categories, name):
+            for category in categories:
+                if category.text == name:
+                    return category
+            return None
+        excluded_name = 'Category #1 of #Category #0 of #Category #1'
+        categories_node = self.get_price_categories_node('gm.yml')
+
+        self.assertFalse(
+            find_category(
+                categories=categories_node.findall('category'),
+                name=excluded_name
+            )
+        )
+
     def test_products_in_price(self):
         products_in_price = self.get_price_offers_node('priceru.xml')
         self.assertEqual(len(products_in_price), Product.objects.count())