Ejemplo n.º 1
0
    def test_type_validate(self):
        user = model.User()

        test_int = 1
        test_str = "Invalid Value"
        self.assertIsInstance(user.user_id, str)
        with self.assertRaises(FieldTypeError):
            user.user_id = test_int

        self.assertIsInstance(user.name, str)
        with self.assertRaises(FieldTypeError):
            user.name = test_int

        self.assertIsInstance(user.screen_name, str)
        with self.assertRaises(FieldTypeError):
            user.screen_name = test_int

        self.assertIsInstance(user.location, str)
        with self.assertRaises(FieldTypeError):
            user.location = test_int

        self.assertIsInstance(user.description, str)
        with self.assertRaises(FieldTypeError):
            user.description = test_int

        self.assertIsInstance(user.followers_count, int)
        with self.assertRaises(FieldTypeError):
            user.followers_count = test_str

        self.assertIsInstance(user.following_count, int)
        with self.assertRaises(FieldTypeError):
            user.following_count = test_str

        self.assertIsInstance(user.listed_count, int)
        with self.assertRaises(FieldTypeError):
            user.listed_count = test_str

        self.assertIsInstance(user.favorites_count, int)
        with self.assertRaises(FieldTypeError):
            user.favorites_count = test_str

        self.assertIsInstance(user.statuses_count, int)
        with self.assertRaises(FieldTypeError):
            user.statuses_count = test_str

        self.assertIsInstance(user.created_at, datetime)
        with self.assertRaises(FieldTypeError):
            user.created_at = test_int

        self.assertIsInstance(user.updated_at, datetime)
        with self.assertRaises(FieldTypeError):
            user.updated_at = test_int
Ejemplo n.º 2
0
 def from_ts_user(ts_u) -> model.User:
     user = model.User()
     user.user_id = ts_u.id
     user.name = ts_u.full_name
     user.screen_name = ts_u.user
     user.location = ts_u.location
     user.followers_count = ts_u.followers
     user.following_count = ts_u.following
     user.favorites_count = ts_u.likes
     user.listed_count = ts_u.lists
     user.statuses_count = ts_u.tweets
     user.created_at = datetime.strptime(ts_u.date_joined,
                                         "%H:%M - %Y年%m月%d日")
     user.updated_at = datetime.now()
     return user
Ejemplo n.º 3
0
    def from_tpy_user(tpy_u) -> model.User:
        user = model.User()
        user.user_id = str(tpy_u.id)
        user.name = tpy_u.name
        user.screen_name = tpy_u.screen_name
        user.location = tpy_u.location
        user.description = tpy_u.description
        user.followers_count = tpy_u.followers_count
        user.following_count = tpy_u.friends_count
        user.listed_count = tpy_u.listed_count
        user.favorites_count = tpy_u.favourites_count
        user.statuses_count = tpy_u.statuses_count
        user.created_at = tpy_u.created_at
        user.updated_at = datetime.now()

        return user
Ejemplo n.º 4
0
    def test_default_value(self):
        user = model.User()
        self.assertEqual(user.user_id, DEFAULT_USER_ID)
        self.assertEqual(user.name, "")
        self.assertEqual(user.screen_name, "")
        self.assertEqual(user.location, "")
        self.assertEqual(user.description, "")
        self.assertEqual(user.followers_count, -1)
        self.assertEqual(user.following_count, -1)
        self.assertEqual(user.listed_count, -1)
        self.assertEqual(user.favorites_count, -1)
        self.assertEqual(user.statuses_count, -1)
        self.assertEqual(user.created_at, DEFAULT_CREATED_AT)

        # It cannot get same current time, so if time difference is less than 1 seconds, it will pass.
        time_diff = datetime.now() - user.updated_at
        self.assertLessEqual(time_diff.seconds, 600)
Ejemplo n.º 5
0
    def test_forbidden_blank(self):
        user = model.User()
        test_val = ""
        try:
            test_val = "A"
            user.user_id = test_val
            test_val = "0"
            user.user_id = test_val
        except ValidationError:
            self.fail(
                "user_id raised ValidationError about blank unexpectedly\nInput Value: {}"
                .format(test_val))

        with self.assertRaises(ValidationError):
            user.user_id = ""
        with self.assertRaises(ValidationError):
            user.user_id = " " * 20
        with self.assertRaises(ValidationError):
            user.user_id = "    " * 5
Ejemplo n.º 6
0
    def test_max_len(self):
        user = model.User()

        # max length is 30
        try:
            user.user_id = "A"
            user.user_id = "A" * 15
            user.user_id = "A" * 30
        except ValidationError:
            self.fail(
                "user_id raised ValidationError about length unexpectedly")

        with self.assertRaises(ValidationError):
            user.user_id = "A" * 31

        # max length is 100
        try:
            user.name = "A"
            user.name = "A" * 50
            user.name = "A" * 100
        except ValidationError:
            self.fail("name raised ValidationError about length unexpectedly")

        with self.assertRaises(ValidationError):
            user.name = "A" * 101

        # max length is 50
        try:
            user.screen_name = "A"
            user.screen_name = "A" * 25
            user.screen_name = "A" * 50
        except ValidationError:
            self.fail(
                "screen_name raised ValidationError about length unexpectedly")

        with self.assertRaises(ValidationError):
            user.screen_name = "A" * 51

        # max length is 50
        try:
            user.location = "A"
            user.location = "A" * 25
            user.location = "A" * 50
        except ValidationError:
            self.fail(
                "location raised ValidationError about max length unexpectedly"
            )

        with self.assertRaises(ValidationError):
            user.location = "A" * 51

        # max length is 300
        try:
            user.description = "A"
            user.description = "A" * 150
            user.description = "A" * 300
        except ValidationError:
            self.fail(
                "description raised ValidationError about length unexpectedly")

        with self.assertRaises(ValidationError):
            user.description = "A" * 301
Ejemplo n.º 7
0
    def test_type_validate(self):
        """
        [!!] "hashtags" and "urls" cannot test
        """
        tweet = model.Tweet()

        test_int = 1
        test_str = "Invalid"
        test_user = model.User()

        # tweet_id
        try:
            tweet.tweet_id = test_str
        except ValidationError:
            self.fail("tweet_id Validation is occurred unexpectedly. ")
        with self.assertRaises(FieldTypeError):
            tweet.tweet_id = test_int

        # user
        try:
            tweet.user = test_user
        except ValidationError:
            self.fail("user Validation is occurred unexpectedly. ")
        with self.assertRaises(FieldTypeError):
            tweet.user = test_str

        # text
        try:
            tweet.text = test_str
        except ValidationError:
            self.fail("text Validation is occurred unexpectedly. ")
        with self.assertRaises(FieldTypeError):
            tweet.text = test_int

        # lang
        try:
            tweet.lang = test_str
        except ValidationError:
            self.fail("lang Validation is occurred unexpectedly. ")
        with self.assertRaises(FieldTypeError):
            tweet.lang = test_int

        # retweet_count
        try:
            tweet.retweet_count = test_int
        except ValidationError:
            self.fail("retweet_count Validation is occurred unexpectedly. ")
        with self.assertRaises(FieldTypeError):
            tweet.retweet_count = test_str

        # favorite_count
        try:
            tweet.favorite_count = test_int
        except ValidationError:
            self.fail("favorite_count Validation is occurred unexpectedly. ")
        with self.assertRaises(FieldTypeError):
            tweet.favorite_count = test_str

        # source
        try:
            tweet.source = test_str
        except ValidationError:
            self.fail("source Validation is occurred unexpectedly. ")
        with self.assertRaises(FieldTypeError):
            tweet.source = test_int

        # in_reply_to_status_id
        try:
            tweet.in_reply_to_status_id = test_str
        except ValidationError:
            self.fail(
                "in_reply_to_status_id Validation is occurred unexpectedly. ")
        with self.assertRaises(FieldTypeError):
            tweet.in_reply_to_status_id = test_int

        # coordinates
        try:
            tweet.coordinates = test_str
        except ValidationError:
            self.fail("coordinates Validation is occurred unexpectedly. ")
        with self.assertRaises(FieldTypeError):
            tweet.coordinates = test_int

        # place
        try:
            tweet.place = test_str
        except ValidationError:
            self.fail("place Validation is occurred unexpectedly. ")
        with self.assertRaises(FieldTypeError):
            tweet.place = test_int

        # created_at
        try:
            tweet.created_at = datetime.now()
        except ValidationError:
            self.fail("created_at Validation is occurred unexpectedly. ")
        with self.assertRaises(FieldTypeError):
            tweet.created_at = test_str

        # updated_At
        try:
            tweet.updated_at = datetime.now()
        except ValidationError:
            self.fail("updated_at Validation is occurred unexpectedly. ")
        with self.assertRaises(FieldTypeError):
            tweet.updated_at = test_str