Esempio n. 1
0
    def test_save_and_get(self):
        now = self.ts_now()
        following = HBaseFollowing(
            from_user_id=123,
            created_at=now,
            to_user_id=456,
        )
        following.save()
        following = HBaseFollowing.get(from_user_id=123, created_at=now)
        self.assertEqual(following.from_user_id, 123)
        self.assertEqual(following.created_at, now)
        self.assertEqual(following.to_user_id, 456)

        following.to_user_id = 789
        following.save()
        self.assertEqual(following.to_user_id, 789)
        following = HBaseFollowing.get(from_user_id=123, created_at=now)
        self.assertEqual(following.to_user_id, 789)

        # get non-exist object get none
        following = HBaseFollowing.get(from_user_id=123,
                                       created_at=self.ts_now())
        self.assertIsNone(following)

        # wrong row_keys to creat
        try:
            following = HBaseFollowing(from_user_id=123, to_user_id=456)
            following.save()
            exception_raised = False
        except BadRowKeyException as e:
            exception_raised = True
            self.assertEqual(str(e), 'created_at not defined')
        self.assertEqual(exception_raised, True)
Esempio n. 2
0
    def test_save_and_get(self):
        timestamp = self.ts_now
        following = HBaseFollowing(from_user_id=123, to_user_id=34, created_at=timestamp)
        following.save()

        instance = HBaseFollowing.get(from_user_id=123, created_at=timestamp)
        self.assertEqual(instance.from_user_id, 123)
        self.assertEqual(instance.to_user_id, 34)
        self.assertEqual(instance.created_at, timestamp)

        following.to_user_id = 456
        following.save()

        instance = HBaseFollowing.get(from_user_id=123, created_at=timestamp)
        self.assertEqual(instance.to_user_id, 456)

        # object does not exist, return None
        instance = HBaseFollowing.get(from_user_id=123, created_at=self.ts_now)
        self.assertEqual(instance, None)