Commits

Anonymous committed 4bc9ce8

Fixed tests, cleaned up.

  • Participants
  • Parent commits 89b8d57

Comments (0)

Files changed (4)

packageindex/tests.py

 from packageindex.views import search_packages
 
 class PackageIndexViews(TestCase):
+
     def test_search_packages(self):
 
+        STPackage.objects.create(
+                        name="Powershell",
+                        slug="XXX",
+                        description="XXX",
+                        checkout_url="XXX",
+                        repository_type=0,
+                        resource_type=0,
+                        )
         c = Client()
         response = c.get("/packages/search/?search=powershell")
-
         self.assertEquals(len(response.context["results_list"]), 1)
 
-
     def test_add_package_fail(self):
-
+        # TODO: We need to bypass recaptcha to do this.
         c = Client()
         response = c.post("/packages/add/", {
                                             "name": "one",
                                             "checkout_url": "two",
-                                            "description":"three"
+                                            "description":"three",
+                                            "recaptcha_response_field":"dummy",
+                                            "recaptcha_challenge_field":"dummy",
                                             }
                         )
-        self.assertFormError(response=response, form="form", field="checkout_url", errors="Cannot locate rss feed.")
+        self.assertFormError(response=response, form="form", field="checkout_url", errors="Cannot find repository.")
         self.assertTemplateUsed(response=response, template_name="add_package.html")
 
     def test_add_package_succeed(self):
         c = Client()
         response = c.post("/packages/add/", {
                                             "name": "stindex",
-                                            "checkout_url": "http://bitbucket.org/guillermooo/stindex/rss",
-                                            "description":"Some text here."
+                                            "checkout_url": "http://bitbucket.org/guillermooo/sublimemodelines",
+                                            "description":"Some text here.",
+                                            "recaptcha_response_field":"dummy",
+                                            "recaptcha_challenge_field":"dummy",
                                             },
                             follow=True
                         )
 
-        self.assertRedirects(response=response, expected_url="/packages/stindex/")
+        self.assertRedirects(response=response, expected_url="/packages/sublimemodelines/")

packageindex/views.py

 from django.db.models import Q
 from recaptcha.client import captcha
 import socket
+from django.conf import settings
 
 def show_all_packages(request, page):
     live_packages = {
     if request.method == 'GET':
         search_term = request.GET.get('search', '')
 
-        print search_term
-        print request.GET
-
         # TODO: look for search term in NAME and DESCRIPTION
         return object_list(request,
                     queryset=STPackage.objects.filter(
     if request.method == 'POST':
         form = forms.AddPackageForm(data=request.POST)
 
+
         recaptcha_user_response = request.POST["recaptcha_response_field"]
         recaptcha_challenge_field = request.POST["recaptcha_challenge_field"]
-        r = captcha.submit(recaptcha_challenge_field,
-                            recaptcha_user_response,
-                            "6LcsL70SAAAAAHjpjI0R8ydYuYzQGv9Y2KTb-T4c",
-                            socket.gethostbyname(request.META["SERVER_NAME"]))
+        passed_recaptcha = True
+        if settings.RECAPTCHA_ENABLED:
+            r = captcha.submit(recaptcha_challenge_field,
+                                recaptcha_user_response,
+                                "6LcsL70SAAAAAHjpjI0R8ydYuYzQGv9Y2KTb-T4c",
+                                socket.gethostbyname(request.META["SERVER_NAME"]))
+            passed_recaptcha = r.is_valid
 
-        if r.is_valid:
+        if passed_recaptcha:
             if form.is_valid():
                 p = form.save(commit=False)
                 # We've cached repo_data after passing validation. This data is

repoparsers/parsers.py

 
 def parse(url):
     parsed = urlparse.urlparse(url)
-    if parsed.hostname.lower() == 'bitbucket.org':
-        data = parsed.path.split("/")
-        return get_repo_by_name(data[1], data[2])
-    elif parsed.hostname.lower() == "github.com":
-        data = parsed.path.split("/")
-        return get_git_repo_by_name(data[1], data[2])
-    else:
+
+    try:
+        if parsed.hostname.lower() == 'bitbucket.org':
+            data = parsed.path.split("/")
+            return get_repo_by_name(data[1], data[2])
+        elif parsed.hostname.lower() == "github.com":
+            data = parsed.path.split("/")
+            return get_git_repo_by_name(data[1], data[2])
+        else:
+            return {}
+    except AttributeError:
         return {}
 
 if __name__ == '__main__':
 import os
 
 DEBUG = False
+RECAPTCHA_ENABLED = True # Set to False when TESTING!
 TEMPLATE_DEBUG = DEBUG
 
 ADMINS = (