Ejemplo n.º 1
0
class TestUserManager(TestCase):
    def setUp(self):
        self._user_manager = UserManager()
        UserModel.objects.create(user_id=1775634455973687126, access_token="token1", account="account1", password="******")
        UserModel.objects.create(user_id=3589683559412082469, access_token="token2", account="account2", password="******")

    def test_get_user_from_token(self):
        user = self._user_manager.get_user_from_token("token1")
        self.assertEqual(user.account, 'account1')

    def test_get_user_from_token_exception(self):
        try:
            user = self._user_manager.get_user_from_token("no this token")
            self.assertTrue(False)
        except AuthorizationError:
            pass

    def test_login(self):
        user = self._user_manager.login("account1", "password1")
        self.assertEqual(user["accessToken"], "token1")
        self.assertEqual(user["account"], "account1")

    def test_login_fail(self):
        try:
            user = self._user_manager.login("no this account", "no this password")
            self.assertTrue(False)
        except AuthorizationError:
            pass

    def tearDown(self):
        UserModel.objects.all().delete()
Ejemplo n.º 2
0
class TestUserManager(TestCase):
    def setUp(self):
        self._user_manager = UserManager()

    def test_register(self):
        fb_token = Utility.generate_token()
        user = self._user_manager.register(fb_token)
        self.assertEqual(fb_token, user.fb_token, "fb token error")

    def tearDown(self):
        pass
Ejemplo n.º 3
0
def register(request):
    try:
        request = RequestChecker(request)

        # header

        # POST data
        data = {
            "fb_token": request.get_data("fb_token"),
        }

        # action
        user = UserManager.register(data["fb_token"])

        return JSONResponse.output({"access_token": user.token})

    except Error as error:
        return JSONResponse.output(error)
Ejemplo n.º 4
0
 def setUp(self):
     self._user_manager = UserManager()
Ejemplo n.º 5
0
 def setUp(self):
     self._user_manager = UserManager()
     UserModel.objects.create(user_id=1775634455973687126, access_token="token1", account="account1", password="******")
     UserModel.objects.create(user_id=3589683559412082469, access_token="token2", account="account2", password="******")