Exemplo n.º 1
0
 def get_issue(self, issueId: str):
     result = self.db.collection(
         properties.issuesPath).document(issueId).get()
     if result.to_dict() is None:
         return None
     issue = Issue(result.to_dict())
     issue.id = result.id
     return issue
Exemplo n.º 2
0
class AppCase(RequiresMocks):
    def setup_app(self):
        self.app = app.test_client()

        # Mock the GitHub API
        self.mock_github = self.create_patch('app.routes.oauth.github.api')
        self.mock_github_api = MagicMock()
        self.mock_github.return_value = self.mock_github_api

        # Mock the Google API
        self.mock_google_user_info = self.create_patch('app.routes.oauth.google.user_info')
        self.mock_google_drive_api = self.create_patch('app.routes.oauth.google.drive_api')
        self.mock_google_drive_api.return_value = MagicMock()

    def teardown_dbs(self):
        Issue.drop_collection()
        User.drop_collection()
        Project.drop_collection()
        Attachment.drop_collection()
        Comment.drop_collection()

    def create_user(self):
        self.test_user = User(
                name='Numpy Ping',
                google_id='12345',
                picture='http://foo.com/image.png',
                email='*****@*****.**'
        )
        self.test_user.save()

    def create_project(self):
        if not hasattr(self, 'test_user'):
            self.create_user()
        self.test_project = Project(
                name='Proj',
                repo='pub/bar',
                author=self.test_user
        )
        self.test_project.save()

    def create_issue(self):
        if not hasattr(self, 'test_project'):
            self.create_project()
        self.test_issue = Issue(
                title='Some important issue',
                project=self.test_project,
                author=self.test_user
        )
        self.test_issue.save()
Exemplo n.º 3
0
def create():
    args = list(request.form.values())
    issue = Issue(email=args[0],
                  description=args[1],
                  category_id=args[2],
                  status_id=args[3])
    dbSession.add(issue)
    dbSession.commit()
    return redirect(url_for("issue_index"))
Exemplo n.º 4
0
 def create_issue(self):
     if not hasattr(self, 'test_project'):
         self.create_project()
     self.test_issue = Issue(
             title='Some important issue',
             project=self.test_project,
             author=self.test_user
     )
     self.test_issue.save()
Exemplo n.º 5
0
def create(data, repo):
    user = users_service.get(data['user']['id'])
    if user is None:
        user = users_service.create(data['user'])
        db.session.add(user)
    issue = Issue(user, repo, data)
    db.session.add(issue)
    for topic in issue.topics:
        topics_service.update_issues_count(topic)
    return issue
Exemplo n.º 6
0
 def test_issue_conversion_from_original(self):
     old_issue = {
         "id":848,
         "title":"20",
         "date":"February 3, 2014",
         "url":"http:\/\/www.themagpi.com\/issue\/issue-20\/",
         "issuu":"issue20final",
         "pdf":"http:\/\/www.themagpi.com\/issue\/issue-20\/pdf",
         "cover":"http:\/\/www.themagpi.com\/assets\/20.jpg",
         "editorial":"Welcome"
     }
     expected = {
         "id": 20, 
         "id_issuu":"issue20final",
         "pdf_url": "http:\/\/www.themagpi.com\/issue\/issue-20\/pdf",
         "image_url": "http:\/\/www.themagpi.com\/assets\/20.jpg",
         "date": "February 3, 2014", 
         "content": "Welcome",
     }
     issue = Issue()
     issue.fill_from_old(old_issue)
     assert_equal(issue.maximize(), expected)
Exemplo n.º 7
0
    def setUp(self):
        self.setup_app()
        self.create_user()
        self.create_project()

        self.mock_current_user = self.create_patch('app.models.user.current_user')
        self.mock_current_user.return_value = self.test_user

        self.issue = Issue(
                title='Some important issue',
                project=self.test_project,
                author=self.test_user
        )
        self.issue.save()
Exemplo n.º 8
0
    def test_parse_references(self):
        issue_ = Issue(
                title='Referenced issue',
                project=self.test_project,
                author=self.test_user
        )
        issue_.save()

        self.issue.body = 'Some body text referencing this issue /%s/issues/%s' % (self.test_project.name, issue_.id)

        self.issue.parse_references(self.issue.body)

        # Reload the issue so changes are reflected.
        issue_.reload()

        self.assertEqual(len(self.issue.references), 1)
        self.assertEqual(len(issue_.events), 1)
        self.assertEqual(self.issue.references[0].title, 'Referenced issue')
        self.assertEqual(issue_.events[0].data, {
            'project_slug': self.test_project.slug,
            'referencer_id': self.issue.id,
            'referencer_title': self.issue.title
        })
Exemplo n.º 9
0
def new_issue():
    try:
        data = request.get_json()
        if "issue" in data:
            issue = Issue(data["issue"]).to_dict(remove_id=True)
            issue_ref = firestore_service.create_issue(issue)
            resp = make_response(jsonify({"id": issue_ref}), 200)
        else:
            resp = make_response(jsonify({"error": "not enough args"}), 400)
        return resp
    except Exception as e:
        logging.info("Creating issue triggered the below error :")
        logging.info(e)
        resp = make_response(jsonify({}), 500)
        return resp
Exemplo n.º 10
0
 def test_maximize_issue(self):
     expected = {
         "id": 19,
         "id_issuu":"issuu19final",
         "pdf_url": "https://issuee",
         "image_url": "https://issuee.jpg",
         "date": "Feb 2013", 
         "content": "Bla Bla Bla content"
     }
     issue = Issue()
     issue.id = 19
     issue.id_issuu = "issuu19final"
     issue.date = "Feb 2013"
     issue.pdf_url = "https://issuee"
     issue.image_url = "https://issuee.jpg" 
     issue.content = "Bla Bla Bla content"
     assert_equal(issue.maximize(), expected)
Exemplo n.º 11
0
 def test_minimize_issue(self):
     expected = {
         "id": 19, 
         "pdf_url": "https://issuee",
         "image_url": "https://issuee.jpg",
         "date": "Feb 2013", 
     }
     issue = Issue()
     issue.id = 19
     issue.date = "Feb 2013"
     issue.pdf_url = "https://issuee"
     issue.image_url = "https://issuee.jpg"
     assert_equal(issue.minimize(), expected)
Exemplo n.º 12
0
def new_issue():
    """Report an issue with a car if the user making the report is an admin.
    Also send notifications to all engineers via pushbullet that an issue has
    been reported

    .. :quickref: Issue; Report a new issue.

    **Example request**:

    .. sourcecode:: http

        POST /api/issue HTTP/1.1
        Host: localhost
        Accept: application/json
        Content-Type: application/json

        {
            "car_id": 1,
            "username": "******",
            "details": "Broken tail light"
        }

    **Example response**:

    .. sourcecode:: http

        HTTP/1.1 200 OK
        Content-Type: application/json

        {
            "message": "Success"
        }

    .. sourcecode:: http

        HTTP/1.1 401 UNAUTHORIZED
        Content-Type: application/json

        {
            "message": {
                "user": ["User is not an admin."]
            }
        }

    :<json int car_id: the make of the car being updated
    :<json string username: the username of the person reporting the issue
    :<json string details: details of what the issue may be
    :resheader Content-Type: application/json
    :status 200: creating a new issue was successful
    :status 400: missing or invalid fields
    :status 401: user is not an admin
    """

    response = {
        'message': '',
    }
    status = 200

    form_schema = ReportIssueFormSchema()
    form_errors = form_schema.validate(request.json)
    if form_errors:
        response['message'] = form_errors
        status = 400
    else:
        # Checking if user making the request is an admin
        user = User.query.get(request.json["username"])
        if user.role is not Role.admin:
            response['message'] = {'user': ['User is not an admin.']}
            status = 401
        else:
            car_id = request.json["car_id"]
            time = datetime.utcnow()
            details = request.json["details"]

            issue = Issue(car_id, time, details)
            db.session.add(issue)
            db.session.commit()
            response['message'] = "Success"

    if response['message'] == "Success":
        # Notifying every engineer via Pushbullet if they have a token
        engineers = (User.query.filter(User.role == Role.engineer).filter(
            User.pb_token != None).all())
        for engineer in engineers:
            data = {
                "type": "note",
                "title": "Issue with car #" + str(car_id),
                "body": details
            }
            # Making request to pushbullet API
            requests.post('https://api.pushbullet.com/v2/pushes',
                          data=json.dumps(data),
                          headers={
                              'Authorization': 'Bearer ' + engineer.pb_token,
                              'Content-Type': 'application/json'
                          })

    return response, status
Exemplo n.º 13
0
def index():
    conn = connection()
    issues = Issue.all(conn)

    return jsonify(issues=issues)
Exemplo n.º 14
0
def create():
    conn = connection()
    Issue.create(conn, request.form)

    return redirect(url_for("issue_index"))
Exemplo n.º 15
0
 def teardown_dbs(self):
     Issue.drop_collection()
     User.drop_collection()
     Project.drop_collection()
     Attachment.drop_collection()
     Comment.drop_collection()
Exemplo n.º 16
0
class IssueTest(AppCase):
    def setUp(self):
        self.setup_app()
        self.create_user()
        self.create_project()

        self.mock_current_user = self.create_patch('app.models.user.current_user')
        self.mock_current_user.return_value = self.test_user

        self.issue = Issue(
                title='Some important issue',
                project=self.test_project,
                author=self.test_user
        )
        self.issue.save()

    def tearDown(self):
        self.teardown_dbs()

    def test_db_starting_state(self):
        # Expected to be 1 because we create an issue in the setUp method.
        self.assertEqual(Issue.objects.count(), 1)

    def test_close(self):
        with app.test_request_context():
            self.issue.close()
            self.assertFalse(self.issue.open)
            self.assertEqual(len(self.issue.events), 1)

    def test_close_linked(self):
        self.issue.github_id = 1
        self.issue.linked_url = MagicMock(return_value='foo')
        with app.test_request_context():
            self.issue.close()
            self.mock_github_api.patch.assert_called_with(
                    'foo',
                    data=json.dumps({'state':'closed'})
            )

    def test_reopen(self):
        with app.test_request_context():
            self.issue.reopen()
            self.assertTrue(self.issue.open)
            self.assertEqual(len(self.issue.events), 1)

    def test_reopen_linked(self):
        self.issue.github_id = 1
        self.issue.linked_url = MagicMock(return_value='foo')
        with app.test_request_context():
            self.issue.reopen()
            self.mock_github_api.patch.assert_called_with(
                    'foo',
                    data=json.dumps({'state':'open'})
            )

    def test_parse_references(self):
        issue_ = Issue(
                title='Referenced issue',
                project=self.test_project,
                author=self.test_user
        )
        issue_.save()

        self.issue.body = 'Some body text referencing this issue /%s/issues/%s' % (self.test_project.name, issue_.id)

        self.issue.parse_references(self.issue.body)

        # Reload the issue so changes are reflected.
        issue_.reload()

        self.assertEqual(len(self.issue.references), 1)
        self.assertEqual(len(issue_.events), 1)
        self.assertEqual(self.issue.references[0].title, 'Referenced issue')
        self.assertEqual(issue_.events[0].data, {
            'project_slug': self.test_project.slug,
            'referencer_id': self.issue.id,
            'referencer_title': self.issue.title
        })

    def test_parse_mentions(self):
        u = User(name='Numpy', google_id='1', email='*****@*****.**')
        u.save()

        # Tests adds mentions
        self.issue.body = 'Some body text with a mention @[Numpy](user:%s)' % u.google_id
        self.issue.parse_mentions()

        u.reload()

        self.assertEqual(len(self.issue.mentions), 1)
        self.assertEqual(len(u.references), 1)

        # Tests removes mentions
        self.issue.body = 'Some body text without a mention'
        self.issue.parse_mentions()

        u.reload()

        self.assertEqual(len(self.issue.mentions), 0)
        self.assertEqual(len(u.references), 0)

        # Tests multiple mentions
        u_ = User(name='Lumpy', google_id='2', email='*****@*****.**')
        u_.save()

        self.issue.body = 'Some body text with two mentions @[Numpy](user:%s) @[Lumpy](user:%s)' % (u.google_id, u_.google_id)
        self.issue.parse_mentions()

        u.reload()
        u_.reload()

        self.assertEqual(len(self.issue.mentions), 2)
        self.assertEqual(len(u.references), 1)
        self.assertEqual(len(u_.references), 1)

        self.issue.body = 'Some body text with two mentions @[Lumpy](user:%s)' % u_.google_id
        self.issue.parse_mentions()

        u.reload()
        u_.reload()

        self.assertEqual(len(self.issue.mentions), 1)
        self.assertEqual(len(u.references), 0)
        self.assertEqual(len(u_.references), 1)

    def test_push_to_github_updates_linked_issue(self):
        self.issue.github_id = 1
        self.issue.linked_url = MagicMock(return_value='foo')

        resp = MagicMock()
        resp.status_code = 200

        self.mock_github_api.patch.return_value = resp

        self.issue.push_to_github()

        self.mock_github_api.patch.assert_called_with('foo', data=json.dumps({
            'title': self.issue.title,
            'body': self.issue.body,
            'labels': self.issue.labels
        }))

    def test_push_to_github_creates_linked_issue(self):
        self.issue.body = 'Let us create a %github issue'
        self.issue.linked_url = MagicMock(return_value='foo')

        resp = MagicMock()
        resp.status_code = 201
        resp.json.return_value = {'number': 1}

        self.mock_github_api.post.return_value = resp

        self.issue.push_to_github()

        self.assertEqual(self.issue.github_id, 1)

    def test_pre_delete(self):
        c = Comment(body='foo', author=self.test_user)
        c.issue = self.issue
        c.save()

        self.test_user.references.append(self.issue)
        self.test_user.save()

        self.issue.mentions.append(self.test_user)
        self.issue.comments.append(c)
        self.issue.save()

        self.assertEqual(Issue.objects.count(), 1)
        self.assertEqual(Comment.objects.count(), 1)
        self.assertEqual(len(self.test_user.references), 1)

        self.issue.delete()

        self.assertEqual(Issue.objects.count(), 0)
        self.assertEqual(Comment.objects.count(), 0)
        self.assertEqual(len(self.test_user.references), 0)
Exemplo n.º 17
0
def index():
    conn = connection()
    issues = Issue.all(conn)

    return render_template("issue/index.html", issues=issues)