示例#1
0
 def test_forms_1(self):
     form = RawUrlForm(data=self.xml % self.xml_urls)
     self.assertTrue(form.is_valid())
     self.assertTrue(hasattr(form, 'cleaned_data'))
     self.assertEqual(
         form.cleaned_data.get('urls', ''),
         list(map(lambda x: "http://%s:80" % x, self.xml_urls)))
示例#2
0
 def get_neighbors_urls(self, url_socket, id=None):
     """ START PARSING HERE """
     messages = []
     print "URL (%s) %s" % (id, url_socket)
     try:
         burl, messages = self.validate_base_url(url_socket)
         url = "%s%s" % (burl.url_socket, reverse('api_lookupurls'))
         neighbor_file = self.get_url_as_file(url)
         form = RawUrlForm(data=neighbor_file.read())
         if form.is_valid():
             parent, created = UrlModel.objects.get_or_create(
                 url=burl.url_socket)
             url_list = form.cleaned_data.get('urls')
             for u in url_list:
                 url_model, created = UrlModel.objects.get_or_create(
                     url=u, defaults={'parent': parent})
                 cache.delete_many(
                     map(lambda x: x % (id), [
                         'error_message_url_%s',
                         'error_count_url_%s',
                     ]))
         else:
             messages = messages + form.errors
     except TransferException, e:
         messages = messages + e.messages
示例#3
0
 def test_forms_3(self):
     test_urls = ("http://192.168.0.9:80/", "localhost")
     form = RawUrlForm(data=self.xml % test_urls)
     self.assertTrue(form.is_valid())
     self.assertTrue(hasattr(form, 'cleaned_data'))
     self.assertEqual(form.cleaned_data.get('urls', ''),
                      ["http://192.168.0.9:80", "http://localhost:80"])
     self.assertEqual(form.cleaned_data.get('url_pieces'),
                      [('192.168.0.9', 80), ('localhost', 80)])
示例#4
0
 def test_forms_3(self):
     test_urls = ("http://192.168.0.9:80/","localhost")
     form = RawUrlForm(data=self.xml % test_urls)
     self.assertTrue(form.is_valid())
     self.assertTrue(hasattr(form, 'cleaned_data'))
     self.assertEqual(
         form.cleaned_data.get('urls',''), ["http://192.168.0.9:80","http://localhost:80"] )
     self.assertEqual(form.cleaned_data.get('url_pieces'),
                      [('192.168.0.9', 80), ('localhost', 80)])
示例#5
0
    def post(self, request, *args, **kwargs):

        form = RawUrlForm(data=request.raw_post_data)
        if form.is_valid():
            url_list = form.cleaned_data.get('urls')
            for u in url_list:
                url_model, created = UrlModel.objects.get_or_create(url=u, )

            num_added = len(url_list)
            xml = messagexml("Added %s Records" % (num_added))
        else:
            xml = messagexml('Error with form validation: %s' % form.errors)
            print form.errors

        status = 201
        return prepxml(etree.tostring(xml), status)
示例#6
0
 def post(self, request, *args, **kwargs):
 
     form = RawUrlForm(data=request.raw_post_data)
     if form.is_valid():
         url_list = form.cleaned_data.get('urls')
         for u in url_list:
             url_model, created = UrlModel.objects.get_or_create(url=u,)
             
         num_added = len(url_list)
         xml = messagexml("Added %s Records" % (num_added))
     else:
         xml = messagexml('Error with form validation: %s' % form.errors)
         print form.errors
     
     status=201
     return prepxml(etree.tostring(xml), status)
示例#7
0
 def get_neighbors_urls(self, url_socket, id=None):
     """ START PARSING HERE """
     messages = []
     print "URL (%s) %s" % (id, url_socket)
     try:
         burl, messages = self.validate_base_url(url_socket)
         url = "%s%s" % (burl.url_socket, reverse("api_lookupurls"))
         neighbor_file = self.get_url_as_file(url)
         form = RawUrlForm(data=neighbor_file.read())
         if form.is_valid():
             parent, created = UrlModel.objects.get_or_create(url=burl.url_socket)
             url_list = form.cleaned_data.get("urls")
             for u in url_list:
                 url_model, created = UrlModel.objects.get_or_create(url=u, defaults={"parent": parent})
                 cache.delete_many(map(lambda x: x % (id), ["error_message_url_%s", "error_count_url_%s"]))
         else:
             messages = messages + form.errors
     except TransferException, e:
         messages = messages + e.messages
示例#8
0
 def test_forms_9(self):
     form = RawUrlForm(data='<response />')
     self.assertTrue(not form.is_valid())
     self.assertTrue(not hasattr(form, 'cleaned_data'))
     self.assertEqual(len(form.errors), 1)
示例#9
0
 def test_forms_7(self):
     form = RawUrlForm(data=self.xml2 % self.xml_urls)
     self.assertTrue(not form.is_valid())
     self.assertTrue(not hasattr(form, 'cleaned_data'))
     self.assertEqual(len(form.errors), 1)
示例#10
0
 def test_forms_6(self):
     test_urls = ("http://192.1()68.0.9:80/", "local*&^@!host")
     form = RawUrlForm(data=self.xml % test_urls)
     self.assertTrue(not form.is_valid())
     self.assertTrue(not hasattr(form, 'cleaned_data'))
     self.assertEqual(len(form.errors), 1)
示例#11
0
 def test_forms_9(self):
     form = RawUrlForm(data='<response />' )
     self.assertTrue(not form.is_valid())
     self.assertTrue(not hasattr(form, 'cleaned_data'))
     self.assertEqual(len(form.errors), 1)
示例#12
0
 def test_forms_7(self):
     form = RawUrlForm(data=self.xml2 % self.xml_urls)
     self.assertTrue(not form.is_valid())
     self.assertTrue(not hasattr(form, 'cleaned_data'))
     self.assertEqual(len(form.errors), 1)
示例#13
0
 def test_forms_6(self):
     test_urls = ("http://192.1()68.0.9:80/","local*&^@!host")
     form = RawUrlForm(data=self.xml % test_urls)
     self.assertTrue(not form.is_valid())
     self.assertTrue(not hasattr(form, 'cleaned_data'))
     self.assertEqual(len(form.errors), 1)
示例#14
0
 def test_forms_1(self):
     form = RawUrlForm(data=self.xml % self.xml_urls)
     self.assertTrue(form.is_valid())
     self.assertTrue(hasattr(form, 'cleaned_data'))
     self.assertEqual(
         form.cleaned_data.get('urls',''), list(map(lambda x: "http://%s:80" % x, self.xml_urls)) )