class NonArtistTest(unittest.TestCase): def setUp(self): self.short_url_non = 'flexboogie' self.uid_non = '8840037' # basic page getting self.M = MyspaceScrape(uid = self.uid_non) self.M.get_page() self.M.get_uid() self.M.is_artist() def test_get_nice_url(self): url = self.M.get_nice_url_non_artist() assert url == 'flexboogie', 'clean url is wrong: '+str(url) def test_get_stats_non_artist(self): self.M.get_stats_non_artist() self.M.serialize() graph = mopy.exportRDFGraph(self.M.mi) for row in graph.query('''SELECT ?age where { ?x <http://purl.org/ontology/myspace#age> ?age } '''): age = row[0] print age assert int(age)>98, 'wrong age ' + str(age) for row in graph.query('''SELECT ?gender where { ?x <http://xmlns.com/foaf/0.1/gender> ?gender . } '''): gender = row[0] assert gender == 'male' , 'wrong gender '+ str(gender) for row in graph.query('''SELECT ?loc ?reg ?co where { ?x <http://purl.org/ontology/myspace#locality> ?loc . ?x <http://purl.org/ontology/myspace#region> ?reg . ?x <http://purl.org/ontology/myspace#country> ?co . } '''): loc = row[0] #print loc reg=row[1] #print reg co = row[2] #print co assert loc == 'SAINT LOUIS' , 'wrong locality '+str(loc) assert reg == 'Missouri' , 'wrong region '+str(reg) assert co == 'US' , 'wrong country '+str(co) for row in graph.query('SELECT ?totf where { ?x <http://purl.org/ontology/myspace#totalFriends> ?totf } '): totf = row[0] assert int(totf)>2000 , 'wrong number of friends '+str(totf) def test_get_image_non_artist(self): img = self.M.get_image_non_artist() # just check it looks vaguely like an image url assert img.startswith('http://') and (img.endswith('.jpg') or img.endswith('.gif')), 'does not look like an image url: '+str(img) def test_get_friends(self): self.M.get_friends_non_artist() self.M.serialize() graph = mopy.exportRDFGraph(self.M.mi) friends = [] for row in graph.query('''SELECT ?friends WHERE { ?s <http://purl.org/ontology/myspace#topFriend> ?friends } '''): friend = '%s' % row friends.append(friend) assert len(friends)>4 , 'too few friends found - some kind of problem in .get_friends_non_artist()'
def default(self, uid): if uid.endswith(".rdf"): # serve the data cherrypy.response.headers["Content-Type"] = "application/rdf+xml; charset=UTF-8;" M = MyspaceScrape(uid=uid.rsplit(".rdf")[0]) M.run() if SPARQL_ENABLED: try: M.insert_sparql() except Exception, err: print "ERROR insert_sparql() failed" + err return M.serialize()
class ArtistTest(unittest.TestCase): def setUp(self): self.short_url_artist = 'kurtisrandom' self.uid_artist = '30650288' self.M = MyspaceScrape(uid=self.uid_artist) self.M.get_page() self.M.get_uid() self.M.is_artist() def test_get_nice_url(self): url = self.M.get_nice_url() assert url == 'kurtisrandom', 'clean url is wrong: '+str(url) def test_get_image(self): img = self.M.get_image() # just check it looks vaguely like an image url assert img.startswith('http://') and img.endswith('.jpg'), 'does not look like an image url: '+str(img) def test_get_genres(self): genres = self.M.get_genres() gnames = [] for genre in genres: gnames.append(genre.name.pop()) gnames.sort() assert gnames == ['Experimental', 'Hip Hop', 'R&B'], 'wrong genre names ' +str(gnames) def test_get_friends(self): self.M.get_friends() self.M.serialize() graph = self.M.graph friends=[] for row in graph.query('''SELECT ?friends WHERE { ?s <http://purl.org/ontology/myspace#topFriend> ?friends } '''): friend = '%s' % row friends.append(friend) friends.sort() assert friends == [u'http://dbtune.org/myspace/7shotscreamers', u'http://dbtune.org/myspace/Dawit7', u'http://dbtune.org/myspace/dbaad', u'http://dbtune.org/myspace/dbirghenthal', u'http://dbtune.org/myspace/djthumpasaurus', u'http://dbtune.org/myspace/duplicateband', u'http://dbtune.org/myspace/flexboogie', u'http://dbtune.org/myspace/fliplynch', u'http://dbtune.org/myspace/serpientesmsn', u'http://dbtune.org/myspace/speedballband', u'http://dbtune.org/myspace/thelegendjamesbrown', u'http://dbtune.org/myspace/uid/30642042'] , 'wrong friends list '+str(friends) def test_get_stats(self): self.M.get_stats() self.M.serialize() graph = self.M.graph #graph = mopy.exportRDFGraph(self.M.mi) # raw country and city text tCountry = 'United Kingdom' tCity = 'London,' for row in graph.query('''SELECT ?loc ?co where { ?x <http://purl.org/ontology/myspace#locality> ?loc . ?x <http://purl.org/ontology/myspace#country> ?co . } '''): loc = row[0] #print loc co = row[1] #print co assert loc == 'London' , 'wrong locality '+ str(loc) assert co == 'United Kingdom' , 'wrong country '+ str(co) # check based near for row in graph.query('''select ?based where { ?x <http://xmlns.com/foaf/0.1/based_near> ?based } '''): based = row[0] assert str(based) == 'http://sws.geonames.org/2635167/', 'wrong based_near: '+ str(based) # total friends count totf = -1 for row in graph.query('SELECT ?totf where { ?x <http://purl.org/ontology/myspace#totalFriends> ?totf } '): totf = row[0] assert int(totf)>190 , 'wrong number of total friends '+str(totf) views = -1 for row in graph.query('SELECT ?views WHERE { ?x <http://purl.org/ontology/myspace#profileViews> ?views } '): views = row[0] assert views != -1 , 'faild to get profile views: ' + str(views)