1
0
mirror of https://github.com/zedeus/nitter synced 2024-11-25 19:19:17 +01:00
nitter/tests/test_profile.py

88 lines
2.9 KiB
Python
Raw Normal View History

2019-06-28 04:56:02 +02:00
from base import BaseTestCase, Profile
2019-06-28 19:18:52 +02:00
from parameterized import parameterized
2019-06-28 04:56:02 +02:00
2019-06-28 19:18:52 +02:00
profiles = [
2019-06-29 00:42:44 +02:00
['mobile_test', 'Test account',
'Test Account. test test Testing username with @mobile_test_2 and a #hashtag',
2019-08-15 04:07:01 +02:00
'San Francisco, CA', 'example.com/foobar', 'Joined October 2009', '100'],
['mobile_test_2', 'mobile test 2', '', '', '', 'Joined January 2011', '13']
2019-06-28 19:18:52 +02:00
]
2019-06-28 04:56:02 +02:00
2019-06-28 19:18:52 +02:00
verified = [['jack'], ['elonmusk']]
protected = [
2019-08-15 04:07:01 +02:00
['mobile_test_7', 'mobile test 7', ''],
['Poop', 'Randy', 'Social media fanatic.']
2019-06-28 19:18:52 +02:00
]
invalid = [['thisprofiledoesntexist'], ['%']]
2019-06-28 04:56:02 +02:00
2019-06-29 00:42:44 +02:00
banner_color = [
['nim_lang', '22, 25, 32'],
['rustlang', '35, 31, 32']
2019-06-29 00:42:44 +02:00
]
banner_image = [
['mobile_test', 'profile_banners%2F82135242%2F1384108037%2F1500x500']
]
2019-06-28 19:18:52 +02:00
2019-06-29 00:42:44 +02:00
class ProfileTest(BaseTestCase):
2019-06-28 19:18:52 +02:00
@parameterized.expand(profiles)
def test_data(self, username, fullname, bio, location, website, joinDate, mediaCount):
2019-06-28 19:18:52 +02:00
self.open_nitter(username)
self.assert_exact_text(fullname, Profile.fullname)
self.assert_exact_text(f'@{username}', Profile.username)
tests = [
(bio, Profile.bio),
(location, Profile.location),
(website, Profile.website),
(joinDate, Profile.joinDate),
2019-08-15 04:07:01 +02:00
(mediaCount + " Photos and videos", Profile.mediaCount)
]
for text, selector in tests:
if len(text) > 0:
self.assert_exact_text(text, selector)
else:
self.assert_element_absent(selector)
2019-06-28 19:18:52 +02:00
@parameterized.expand(verified)
def test_verified(self, username):
self.open_nitter(username)
2019-06-28 04:56:02 +02:00
self.assert_element_visible(Profile.verified)
2019-06-28 19:18:52 +02:00
@parameterized.expand(protected)
2019-06-29 00:42:44 +02:00
def test_protected(self, username, fullname, bio):
2019-06-28 19:18:52 +02:00
self.open_nitter(username)
2019-06-28 04:56:02 +02:00
self.assert_element_visible(Profile.protected)
2019-06-28 19:18:52 +02:00
self.assert_exact_text(fullname, Profile.fullname)
self.assert_exact_text(f'@{username}', Profile.username)
2019-06-28 04:56:02 +02:00
2019-06-28 19:18:52 +02:00
if len(bio) > 0:
self.assert_text(bio, Profile.bio)
else:
self.assert_element_absent(Profile.bio)
2019-06-28 04:56:02 +02:00
2019-06-28 19:18:52 +02:00
@parameterized.expand(invalid)
def test_invalid_username(self, username):
self.open_nitter(username)
self.assert_text(f'User "{username}" not found')
2019-06-28 04:56:02 +02:00
2020-06-17 20:55:38 +02:00
def test_suspended(self):
2021-07-18 03:56:51 +02:00
self.open_nitter('user')
self.assert_text('User "user" has been suspended')
2019-06-29 00:42:44 +02:00
@parameterized.expand(banner_color)
def test_banner_color(self, username, color):
self.open_nitter(username)
2022-01-20 06:03:08 +01:00
banner = self.find_element(Profile.banner + ' a')
2019-06-29 00:42:44 +02:00
self.assertIn(color, banner.value_of_css_property('background-color'))
@parameterized.expand(banner_image)
def test_banner_image(self, username, url):
self.open_nitter(username)
banner = self.find_element(Profile.banner + ' img')
self.assertIn(url, banner.get_attribute('src'))