Ejemplo n.º 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')
Ejemplo n.º 2
0
    def test_save_github_repo_data(self):
        user = User()
        username = "******"
        user.create_user(username)

        project = Project()
        project.user_id = user.id
        project.save()

        user.save_github_repo_data(project)

        project_user = User.objects(project=project).first()
        self.assertEqual(user, project_user)
    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)
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
    def register_repo(self, repo_json):
        project_name = repo_json["repository_name"]
        owner = repo_json["owner"]
        chat_id = repo_json["chat_id"]

        user = User.objects(chat_id=chat_id).first()
        try:
            project = Project()
            if user.project:
                webhook = Webhook(chat_id)
                webhook.delete_hook(owner, project_name)
                webhook.delete_hook(user.github_user, user.project.name)
                user.github_user = owner
                user.save()
                project = user.project
                project.update_repository_infos(str(project_name))
            else:
                webhook = Webhook(chat_id)
                webhook.delete_hook(owner, project_name)
                user.github_user = owner
                user.save()
                project.save_repository_infos(user, str(project_name))
            user.save_github_repo_data(project)
        except AttributeError:
            dict_error = {
                "message":
                "Tive um erro tentando cadastrar seu repositório. "
                "Mais tarde você tenta. Ok?"
            }
            raise AttributeError(json.dumps(dict_error))
Ejemplo n.º 6
0
def comment_issue(chat_id):
    try:
        response = request.get_json()
        body = response['body']
        issue_number = response['issue_number']

        user = User.objects(chat_id=chat_id).first()
        project = Project()
        project = user.project
        project = project.name.split("/")
        issue = Issue(chat_id)
        comment_issue = issue.comment_issue(project[-1], user.github_user,
                                            issue_number, body)
    except HTTPError as http_error:
        return issue.error_message(http_error)
    except AttributeError:
        return jsonify(NOT_FOUND), 404
    else:
        return jsonify({"body": comment_issue["body"]}), 200
Ejemplo n.º 7
0
def create_issue(chat_id):
    try:
        response = request.get_json()
        title = response['title']
        body = response['body']

        user = User.objects(chat_id=chat_id).first()
        project = Project()
        project = user.project
        project = project.name.split("/")
        issue = Issue(chat_id)
        create_issue = issue.create_issue(project[-1], user.github_user, title,
                                          body)
    except HTTPError as http_error:
        return issue.error_message(http_error)
    except AttributeError:
        return jsonify(NOT_FOUND), 404
    else:
        return jsonify({
            "title": create_issue["title"],
            "body": create_issue["body"],
            "html_url": create_issue["html_url"]
        }), 200
 def setup(self):
     super().setUp()
     Project.drop_collection()