Commit db731d76 authored by ViolanteCodes's avatar ViolanteCodes
Browse files

moved gitlab object calls to within local functions and tested. all tests...

moved gitlab object calls to within local functions and tested. all tests passing. added a testing=False default call to gitlab test calls to make testing easier
parent e6b872c9
......@@ -413,7 +413,7 @@ class TestProjectDetailViewPagination(TestCase):
tor_project = Project(gitlab_id=426)
tor_project.save()
self.tor_project = tor_project
self.gl_project = gl_public.projects.get(426)
self.gl_project = gitlab_get_project(426, public=True)
self.open_issues_metadata = self.get_issues_metadata('opened')
self.closed_issues_metadata = self.get_issues_metadata('closed')
# Get metadata for open issues, including total and pages
......
......@@ -226,38 +226,50 @@ from gl_bot.gitlabdown import (
# gl = gitlab.Gitlab(
# settings.GITLAB_URL,
# private_token=settings.GITLAB_SECRET_TOKEN,
# timeout=settings.GITLAB_TIMEOUT)
gl_public = gitlab.Gitlab(
settings.GITLAB_URL, timeout=settings.GITLAB_TIMEOUT)
gl_gitlab_down = GitlabDownObject()
# # timeout=settings.GITLAB_TIMEOUT)
# gl_public = gitlab.Gitlab(
# settings.GITLAB_URL, timeout=settings.GITLAB_TIMEOUT)
# gl_gitlab_down = GitlabDownObject()
def gitlab_get_project(project, public=False, testing=False):
"""Takes an integer, and grabs a gitlab project where gitlab_id
matches the integer."""
# Pull timeout value from settings
timeout = settings.GITLAB_TIMEOUT
# if testing = true, swap URLs
if testing == True:
gitlab_url = settings.TIMEOUT_URL
else:
gitlab_url = settings.GITLAB_URL
# If public == True, create without token.
if public == True:
gl_object = gl_public
gl = gitlab.Gitlab(gitlab_url, timeout=timeout)
else:
gl_object = gl
gl = gitlab.Gitlab(
gitlab_url,
private_token = settings.GITLAB_SECRET_TOKEN,
timeout=timeout)
# Try to get project, if fails, swap to GitlabDownObject.
try:
working_project = gl_object.projects.get(project)
working_project = gl.projects.get(project)
except (ConnectTimeout, ConnectionError):
working_project = gl_gitlab_down.projects.get(project)
gl = GitLabDownObject()
working_project = gl.projects.get(project)
return working_project
def gitlab_get_issue(project, issue, public=False):
def gitlab_get_issue(project, issue, public=False, testing=False):
"""Takes two integers and grabs corresponding gitlab issue."""
working_project = gitlab_get_project(project, public=public)
working_project = gitlab_get_project(
project, public=public, testing=testing)
try:
working_issue = working_project.issues.get(issue)
except (ConnectTimeout, ConnectionError):
working_issue = gl_gitlab_down.projects.issues.get(issue)
gl = GitLabDownObject()
project = gl.projects.get(project)
working_issue = project.issues.get(issue)
return working_issue
def gitlab_get_notes_list(project, issue, public=False):
def gitlab_get_notes_list(project, issue, public=False, testing=False):
"""Grabs the notes list for a specific issue."""
working_issue = gitlab_get_issue(project, issue, public=public)
notes_list = working_issue.notes.list()
......
"""Tests specific to Gitlab bot and Gitlab Fail Gracefully"""
from django.conf import settings
from django.test import SimpleTestCase, Client, tag
from django.test import SimpleTestCase, Client, tag, override_settings
from test_plus.test import TestCase, CBVTestCase
from django.urls import reverse, resolve
# from django.views.generic import TemplateView, DetailView, CreateView, UpdateView
from django.core.cache import cache
from anonticket.models import Project, Issue, Note
from anonticket.views import ProjectDetailView
# Import gitlab and relevant gl_bot functions.
import gitlab
from gl_bot.gitlabdown import (
GitlabDownObject, GitlabDownProject, GitlabDownIssue, GitlabDownNote
)
GitlabDownObject, GitlabDownProject, GitlabDownIssue, GitlabDownNote)
from requests.exceptions import ConnectTimeout, ConnectionError
# import get functions from view
# Note: If you run tests with --tag prefix, you can test a small suite
# of tests with one of the tags below (registered with '@tag'.)
......@@ -106,15 +111,3 @@ class TestGitLabBotBasic(SimpleTestCase):
for note in test_notes_list:
self.assertEqual(note.name, "GitLab API call failed.")
self.assertEqual(note.attributes['id'],9999999)
class TestGitlabTimeoutProjectDetailView(TestCase):
"""Test that ProjectDetailView displays the mock GL object
when GitLab connection times out."""
pass
class TestGitlabTimeoutIssueDetailView(TestCase):
"""Test that the issue_detail_view displays the mock GL object
datal when GitLab connection times out."""
pass
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment