def test_stories(self): olegs_id = 2 oleg = User(olegs_id) oleg.blog_posts self.assertTrue(hasattr(oleg, 'blog_posts')) """ Oleg wrote the first blog post :) """ self.assertIn(1, oleg.blog_posts)
def setUp(self): self.test_settings = test_settings authorized_client = None if self.test_settings['oauth']: zachaysan = User(403022, authorize=True) authorized_client = zachaysan.authorized_client self.test_collection = Collection(383355, authorized_client=authorized_client)
def test_follow_and_unfollow_user(self): """ Normally these would be two tests but I can't guarantee execution order. """ if self.test_settings['oauth']: zachapitest = User(username="******") self.assertTrue(self.auth_zach.follow(zachapitest)) self.assertTrue(self.auth_zach.find_friend(username="******")) self.assertTrue(zachapitest.find_follower(username="******")) self.assertTrue(self.auth_zach.unfollow(zachapitest)) no_friend = self.auth_zach.find_friend(username="******") no_follower = zachapitest.find_follower(username="******") self.assertTrue(no_friend is None) self.assertTrue(no_follower is None)
def test_two_stage_oauth(self): if self.test_settings['oauth']: zachaysan = User(403022, force_fn_call=True) verify_url = zachaysan.five_hundred_px.verify_url zachaysan.initialize_authorization() # Normally, at this point, you would break this into # the section of code that the user would hit on your site # *after* they finished authorizing (so the webserver would # pick it up there) but since I don't want to run the tests # as a web server + client, I'm re-creating the lightweight # verifier app. oauth_token = zachaysan._oauth_token oauth_verifier = retrieve_oauth_verifier(oauth_token, verify_url) zachaysan.complete_authorization(oauth_verifier) self.assertTrue(zachaysan.auth)
def crawl_users(self): to_add = [] for username in self.usernames: user = User(username=username) for u in user.friends: if u.username in self.finished_usernames: continue to_add.append(u.username) for photo in user.favorites: if os.path.isfile("photos/%s.jpg" % photo.id): continue self.i += 1 if self.i > self.MAX: break self.harvest_photo(photo) self.finished_usernames.add(username) for username in to_add: self.usernames.add(username) print to_add print "here!" print self.usernames print self.finished_usernames
def get_comment_count(self): self.comment_counter = defaultdict(int) user = User(username=username) for photo in user.photos: self.analze_photo(photo)
def test_friends_is_same_object_when_after(self): evgenys_id = 1 evgeny = User(evgenys_id) zachaysan = User(username='******') friend_evgeny = self.zachaysan.find_friend(id=evgenys_id) self.assertEqual(friend_evgeny.__hash__(), evgeny.__hash__())
def test_friends_is_same_object_when_before(self): evgenys_id = 1 friend_evgeny = self.zachaysan.find_friend(id=evgenys_id) self.assertEqual(evgenys_id, friend_evgeny.id) evgeny = User(evgenys_id) self.assertEqual(friend_evgeny.__hash__(), evgeny.__hash__())
def test_init_with_username_first_then_id(self): arragorn = User(username='******') arragorn_again = User(1354783) self.assertEqual(arragorn.__hash__(), arragorn_again.__hash__())
def test_init_with_username_ensure_same_object_as_id_lookup(self): zachaysan = User(username='******') self.assertEqual(zachaysan.__hash__(), self.zachaysan.__hash__())
def test_init_with_username(self): zachaysan = User(username='******') self.assertEqual(zachaysan.id, self.zachaysan.id)
def test_list_photos_a_user_has_taken(self): paddy = User(username="******") self.assertTrue(paddy.photos.first()) self.assertEqual( paddy.find_photo(name="Llama!").category_name, "Animals")
def test_collection_pulling(self): if not self.test_settings['ignore_known_failing_tests']: evgenys_id = 1 evgeny = User(evgenys_id) self.assertTrue(evgeny.collections)
def setUp(self): self.zachaysan = User(403022) self.test_settings = test_settings if self.test_settings['oauth']: self.auth_zach = User(403022, authorize=True)