Repository: translate/pootle

Issue:
update_stores and sync_stores should produce an error if the project doesn't exist
If a non-existent project is passed to `update_stores` or `sync_stores` there is no output. I would expect an error:

```
# pootle update_stores --project=nonexistent-project
# pootle sync_stores --project=nonexistent-project
#
```


Discussion:

Resolving patch:
diff --git a/pootle/apps/pootle_app/management/commands/__init__.py b/pootle/apps/pootle_app/management/commands/__init__.py
--- a/pootle/apps/pootle_app/management/commands/__init__.py
+++ b/pootle/apps/pootle_app/management/commands/__init__.py
@@ -12,6 +12,7 @@
 from django.core.management.base import BaseCommand, CommandError
 
 from pootle.runner import set_sync_mode
+from pootle_language.models import Language
 from pootle_project.models import Project
 
 
@@ -82,6 +83,26 @@ def do_translation_project(self, tp, **options):
                              self.name, store.pootle_path)
                 self.handle_store(store, **options)
 
+    def check_projects(self, project_codes):
+        existing_projects = Project.objects.filter(
+            code__in=project_codes
+        ).values_list("code", flat=True)
+        if len(existing_projects) != len(project_codes):
+            unrecognized_projects = list(set(project_codes) -
+                                         set(existing_projects))
+            raise CommandError("Unrecognized projects: %s" %
+                               unrecognized_projects)
+
+    def check_languages(self, language_codes):
+        existing_languages = Language.objects.filter(
+            code__in=language_codes
+        ).values_list("code", flat=True)
+        if len(existing_languages) != len(language_codes):
+            unrecognized_languages = list(set(language_codes) -
+                                          set(existing_languages))
+            raise CommandError("Unrecognized languages: %s" %
+                               unrecognized_languages)
+
     def handle(self, **options):
         # adjust debug level to the verbosity option
         debug_levels = {
@@ -102,6 +123,10 @@ def handle(self, **options):
 
         self.projects = options.pop('projects', [])
         self.languages = options.pop('languages', [])
+        if self.projects:
+            self.check_projects(self.projects)
+        if self.languages:
+            self.check_languages(self.languages)
 
         # info start
         start = datetime.datetime.now()
diff --git a/pootle/apps/pootle_app/management/commands/set_filetype.py b/pootle/apps/pootle_app/management/commands/set_filetype.py
--- a/pootle/apps/pootle_app/management/commands/set_filetype.py
+++ b/pootle/apps/pootle_app/management/commands/set_filetype.py
@@ -39,14 +39,8 @@ def add_arguments(self, parser):
     def get_projects(self):
         if not self.projects:
             return Project.objects.all()
-        projects = []
-        for project in self.projects:
-            # ensure all projects are valid before proceeding
-            try:
-                projects.append(Project.objects.get(code=project))
-            except Project.DoesNotExist:
-                raise CommandError("Unrecognized project '%s'" % project)
-        return projects
+
+        return Project.objects.filter(code__in=self.projects)
 
     def get_filetype(self, name):
         try:


Test patch:
diff --git a/tests/commands/set_filetype.py b/tests/commands/set_filetype.py
--- a/tests/commands/set_filetype.py
+++ b/tests/commands/set_filetype.py
@@ -103,8 +103,3 @@ def test_cmd_set_project_filetypes_bad():
             "set_filetype",
             "--project=project0",
             "FORMAT_DOES_NOT_EXIST")
-    with pytest.raises(CommandError):
-        call_command(
-            "set_filetype",
-            "--project=PROJECT_DOES_NOT_EXIST",
-            "po")
diff --git a/tests/commands/update_stores.py b/tests/commands/update_stores.py
--- a/tests/commands/update_stores.py
+++ b/tests/commands/update_stores.py
@@ -8,7 +8,7 @@
 
 import pytest
 
-from django.core.management import call_command
+from django.core.management import CommandError, call_command
 
 
 @pytest.mark.cmd
@@ -42,3 +42,12 @@ def test_update_stores_project_tree_none(capfd, project0):
     out, err = capfd.readouterr()
     assert not out
     assert not err
+
+
+@pytest.mark.cmd
+@pytest.mark.django_db
+def test_update_stores_non_existent_lang_or_proj():
+    with pytest.raises(CommandError):
+        call_command("update_stores", "--project", "non_existent_project")
+    with pytest.raises(CommandError):
+        call_command("update_stores", "--language", "non_existent_language")