test_profile.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. from base import BaseTestCase, Profile
  2. from parameterized import parameterized
  3. profiles = [
  4. ['mobile_test', 'Test account',
  5. 'Test Account. test test Testing username with @mobile_test_2 and a #hashtag',
  6. 'San Francisco, CA', 'example.com/foobar', 'Joined October 2009', '97'],
  7. ['mobile_test_2', 'mobile test 2', '', '', '', 'Joined January 2011', '13']
  8. ]
  9. verified = [['jack'], ['elonmusk']]
  10. protected = [
  11. ['mobile_test_7', 'mobile test 7', ''],
  12. ['Poop', 'Randy', 'Social media fanatic.']
  13. ]
  14. invalid = [['thisprofiledoesntexist']]
  15. malformed = [
  16. ['${userId}'],
  17. ['$%7BuserId%7D'], # URL encoded version
  18. ['%'], # Percent sign is invalid
  19. ['user@name'],
  20. ['user.name'],
  21. ['user-name'],
  22. ['user$name'],
  23. ['user{name}'],
  24. ['user name'], # space
  25. ]
  26. banner_image = [
  27. ['mobile_test', 'profile_banners%2F82135242%2F1384108037%2F1500x500']
  28. ]
  29. # (user_id, expected_username) — resolving a numeric id to a profile (issue #1433)
  30. id_redirects = [
  31. ['12', 'jack'],
  32. ['44196397', 'elonmusk']
  33. ]
  34. class ProfileTest(BaseTestCase):
  35. @parameterized.expand(profiles)
  36. def test_data(self, username, fullname, bio, location, website, joinDate, mediaCount):
  37. self.open_nitter(username)
  38. self.assert_exact_text(fullname, Profile.fullname)
  39. self.assert_exact_text(f'@{username}', Profile.username)
  40. tests = [
  41. (bio, Profile.bio),
  42. (location, Profile.location),
  43. (website, Profile.website),
  44. (joinDate, Profile.joinDate),
  45. (mediaCount + " Photos and videos", Profile.mediaCount)
  46. ]
  47. for text, selector in tests:
  48. if len(text) > 0:
  49. self.assert_exact_text(text, selector)
  50. else:
  51. self.assert_element_absent(selector)
  52. @parameterized.expand(verified)
  53. def test_verified(self, username):
  54. self.open_nitter(username)
  55. self.assert_element_visible(Profile.verified)
  56. @parameterized.expand(protected)
  57. def test_protected(self, username, fullname, bio):
  58. self.open_nitter(username)
  59. self.assert_element_visible(Profile.protected)
  60. self.assert_exact_text(fullname, Profile.fullname)
  61. self.assert_exact_text(f'@{username}', Profile.username)
  62. if len(bio) > 0:
  63. self.assert_text(bio, Profile.bio)
  64. else:
  65. self.assert_element_absent(Profile.bio)
  66. @parameterized.expand(invalid)
  67. def test_invalid_username(self, username):
  68. self.open_nitter(username)
  69. self.assert_text(f'User "{username}" not found')
  70. @parameterized.expand(malformed)
  71. def test_malformed_username(self, username):
  72. """Test that malformed usernames (with invalid characters) return 404"""
  73. self.open_nitter(username)
  74. # Malformed usernames should return 404 page not found, not try to fetch from Twitter
  75. self.assert_text('Page not found')
  76. def test_suspended(self):
  77. self.open_nitter('suspendme')
  78. self.assert_text('User "suspendme" has been suspended')
  79. @parameterized.expand(banner_image)
  80. def test_banner_image(self, username, url):
  81. self.open_nitter(username)
  82. banner = self.find_element(Profile.banner + ' img')
  83. self.assertIn(url, banner.get_attribute('src'))
  84. class UserIdRedirectTest(BaseTestCase):
  85. @parameterized.expand(id_redirects)
  86. def test_i_user_redirect(self, user_id, username):
  87. """/i/user/<id> resolves the numeric id and redirects to the profile (issue #1433)"""
  88. self.open_nitter(f'i/user/{user_id}')
  89. self.assert_true(self.get_current_url().rstrip('/').endswith(f'/{username}'))
  90. self.assert_exact_text(f'@{username}', Profile.username)
  91. @parameterized.expand(id_redirects)
  92. def test_intent_user_redirect(self, user_id, username):
  93. """/intent/user?user_id=<id> redirects to the profile (issue #1433)"""
  94. self.open_nitter(f'intent/user?user_id={user_id}')
  95. self.assert_true(self.get_current_url().rstrip('/').endswith(f'/{username}'))
  96. self.assert_exact_text(f'@{username}', Profile.username)