Permalink
Browse files

Fix some test issues.

  • Loading branch information...
1 parent ec41167 commit ab2d1a807d901ba0ae7874115272f85fcab8e621 @carljm carljm committed Aug 31, 2012
View
@@ -6,3 +6,4 @@ w3lib==1.2
zope.interface==4.0.1
argparse==1.2.1
cssutils==0.9.10b1
+django-inmemorystorage==0.1.1
View
@@ -11,7 +11,7 @@
from spade.vendor import add_vendor_lib
def main():
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "spade.settings.default")
+ os.environ["DJANGO_SETTINGS_MODULE"] = "spade.tests.settings"
add_vendor_lib()
args = sys.argv[1:]
if not args:
View
@@ -3,6 +3,7 @@
"""
from datetime import datetime
+
from django.db import models
@@ -38,8 +39,8 @@ def js_filename(instance, filename):
""" Models for scraper """
-class UserAgent(models.Model):
- """ A user-agent string we will use for scanning. """
+class BaseUserAgent(models.Model):
+ """Base common class for UserAgent and BatchUserAgent."""
DESKTOP = 0
MOBILE = 1
UA_TYPE_CHOICES = (
@@ -56,6 +57,14 @@ class UserAgent(models.Model):
def __unicode__(self):
return self.ua_string
+ class Meta:
+ abstract = True
+
+
+class UserAgent(BaseUserAgent):
+ """ A user-agent string we will use for scanning. """
+ pass
+
class Batch(models.Model):
""" A batch of sites scanned in one run. """
@@ -75,27 +84,16 @@ class Meta:
verbose_name_plural = u"Batches"
-class BatchUserAgent(models.Model):
- """ A user agent from a given batch """
- batch = models.ForeignKey(Batch)
-
- # The following clones the UserAgent model, so that we can retain history
- # for scan UAs while allowing the user to add/remove/modify user agents
- DESKTOP = 0
- MOBILE = 1
- UA_TYPE_CHOICES = (
- (DESKTOP, 'desktop'),
- (MOBILE, 'mobile'),
- )
+class BatchUserAgent(BaseUserAgent):
+ """
+ A user agent from a given batch.
- ua_string = models.CharField(max_length=250)
- ua_type = models.IntegerField(max_length=1,
- choices=UA_TYPE_CHOICES,
- default=DESKTOP)
- primary_ua = models.BooleanField(default=False)
+ Clones the UserAgent model, so that we can retain history for scan UAs
+ while allowing the user to add/remove/modify user agents for future
+ batches.
- def __unicode__(self):
- return self.ua_string
+ """
+ batch = models.ForeignKey(Batch)
class Meta:
unique_together = [("batch", "ua_string")]
@@ -172,7 +170,7 @@ class LinkedCSS(models.Model):
max_length=500, upload_to=css_filename)
def __unicode__(self):
- return self.raw_css.name
+ return self.url
class Meta:
verbose_name_plural = "Linked CSS"
@@ -188,7 +186,7 @@ class LinkedJS(models.Model):
max_length=500, upload_to=js_filename)
def __unicode__(self):
- return self.raw_js.name
+ return self.url
class Meta:
verbose_name_plural = "Linked JS"
@@ -225,38 +223,40 @@ class BatchData(models.Model):
batch = models.OneToOneField(Batch)
# Other metrics
- num_rules = models.IntegerField(max_length=50)
- num_properties = models.IntegerField(max_length=50)
- scanned_pages = models.IntegerField(max_length=50)
+ num_rules = models.IntegerField()
+ num_properties = models.IntegerField()
+ scanned_pages = models.IntegerField()
# Aggregate number of css issues from all scans in all user agents
- css_issues = models.IntegerField(max_length=50)
+ css_issues = models.IntegerField()
# Aggregate number of UA issues in this batch
- ua_issues = models.IntegerField(max_length=50)
+ ua_issues = models.IntegerField()
def __unicode__(self):
- return u"'Scan batch has ({0}) css issues and ({1}) ua issues".format(self.css_issues, self.ua_issues)
+ return u"'{0}' has ({1}) css issues and ({2}) ua issues".format(
+ self.batch, self.css_issues, self.ua_issues)
class SiteScanData(models.Model):
""" Aggregate data model for site scans """
sitescan = models.OneToOneField(SiteScan)
# Other metrics
- num_rules = models.IntegerField(max_length=50)
- num_properties = models.IntegerField(max_length=50)
- scanned_pages = models.IntegerField(max_length=50)
+ num_rules = models.IntegerField()
+ num_properties = models.IntegerField()
+ scanned_pages = models.IntegerField()
# Aggregate number of css issues from all scans in all user agents
- css_issues = models.IntegerField(max_length=50)
+ css_issues = models.IntegerField()
# Aggregate number of sniffing issues detected in this site scan
- ua_issues = models.IntegerField(max_length=50)
+ ua_issues = models.IntegerField()
def __unicode__(self):
- return u"'Site scanned has ({0}) css issues and ({1}) ua issues".format(self.css_issues, self.ua_issues)
+ return u"'{0}' has ({1}) css issues and ({2}) ua issues".format(
+ self.sitescan, self.css_issues, self.ua_issues)
class URLScanData(models.Model):
@@ -267,19 +267,20 @@ class URLScanData(models.Model):
urlscan = models.OneToOneField(URLScan)
# Other metrics
- num_rules = models.IntegerField(max_length=50)
- num_properties = models.IntegerField(max_length=50)
- scanned_pages = models.IntegerField(max_length=50)
+ num_rules = models.IntegerField()
+ num_properties = models.IntegerField()
+ scanned_pages = models.IntegerField()
# Aggregate css_issues from all linked css stylesheets
- css_issues = models.IntegerField(max_length=50)
+ css_issues = models.IntegerField()
# If the url scan had a user agent issue (recognized non-primary mobile ua
# but not the primary mobile ua)
- ua_issues = models.BooleanField(default=False)
+ ua_issue = models.BooleanField(default=False)
def __unicode__(self):
- return u"'URL scanned has ({0}) css issues and ({1}) ua issues".format(self.css_issues, self.ua_issues)
+ return u"'{0}' has ({1}) css issues".format(
+ self.urlscan, self.css_issues)
class URLContentData(models.Model):
@@ -290,28 +291,28 @@ class URLContentData(models.Model):
urlcontent = models.OneToOneField(URLContent)
# Other metrics
- num_rules = models.IntegerField(max_length=50)
- num_properties = models.IntegerField(max_length=50)
+ num_rules = models.IntegerField()
+ num_properties = models.IntegerField()
# Aggregate css_issues from all linked css stylesheets
css_issues = models.IntegerField(max_length=50)
def __unicode__(self):
- return u"'Page scanned with user agent '{0}' has ({1}) css issues".format(
- self.urlcontent.user_agent, self.css_issues)
+ return u"{0} has ({1}) css issues".format(
+ self.urlcontent, self.css_issues)
class LinkedCSSData(models.Model):
""" Aggregate data model for linked css stylesheet """
linked_css = models.OneToOneField(LinkedCSS)
# These seem to be useful statistics to collect that we can drill down to
- num_rules = models.IntegerField(max_length=50)
- num_properties = models.IntegerField(max_length=50)
+ num_rules = models.IntegerField()
+ num_properties = models.IntegerField()
# Number of places where a rule used a prefixed property but no moz prefix
- css_issues = models.IntegerField(max_length=50)
+ css_issues = models.IntegerField()
def __unicode__(self):
- return u"'Linked CSS stylesheet has ({0}) css issues".format(
- self.css_issues)
+ return u"'{0}' has ({1}) css issues".format(
+ self.linked_css, self.css_issues)
@@ -1,15 +1,16 @@
# Factories for testing objects
-import factory
-
from datetime import datetime
-from django.utils.timezone import utc
from hashlib import sha256
+
+from django.core.files.uploadedfile import SimpleUploadedFile
+from django.utils.timezone import utc
+import factory
+
from spade.model import models
MOCK_DATE = datetime(2012, 6, 29, 21, 10, 24, 10848, tzinfo=utc)
-MOCK_CSS_URL = (u"http://www.sammyliu.com/wp-content/themes/polaroid-perfect/"
- u"style.css")
-MOCK_JS_URL = u"http://code.jquery.com/jquery-1.7.2.min.js"
+MOCK_CSS_URL = u"http://example.com/test.css"
+MOCK_JS_URL = u"http://example.com/test.js"
class BatchFactory(factory.Factory):
@@ -54,7 +55,8 @@ class URLContentFactory(factory.Factory):
FACTORY_FOR = models.URLContent
url_scan = factory.SubFactory(URLScanFactory)
user_agent = factory.SubFactory(BatchUserAgentFactory)
- raw_markup = u"<html>hello world</html>"
+ raw_markup = SimpleUploadedFile(
+ "test.html", "<html>hello world</html>", "text/html")
headers = u""
@@ -64,7 +66,7 @@ class LinkedCSSFactory(factory.Factory):
batch = factory.SubFactory(BatchFactory)
url = MOCK_CSS_URL
url_hash = sha256(MOCK_CSS_URL).hexdigest()
- raw_css = u"body{color:#000}"
+ raw_css = SimpleUploadedFile("test.css", "body{color:#000}", "text/css")
class LinkedJSFactory(factory.Factory):
@@ -73,7 +75,8 @@ class LinkedJSFactory(factory.Factory):
batch = factory.SubFactory(BatchFactory)
url = MOCK_JS_URL
url_hash = sha256(MOCK_JS_URL).hexdigest()
- raw_js = u"document.write('hello world')"
+ raw_js = SimpleUploadedFile(
+ "test.js", "document.write('hello world')", "application/javascript")
class CSSRuleFactory(factory.Factory):
@@ -128,7 +131,7 @@ class URLScanDataFactory(factory.Factory):
num_properties = 10
scanned_pages = 1
css_issues = 3
- ua_issues = 1
+ ua_issue = True
class URLContentDataFactory(factory.Factory):
@@ -17,4 +17,4 @@ def test_unicode():
batchdata = factories.BatchDataFactory.create(
batch=batch, num_rules=1, num_properties=2, css_issues=3, ua_issues=4)
- assert unicode(batchdata) == u"'Scan batch has (3) css issues and (4) ua issues"
+ assert unicode(batchdata) == u"''Batch started at 2012-06-29 21:10:24.010848+00:00' has (3) css issues and (4) ua issues"
@@ -6,9 +6,9 @@
def test_css_unicode():
linkedcss = factories.LinkedCSSFactory()
- assert unicode(linkedcss) == u"body{color:#000}"
+ assert unicode(linkedcss) == u"http://example.com/test.css"
def test_js_unicode():
linkedjs = factories.LinkedJSFactory()
- assert unicode(linkedjs) == u"document.write('hello world')"
+ assert unicode(linkedjs) == u"http://example.com/test.js"
@@ -12,5 +12,5 @@ def test_unicode():
linkedcss_data = factories.LinkedCSSDataFactory.create(
linked_css=linkedcss, css_issues=3)
- assert unicode(linkedcss_data) == u"'Linked CSS stylesheet has (3) css issues"
+ assert unicode(linkedcss_data) == u"'http://example.com/test.css' has (3) css issues"
@@ -13,5 +13,5 @@ def test_unicode():
css_issues=3,
ua_issues=4)
- assert unicode(sitescan_data) == (u"'Site scanned has (3) css issues and"
- u" (4) ua issues")
+ assert unicode(sitescan_data) == (
+ u"'http://www.mozilla.com' has (3) css issues and (4) ua issues")
@@ -14,5 +14,5 @@ def test_unicode():
urlcontent_data = factories.URLContentDataFactory.create(
urlcontent=urlcontent, css_issues=3)
- assert unicode(urlcontent_data) == (u"'Page scanned with user agent "
- u"'Mozilla / 5.0' has (3) css issues")
+ assert unicode(urlcontent_data) == (
+ u"'http://www.mozilla.com' scanned with 'Mozilla / 5.0' has (3) css issues")
@@ -10,8 +10,8 @@ def test_unicode():
urlscan = factories.URLScanFactory.create()
urlscan_data = factories.URLScanDataFactory.create(urlscan=urlscan,
- css_issues=3,
- ua_issues=4)
+ css_issues=3,
+ ua_issue=True)
- assert unicode(urlscan_data) == (u"'URL scanned has (3) css issues and (4) "
- u"ua issues")
+ assert unicode(urlscan_data) == (
+ u"'http://www.mozilla.com' has (3) css issues")
View
@@ -0,0 +1,3 @@
+from spade.settings.default import *
+
+DEFAULT_FILE_STORAGE = "inmemorystorage.InMemoryStorage"
Oops, something went wrong.

0 comments on commit ab2d1a8

Please sign in to comment.