Example #1
0
class BaseTestCase(TestCase):
    def setUp(self):
        self.db = init_db()
        self.user = User()
        self.user.username = '******'
        self.user.chat_id = '123456789'
        self.user.github_user = '******'
        self.user.github_user_id = '46005310'
        self.user.access_token = os.getenv("GITHUB_API_TOKEN", "")
        self.project = Project()
        self.project.name = 'apitest'
        self.project_id = '185474581'
        self.project.save()
        self.user.project = self.project
        self.user.save()
        self.GITHUB_API_TOKEN = os.getenv("GITHUB_API_TOKEN", "")
        self.response_not_found = Response()
        self.response_not_found.status_code = 404
        self.response_unauthorized = Response()
        self.response_unauthorized.status_code = 401

    def create_app(self):
        app = create_app()
        app.config.from_object("github.config.TestingConfig")
        return app

    def tearDown(self):
        self.db.drop_database('api')
Example #2
0
    def test_save_github_user_data(self):
        User.drop_collection()
        github_user = '******'
        chat_id = 'id'
        github_user_id = 'git_id'
        user = User()
        user.github_user = github_user
        user.save()
        user.save_github_user_data(github_user, chat_id, github_user_id)

        user_db = User.objects(github_user=github_user).first()
        self.assertEqual(user, user_db)
    def test_create_project(self):
        project = Project()
        description = "Test project"
        name = "Test Project"
        web_url = "https://cakaca.com"
        branches = ["branch1", "branch2"]
        project_id = "2113"

        user = User()
        user.username = "******"
        user.save()

        project.create_project(user, description, name, web_url, branches,
                               project_id)
        project_db = Project.objects(name=name).first()
        self.assertEqual(project, project_db)
Example #4
0
def get_access_token(chat_id):
    code = request.args.get('code')
    existing_user = User.objects(chat_id=chat_id).first()
    send_message(ACCESS_TOKEN, chat_id)
    if not existing_user:
        GITHUB_TOKEN = authenticate_access_token(code)
        db_user = User()
        db_user.access_token = GITHUB_TOKEN
        db_user.chat_id = str(chat_id)
        db_user.save()
        user = UserInfo(chat_id)
        user_infos = user.get_own_user_data()
        db_user.github_user = user_infos["github_username"]
        db_user.github_user_id = str(user_infos["github_user_id"])
        db_user.save()
        user.send_button_message(user_infos, chat_id)
    redirect_uri = "https://t.me/{bot_name}".format(bot_name=BOT_NAME)
    return redirect(redirect_uri, code=302)