test_profile.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. class ProfileTest(BaseTestCase):
  30. @parameterized.expand(profiles)
  31. def test_data(self, username, fullname, bio, location, website, joinDate, mediaCount):
  32. self.open_nitter(username)
  33. self.assert_exact_text(fullname, Profile.fullname)
  34. self.assert_exact_text(f'@{username}', Profile.username)
  35. tests = [
  36. (bio, Profile.bio),
  37. (location, Profile.location),
  38. (website, Profile.website),
  39. (joinDate, Profile.joinDate),
  40. (mediaCount + " Photos and videos", Profile.mediaCount)
  41. ]
  42. for text, selector in tests:
  43. if len(text) > 0:
  44. self.assert_exact_text(text, selector)
  45. else:
  46. self.assert_element_absent(selector)
  47. @parameterized.expand(verified)
  48. def test_verified(self, username):
  49. self.open_nitter(username)
  50. self.assert_element_visible(Profile.verified)
  51. @parameterized.expand(protected)
  52. def test_protected(self, username, fullname, bio):
  53. self.open_nitter(username)
  54. self.assert_element_visible(Profile.protected)
  55. self.assert_exact_text(fullname, Profile.fullname)
  56. self.assert_exact_text(f'@{username}', Profile.username)
  57. if len(bio) > 0:
  58. self.assert_text(bio, Profile.bio)
  59. else:
  60. self.assert_element_absent(Profile.bio)
  61. @parameterized.expand(invalid)
  62. def test_invalid_username(self, username):
  63. self.open_nitter(username)
  64. self.assert_text(f'User "{username}" not found')
  65. @parameterized.expand(malformed)
  66. def test_malformed_username(self, username):
  67. """Test that malformed usernames (with invalid characters) return 404"""
  68. self.open_nitter(username)
  69. # Malformed usernames should return 404 page not found, not try to fetch from Twitter
  70. self.assert_text('Page not found')
  71. def test_suspended(self):
  72. self.open_nitter('suspendme')
  73. self.assert_text('User "suspendme" has been suspended')
  74. @parameterized.expand(banner_image)
  75. def test_banner_image(self, username, url):
  76. self.open_nitter(username)
  77. banner = self.find_element(Profile.banner + ' img')
  78. self.assertIn(url, banner.get_attribute('src'))