Blame tests/test_pagure_flask_api_user.py

Pierre-Yves Chibon 8fc633
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
"""
Pierre-Yves Chibon baaf54
 (c) 2015-2018 - Copyright Red Hat Inc
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
 Authors:
Pierre-Yves Chibon 8fc633
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
"""
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 67d1cc
from __future__ import unicode_literals, absolute_import
Aurélien Bompard dcf6f6
Pierre-Yves Chibon 8fc633
import datetime
Pierre-Yves Chibon 219e3b
import os
Pierre-Yves Chibon 219e3b
import pytz
Pierre-Yves Chibon 8fc633
import shutil
Pierre-Yves Chibon 8fc633
import sys
Pierre-Yves Chibon 219e3b
import unittest
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
import json
Pierre-Yves Chibon 8fc633
from mock import patch
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 73d120
sys.path.insert(
Pierre-Yves Chibon 73d120
    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
Pierre-Yves Chibon 73d120
)
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
import pagure.api
Pierre-Yves Chibon b130e5
import pagure.config
Pierre-Yves Chibon d6ddc4
import pagure.lib.model as model
Pierre-Yves Chibon 930073
import pagure.lib.query
Pierre-Yves Chibon 8fc633
import tests
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
class PagureFlaskApiUSertests(tests.Modeltests):
Pierre-Yves Chibon 8fc633
    """ Tests for the flask API of pagure for issue """
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon f8a683
    maxDiff = None
Pierre-Yves Chibon f8a683
Pierre-Yves Chibon 8fc633
    def setUp(self):
Pierre-Yves Chibon 8fc633
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon 8fc633
        super(PagureFlaskApiUSertests, self).setUp()
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 73d120
        pagure.config.config["REQUESTS_FOLDER"] = None
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
    def test_api_users(self):
Pierre-Yves Chibon 8fc633
        """ Test the api_users function.  """
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/users")
Pierre-Yves Chibon 8fc633
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(sorted(data["users"]), ["foo", "pingou"])
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            sorted(data.keys()), ["mention", "total_users", "users"]
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["total_users"], 2)
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/users?pattern=p")
Pierre-Yves Chibon 8fc633
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(data["users"], ["pingou"])
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            sorted(data.keys()), ["mention", "total_users", "users"]
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["total_users"], 1)
Pierre-Yves Chibon 8fc633
Clement Verna 8ed9ee
    def test_api_view_user(self):
Clement Verna 8ed9ee
        """
Clement Verna 8ed9ee
            Test the api_view_user method of the flask api
Clement Verna 8ed9ee
            The tested user has no project or forks.
Clement Verna 8ed9ee
        """
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/user/pingou")
Clement Verna 8ed9ee
        self.assertEqual(output.status_code, 200)
Clement Verna 8ed9ee
        exp = {
Clement Verna 8ed9ee
            "forks": [],
Pierre-Yves Chibon 73d120
            "forks_pagination": {
Pierre-Yves Chibon 73d120
                "first": "http://localhost...",
Pierre-Yves Chibon 73d120
                "last": "http://localhost...",
Pierre-Yves Chibon 73d120
                "next": None,
Pierre-Yves Chibon 73d120
                "forkpage": 1,
Pierre-Yves Chibon 73d120
                "pages": 0,
Pierre-Yves Chibon 73d120
                "per_page": 20,
Pierre-Yves Chibon 73d120
                "prev": None,
Pierre-Yves Chibon 73d120
            },
Clement Verna 8ed9ee
            "repos": [],
Pierre-Yves Chibon 73d120
            "repos_pagination": {
Pierre-Yves Chibon 73d120
                "first": "http://localhost...",
Pierre-Yves Chibon 73d120
                "last": "http://localhost...",
Pierre-Yves Chibon 73d120
                "next": None,
Pierre-Yves Chibon 73d120
                "repopage": 1,
Pierre-Yves Chibon 73d120
                "pages": 0,
Pierre-Yves Chibon 73d120
                "per_page": 20,
Pierre-Yves Chibon 73d120
                "prev": None,
Pierre-Yves Chibon 73d120
            },
Pierre-Yves Chibon 73d120
            "user": {
Pierre-Yves Chibon 73d120
                "fullname": "PY C",
Pierre-Yves Chibon 73d120
                "name": "pingou",
Pierre-Yves Chibon 73d120
                "avatar_url": "https://seccdn.libravatar.org/avatar/...",
Pierre-Yves Chibon 73d120
            },
Pierre-Yves Chibon 73d120
        }
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Ryan Lerch 36ee38
        data["user"]["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
Pierre-Yves Chibon 73d120
        for k in ["forks_pagination", "repos_pagination"]:
Pierre-Yves Chibon 73d120
            for k2 in ["first", "last"]:
Pierre-Yves Chibon 610db7
                self.assertIsNotNone(data[k][k2])
Pierre-Yves Chibon 73d120
                data[k][k2] = "http://localhost..."
Clement Verna 8ed9ee
        self.assertEqual(data, exp)
Clement Verna 8ed9ee
Clement Verna 8ed9ee
    def test_api_view_user_with_project(self):
Clement Verna 8ed9ee
        """
Clement Verna 8ed9ee
            Test the api_view_user method of the flask api,
Clement Verna 8ed9ee
            this time the user has some project defined.
Clement Verna 8ed9ee
        """
Clement Verna 8ed9ee
        tests.create_projects(self.session)
Clement Verna 8ed9ee
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/user/pingou")
Clement Verna 8ed9ee
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        data["repos"][0]["date_created"] = "1490272832"
Pierre-Yves Chibon 73d120
        data["repos"][0]["date_modified"] = "1490272832"
Pierre-Yves Chibon 73d120
        data["repos"][1]["date_created"] = "1490272832"
Pierre-Yves Chibon 73d120
        data["repos"][1]["date_modified"] = "1490272832"
Pierre-Yves Chibon 73d120
        data["repos"][2]["date_created"] = "1490272832"
Pierre-Yves Chibon 73d120
        data["repos"][2]["date_modified"] = "1490272832"
Pierre-Yves Chibon 73d120
        for k in ["forks_pagination", "repos_pagination"]:
Pierre-Yves Chibon 73d120
            for k2 in ["first", "last"]:
Pierre-Yves Chibon 610db7
                self.assertIsNotNone(data[k][k2])
Pierre-Yves Chibon 73d120
                data[k][k2] = "http://localhost..."
Matt Prahl 6bf79a
        expected_data = {
Clement Verna 8ed9ee
            "forks": [],
Pierre-Yves Chibon 73d120
            "forks_pagination": {
Pierre-Yves Chibon 73d120
                "first": "http://localhost...",
Pierre-Yves Chibon 73d120
                "last": "http://localhost...",
Pierre-Yves Chibon 73d120
                "next": None,
Pierre-Yves Chibon 73d120
                "forkpage": 1,
Pierre-Yves Chibon 73d120
                "pages": 0,
Pierre-Yves Chibon 73d120
                "per_page": 20,
Pierre-Yves Chibon 73d120
                "prev": None,
Pierre-Yves Chibon 73d120
            },
Pierre-Yves Chibon c9e619
            "repos": [
Pierre-Yves Chibon c9e619
                {
Pierre-Yves Chibon 73d120
                    "access_groups": {"admin": [], "commit": [], "ticket": []},
Matt Prahl 6bf79a
                    "access_users": {
Matt Prahl 6bf79a
                        "admin": [],
Matt Prahl 6bf79a
                        "commit": [],
Matt Prahl 6bf79a
                        "owner": ["pingou"],
Pierre-Yves Chibon 73d120
                        "ticket": [],
Matt Prahl 6bf79a
                    },
Matt Prahl 6bf79a
                    "close_status": [
Matt Prahl 6bf79a
                        "Invalid",
Matt Prahl 6bf79a
                        "Insufficient data",
Matt Prahl 6bf79a
                        "Fixed",
Pierre-Yves Chibon 73d120
                        "Duplicate",
Matt Prahl 6bf79a
                    ],
Matt Prahl 6bf79a
                    "custom_keys": [],
Matt Prahl 6bf79a
                    "date_created": "1490272832",
Clement Verna cd6e30
                    "date_modified": "1490272832",
Matt Prahl 6bf79a
                    "description": "test project #1",
Matt Prahl 6bf79a
                    "fullname": "test",
Pierre-Yves Chibon 469e24
                    "url_path": "test",
Matt Prahl 6bf79a
                    "id": 1,
Matt Prahl 6bf79a
                    "milestones": {},
Matt Prahl 6bf79a
                    "name": "test",
Matt Prahl 6bf79a
                    "namespace": None,
Matt Prahl 6bf79a
                    "parent": None,
Matt Prahl 6bf79a
                    "priorities": {},
Matt Prahl 6bf79a
                    "tags": [],
Pierre-Yves Chibon 73d120
                    "user": {"fullname": "PY C", "name": "pingou"},
Clement Verna 8ed9ee
                },
Clement Verna 8ed9ee
                {
Pierre-Yves Chibon 73d120
                    "access_groups": {"admin": [], "commit": [], "ticket": []},
Matt Prahl 6bf79a
                    "access_users": {
Matt Prahl 6bf79a
                        "admin": [],
Matt Prahl 6bf79a
                        "commit": [],
Matt Prahl 6bf79a
                        "owner": ["pingou"],
Pierre-Yves Chibon 73d120
                        "ticket": [],
Matt Prahl 6bf79a
                    },
Matt Prahl 6bf79a
                    "close_status": [
Matt Prahl 6bf79a
                        "Invalid",
Matt Prahl 6bf79a
                        "Insufficient data",
Matt Prahl 6bf79a
                        "Fixed",
Pierre-Yves Chibon 73d120
                        "Duplicate",
Matt Prahl 6bf79a
                    ],
Matt Prahl 6bf79a
                    "custom_keys": [],
Matt Prahl 6bf79a
                    "date_created": "1490272832",
Clement Verna cd6e30
                    "date_modified": "1490272832",
Matt Prahl 6bf79a
                    "description": "test project #2",
Matt Prahl 6bf79a
                    "fullname": "test2",
Pierre-Yves Chibon 469e24
                    "url_path": "test2",
Matt Prahl 6bf79a
                    "id": 2,
Matt Prahl 6bf79a
                    "milestones": {},
Matt Prahl 6bf79a
                    "name": "test2",
Matt Prahl 6bf79a
                    "namespace": None,
Matt Prahl 6bf79a
                    "parent": None,
Matt Prahl 6bf79a
                    "priorities": {},
Matt Prahl 6bf79a
                    "tags": [],
Pierre-Yves Chibon 73d120
                    "user": {"fullname": "PY C", "name": "pingou"},
Clement Verna 8ed9ee
                },
Clement Verna 8ed9ee
                {
Pierre-Yves Chibon 73d120
                    "access_groups": {"admin": [], "commit": [], "ticket": []},
Matt Prahl 6bf79a
                    "access_users": {
Matt Prahl 6bf79a
                        "admin": [],
Matt Prahl 6bf79a
                        "commit": [],
Matt Prahl 6bf79a
                        "owner": ["pingou"],
Pierre-Yves Chibon 73d120
                        "ticket": [],
Matt Prahl 6bf79a
                    },
Matt Prahl 6bf79a
                    "close_status": [
Matt Prahl 6bf79a
                        "Invalid",
Matt Prahl 6bf79a
                        "Insufficient data",
Matt Prahl 6bf79a
                        "Fixed",
Pierre-Yves Chibon 73d120
                        "Duplicate",
Matt Prahl 6bf79a
                    ],
Matt Prahl 6bf79a
                    "custom_keys": [],
Matt Prahl 6bf79a
                    "date_created": "1490272832",
Clement Verna cd6e30
                    "date_modified": "1490272832",
Matt Prahl 6bf79a
                    "description": "namespaced test project",
Matt Prahl 6bf79a
                    "fullname": "somenamespace/test3",
Pierre-Yves Chibon 469e24
                    "url_path": "somenamespace/test3",
Matt Prahl 6bf79a
                    "id": 3,
Matt Prahl 6bf79a
                    "milestones": {},
Matt Prahl 6bf79a
                    "name": "test3",
Matt Prahl 6bf79a
                    "namespace": "somenamespace",
Matt Prahl 6bf79a
                    "parent": None,
Matt Prahl 6bf79a
                    "priorities": {},
Matt Prahl 6bf79a
                    "tags": [],
Pierre-Yves Chibon 73d120
                    "user": {"fullname": "PY C", "name": "pingou"},
Pierre-Yves Chibon 73d120
                },
Clement Verna 8ed9ee
            ],
Pierre-Yves Chibon 73d120
            "repos_pagination": {
Pierre-Yves Chibon 73d120
                "first": "http://localhost...",
Pierre-Yves Chibon 73d120
                "last": "http://localhost...",
Pierre-Yves Chibon 73d120
                "next": None,
Pierre-Yves Chibon 73d120
                "repopage": 1,
Pierre-Yves Chibon 73d120
                "pages": 1,
Pierre-Yves Chibon 73d120
                "per_page": 20,
Pierre-Yves Chibon 73d120
                "prev": None,
Pierre-Yves Chibon 73d120
            },
Clement Verna 8ed9ee
            "user": {
Clement Verna 8ed9ee
                "fullname": "PY C",
Ryan Lerch 36ee38
                "name": "pingou",
Pierre-Yves Chibon 73d120
                "avatar_url": "https://seccdn.libravatar.org/avatar/...",
Pierre-Yves Chibon 73d120
            },
Clement Verna 8ed9ee
        }
Ryan Lerch 36ee38
        data["user"]["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
Matt Prahl 6bf79a
        self.assertEqual(data, expected_data)
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Pierre-Yves Chibon 8fc633
    def test_api_view_user_activity_stats(self, mockemail):
Pierre-Yves Chibon 8fc633
        """ Test the api_view_user_activity_stats method of the flask user
Pierre-Yves Chibon 8fc633
        api. """
Pierre-Yves Chibon 8fc633
        mockemail.return_value = True
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
        tests.create_projects(self.session)
Pierre-Yves Chibon 8fc633
        tests.create_tokens(self.session)
Pierre-Yves Chibon 8fc633
        tests.create_tokens_acl(self.session)
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 73d120
        headers = {"Authorization": "token aaabbbcccddd"}
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
        # Create a pull-request
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query._get_project(self.session, "test")
Pierre-Yves Chibon 73d120
        forked_repo = pagure.lib.query._get_project(self.session, "test")
Pierre-Yves Chibon 930073
        req = pagure.lib.query.new_pull_request(
Pierre-Yves Chibon 8fc633
            session=self.session,
Pierre-Yves Chibon 8fc633
            repo_from=forked_repo,
Pierre-Yves Chibon 73d120
            branch_from="master",
Pierre-Yves Chibon 8fc633
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="test pull-request",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 8fc633
        )
Pierre-Yves Chibon 8fc633
        self.session.commit()
Pierre-Yves Chibon 8fc633
        self.assertEqual(req.id, 1)
Pierre-Yves Chibon 73d120
        self.assertEqual(req.title, "test pull-request")
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
        # Check comments before
Aurélien Bompard 13bcde
        self.session.commit()
Pierre-Yves Chibon 930073
        request = pagure.lib.query.search_pull_requests(
Pierre-Yves Chibon 73d120
            self.session, project_id=1, requestid=1
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 8fc633
        self.assertEqual(len(request.comments), 0)
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 73d120
        data = {"comment": "This is a very interesting question"}
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
        # Valid request
Pierre-Yves Chibon 8fc633
        output = self.app.post(
Pierre-Yves Chibon 73d120
            "/api/0/test/pull-request/1/comment", data=data, headers=headers
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 8fc633
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertDictEqual(data, {"message": "Comment added"})
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
        # One comment added
Aurélien Bompard 13bcde
        self.session.commit()
Pierre-Yves Chibon 930073
        request = pagure.lib.query.search_pull_requests(
Pierre-Yves Chibon 73d120
            self.session, project_id=1, requestid=1
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 8fc633
        self.assertEqual(len(request.comments), 1)
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
        # Close PR
Pierre-Yves Chibon 8fc633
        output = self.app.post(
Pierre-Yves Chibon 73d120
            "/api/0/test/pull-request/1/close", headers=headers
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 8fc633
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertDictEqual(data, {"message": "Pull-request closed!"})
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
        # PR closed
Aurélien Bompard 13bcde
        self.session.commit()
Pierre-Yves Chibon 930073
        request = pagure.lib.query.search_pull_requests(
Pierre-Yves Chibon 73d120
            self.session, project_id=1, requestid=1
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(request.status, "Closed")
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
        # Finally retrieve the user's logs
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/user/pingou/activity/stats")
Pierre-Yves Chibon 8fc633
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        date = datetime.datetime.utcnow().date().strftime("%Y-%m-%d")
Pierre-Yves Chibon a8e4e9
        self.assertDictEqual(data, {date: 4})
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Pierre-Yves Chibon 8fc633
    def test_api_view_user_activity_date(self, mockemail):
Pierre-Yves Chibon 8fc633
        """ Test the api_view_user_activity_date method of the flask user
Pierre-Yves Chibon 8fc633
        api. """
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
        self.test_api_view_user_activity_stats()
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon fa2aba
        # Invalid date
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/user/pingou/activity/AABB")
Pierre-Yves Chibon fa2aba
        self.assertEqual(output.status_code, 400)
Pierre-Yves Chibon fa2aba
Pierre-Yves Chibon fa2aba
        # Invalid date
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/user/pingou/activity/2016asd")
Pierre-Yves Chibon fa2aba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 73d120
        exp = {"activities": [], "date": "2016-01-01"}
Aurélien Bompard 626417
        self.assertEqual(json.loads(output.get_data(as_text=True)), exp)
Pierre-Yves Chibon fa2aba
Pierre-Yves Chibon fa2aba
        # Date parsed, just not really as expected
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/user/pingou/activity/20161245")
Pierre-Yves Chibon fa2aba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 73d120
        exp = {"activities": [], "date": "1970-08-22"}
Aurélien Bompard 626417
        self.assertEqual(json.loads(output.get_data(as_text=True)), exp)
Pierre-Yves Chibon fa2aba
Pierre-Yves Chibon 73d120
        date = datetime.datetime.utcnow().date().strftime("%Y-%m-%d")
Pierre-Yves Chibon 8fc633
        # Retrieve the user's logs for today
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/user/pingou/activity/%s" % date)
Pierre-Yves Chibon 8fc633
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 8fc633
        exp = {
Pierre-Yves Chibon 73d120
            "activities": [
Pierre-Yves Chibon 73d120
                {
Pierre-Yves Chibon 73d120
                    "date": date,
Pierre-Yves Chibon 73d120
                    "date_created": "1477558752",
Pierre-Yves Chibon 73d120
                    "type": "pull-request",
Julen Landa Alustiza 40c5e4
                    "description_mk": '

pingou created PR test#1

',
Pierre-Yves Chibon 73d120
                    "id": 1,
Pierre-Yves Chibon 73d120
                    "ref_id": "1",
Pierre-Yves Chibon 73d120
                    "type": "created",
Pierre-Yves Chibon 73d120
                    "user": {"fullname": "PY C", "name": "pingou"},
Pierre-Yves Chibon 73d120
                },
Pierre-Yves Chibon 73d120
                {
Pierre-Yves Chibon 73d120
                    "date": date,
Pierre-Yves Chibon 73d120
                    "date_created": "1477558752",
Pierre-Yves Chibon 73d120
                    "type": "pull-request",
Julen Landa Alustiza 40c5e4
                    "description_mk": '

pingou commented on PR test#1

',
Pierre-Yves Chibon 73d120
                    "id": 2,
Pierre-Yves Chibon 73d120
                    "ref_id": "1",
Pierre-Yves Chibon 73d120
                    "type": "commented",
Pierre-Yves Chibon 73d120
                    "user": {"fullname": "PY C", "name": "pingou"},
Pierre-Yves Chibon 73d120
                },
Pierre-Yves Chibon 73d120
                {
Pierre-Yves Chibon 73d120
                    "date": date,
Pierre-Yves Chibon 73d120
                    "date_created": "1477558752",
Pierre-Yves Chibon 73d120
                    "type": "pull-request",
Julen Landa Alustiza 40c5e4
                    "description_mk": '

pingou closed PR test#1

',
Pierre-Yves Chibon 73d120
                    "id": 3,
Pierre-Yves Chibon 73d120
                    "ref_id": "1",
Pierre-Yves Chibon 73d120
                    "type": "closed",
Pierre-Yves Chibon 73d120
                    "user": {"fullname": "PY C", "name": "pingou"},
Pierre-Yves Chibon 73d120
                },
Pierre-Yves Chibon 73d120
                {
Pierre-Yves Chibon 73d120
                    "date": date,
Pierre-Yves Chibon 73d120
                    "date_created": "1477558752",
Pierre-Yves Chibon 73d120
                    "type": "pull-request",
Julen Landa Alustiza 40c5e4
                    "description_mk": '

pingou commented on PR test#1

',
Pierre-Yves Chibon 73d120
                    "id": 4,
Pierre-Yves Chibon 73d120
                    "ref_id": "1",
Pierre-Yves Chibon 73d120
                    "type": "commented",
Pierre-Yves Chibon 73d120
                    "user": {"fullname": "PY C", "name": "pingou"},
Pierre-Yves Chibon 73d120
                },
Pierre-Yves Chibon 73d120
            ],
Pierre-Yves Chibon 73d120
            "date": date,
Pierre-Yves Chibon 8fc633
        }
Pierre-Yves Chibon 73d120
        for idx, act in enumerate(data["activities"]):
Pierre-Yves Chibon 73d120
            act["date_created"] = "1477558752"
Pierre-Yves Chibon 73d120
            data["activities"][idx] = act
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 8fc633
        self.assertEqual(data, exp)
Pierre-Yves Chibon 8fc633
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Pierre-Yves Chibon d6ddc4
    def test_api_view_user_activity_date_1_activity(self, mockemail):
Pierre-Yves Chibon d6ddc4
        """ Test the api_view_user_activity_date method of the flask user
Pierre-Yves Chibon d6ddc4
        api when the user only did one action. """
Pierre-Yves Chibon d6ddc4
Pierre-Yves Chibon d6ddc4
        tests.create_projects(self.session)
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query._get_project(self.session, "test")
Pierre-Yves Chibon d6ddc4
Pierre-Yves Chibon d6ddc4
        now = datetime.datetime.utcnow()
Pierre-Yves Chibon 73d120
        date = now.date().strftime("%Y-%m-%d")
Pierre-Yves Chibon d6ddc4
        # Create a single commit log
Pierre-Yves Chibon d6ddc4
        log = model.PagureLog(
Pierre-Yves Chibon d6ddc4
            user_id=1,
Pierre-Yves Chibon 73d120
            user_email="foo@bar.com",
Pierre-Yves Chibon d6ddc4
            project_id=1,
Pierre-Yves Chibon 73d120
            log_type="committed",
Pierre-Yves Chibon 73d120
            ref_id="githash",
Pierre-Yves Chibon d6ddc4
            date=now.date(),
Pierre-Yves Chibon 73d120
            date_created=now,
Pierre-Yves Chibon d6ddc4
        )
Pierre-Yves Chibon d6ddc4
        self.session.add(log)
Pierre-Yves Chibon d6ddc4
        self.session.commit()
Pierre-Yves Chibon d6ddc4
Pierre-Yves Chibon d6ddc4
        # Retrieve the user's logs for today
Pierre-Yves Chibon d6ddc4
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/activity/%s?grouped=1" % date
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon d6ddc4
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon d6ddc4
        exp = {
Pierre-Yves Chibon 73d120
            "activities": [
Julen Landa Alustiza 0cafab
                {
Julen Landa Alustiza 0cafab
                    "description_mk": '

pingou committed on test#githash

'
Julen Landa Alustiza 0cafab
                }
Pierre-Yves Chibon 73d120
            ],
Pierre-Yves Chibon 73d120
            "date": date,
Pierre-Yves Chibon d6ddc4
        }
Pierre-Yves Chibon d6ddc4
        self.assertEqual(data, exp)
Pierre-Yves Chibon d6ddc4
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Adam Williamson f99ac7
    def test_api_view_user_activity_timezone_negative(self, mockemail):
Adam Williamson 8a161a
        """Test api_view_user_activity{_stats,_date} with the America/
Adam Williamson 8a161a
        New York timezone, which is 5 hours behind UTC in winter and
Adam Williamson 8a161a
        4 hours behind UTC in summer (daylight savings). The events
Pierre-Yves Chibon 219e3b
        will occur on XXXX-02-15 in UTC, but on XXXX-02-14 local.
Adam Williamson f99ac7
        """
Adam Williamson f99ac7
        tests.create_projects(self.session)
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query._get_project(self.session, "test")
Adam Williamson f99ac7
Pierre-Yves Chibon 219e3b
        today = datetime.datetime.utcnow().date()
Pierre-Yves Chibon 219e3b
        year = today.year
Pierre-Yves Chibon 73d120
        if today.year == 2 and today.date <= 15:
Pierre-Yves Chibon 219e3b
            year = year - 1
Pierre-Yves Chibon 219e3b
        elif today.year < 2:
Pierre-Yves Chibon 219e3b
            year = year - 1
Pierre-Yves Chibon 219e3b
        dateobj = datetime.datetime(year, 2, 15, 3, 30)
Pierre-Yves Chibon 73d120
        utcdate = "%s-02-15" % year
Pierre-Yves Chibon 219e3b
        # the Unix timestamp for YYYY-02-15 12:00 UTC
Pierre-Yves Chibon 73d120
        utcts = str(
Pierre-Yves Chibon 73d120
            int(
Pierre-Yves Chibon 73d120
                (
Pierre-Yves Chibon 73d120
                    datetime.datetime(year, 2, 15, 12, 0, tzinfo=pytz.UTC)
Pierre-Yves Chibon 73d120
                    - datetime.datetime(1970, 1, 1, tzinfo=pytz.UTC)
Pierre-Yves Chibon 73d120
                ).total_seconds()
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        localdate = "%s-02-14" % today.year
Pierre-Yves Chibon 219e3b
        # the Unix timestamp for YYYY-02-15 18:00 America/New_York
Pierre-Yves Chibon 73d120
        localts = str(
Pierre-Yves Chibon 73d120
            int(
Pierre-Yves Chibon 73d120
                (
Pierre-Yves Chibon 73d120
                    datetime.datetime(
Pierre-Yves Chibon 73d120
                        year,
Pierre-Yves Chibon 73d120
                        2,
Pierre-Yves Chibon 73d120
                        14,
Pierre-Yves Chibon 73d120
                        17,
Pierre-Yves Chibon 73d120
                        0,
Pierre-Yves Chibon 73d120
                        tzinfo=pytz.timezone("America/New_York"),
Pierre-Yves Chibon 73d120
                    )
Pierre-Yves Chibon 73d120
                    - datetime.datetime(
Pierre-Yves Chibon 73d120
                        1970, 1, 1, tzinfo=pytz.timezone("America/New_York")
Pierre-Yves Chibon 73d120
                    )
Pierre-Yves Chibon 73d120
                ).total_seconds()
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Adam Williamson f99ac7
        # Create a single commit log
Adam Williamson f99ac7
        log = model.PagureLog(
Adam Williamson f99ac7
            user_id=1,
Pierre-Yves Chibon 73d120
            user_email="foo@bar.com",
Adam Williamson f99ac7
            project_id=1,
Pierre-Yves Chibon 73d120
            log_type="committed",
Pierre-Yves Chibon 73d120
            ref_id="githash",
Adam Williamson f99ac7
            date=dateobj.date(),
Pierre-Yves Chibon 73d120
            date_created=dateobj,
Adam Williamson f99ac7
        )
Adam Williamson f99ac7
        self.session.add(log)
Adam Williamson f99ac7
        self.session.commit()
Adam Williamson f99ac7
Adam Williamson 8a161a
        # Retrieve the user's stats with no timezone specified (==UTC)
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/user/pingou/activity/stats")
Adam Williamson f99ac7
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Adam Williamson f99ac7
        # date in output should be UTC date
Adam Williamson f99ac7
        self.assertDictEqual(data, {utcdate: 1})
Adam Williamson 8a161a
        # Now in timestamp format...
Pierre-Yves Chibon 73d120
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/activity/stats?format=timestamp"
Pierre-Yves Chibon 73d120
        )
Adam Williamson 8a161a
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Adam Williamson 8a161a
        # timestamp in output should be UTC ts
Adam Williamson 8a161a
        self.assertDictEqual(data, {utcts: 1})
Adam Williamson f99ac7
Adam Williamson 8a161a
        # Retrieve the user's stats with local timezone specified
Pierre-Yves Chibon 73d120
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/activity/stats?tz=America/New_York"
Pierre-Yves Chibon 73d120
        )
Adam Williamson f99ac7
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Adam Williamson f99ac7
        # date in output should be local date
Adam Williamson f99ac7
        self.assertDictEqual(data, {localdate: 1})
Adam Williamson 8a161a
        # Now in timestamp format...
Pierre-Yves Chibon 73d120
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/activity/stats?format=timestamp&tz=America/New_York"
Pierre-Yves Chibon 73d120
        )
Adam Williamson 8a161a
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Adam Williamson 8a161a
        # timestamp in output should be local ts
Adam Williamson 8a161a
        self.assertDictEqual(data, {localts: 1})
Adam Williamson f99ac7
Adam Williamson 8a161a
        # Retrieve the user's logs for 2018-02-15 with no timezone
Adam Williamson f99ac7
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/activity/%s?grouped=1" % utcdate
Pierre-Yves Chibon 73d120
        )
Adam Williamson f99ac7
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Adam Williamson f99ac7
        exp = {
Pierre-Yves Chibon 73d120
            "activities": [
Julen Landa Alustiza 0cafab
                {
Julen Landa Alustiza 0cafab
                    "description_mk": '

pingou committed on test#githash

'
Julen Landa Alustiza 0cafab
                }
Pierre-Yves Chibon 73d120
            ],
Pierre-Yves Chibon 73d120
            "date": utcdate,
Adam Williamson f99ac7
        }
Adam Williamson f99ac7
        self.assertEqual(data, exp)
Adam Williamson f99ac7
Adam Williamson 8a161a
        # Now retrieve the user's logs for 2018-02-14 with local time
Adam Williamson f99ac7
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/activity/%s?grouped=1&tz=America/New_York"
Pierre-Yves Chibon 73d120
            % localdate
Pierre-Yves Chibon 73d120
        )
Adam Williamson f99ac7
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        exp["date"] = localdate
Adam Williamson f99ac7
        self.assertEqual(data, exp)
Adam Williamson f99ac7
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Adam Williamson f99ac7
    def test_api_view_user_activity_timezone_positive(self, mockemail):
Adam Williamson 8a161a
        """Test api_view_user_activity{_stats,_date} with the Asia/
Adam Williamson 8a161a
        Dubai timezone, which is 4 hours ahead of UTC. The events will
Pierre-Yves Chibon 219e3b
        occur on XXXX-02-15 in UTC, but on XXXX-02-16 in local time.
Adam Williamson f99ac7
        """
Adam Williamson f99ac7
        tests.create_projects(self.session)
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query._get_project(self.session, "test")
Adam Williamson f99ac7
Pierre-Yves Chibon 219e3b
        today = datetime.datetime.utcnow().date()
Pierre-Yves Chibon 219e3b
        year = today.year
Pierre-Yves Chibon 73d120
        if today.year == 2 and today.date <= 15:
Pierre-Yves Chibon 219e3b
            year = year - 1
Pierre-Yves Chibon 219e3b
        elif today.year < 2:
Pierre-Yves Chibon 219e3b
            year = year - 1
Pierre-Yves Chibon 219e3b
        dateobj = datetime.datetime(year, 2, 15, 22, 30)
Pierre-Yves Chibon 73d120
        utcdate = "%s-02-15" % year
Pierre-Yves Chibon 219e3b
        # the Unix timestamp for YYYY-02-15 12:00 UTC
Pierre-Yves Chibon 73d120
        utcts = str(
Pierre-Yves Chibon 73d120
            int(
Pierre-Yves Chibon 73d120
                (
Pierre-Yves Chibon 73d120
                    datetime.datetime(year, 2, 15, 12, 0, tzinfo=pytz.UTC)
Pierre-Yves Chibon 73d120
                    - datetime.datetime(1970, 1, 1, tzinfo=pytz.UTC)
Pierre-Yves Chibon 73d120
                ).total_seconds()
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        localdate = "%s-02-16" % year
Pierre-Yves Chibon 219e3b
        # the Unix timestamp for YYYY-02-16 9:00 Asia/Dubai
Pierre-Yves Chibon 73d120
        localts = str(
Pierre-Yves Chibon 73d120
            int(
Pierre-Yves Chibon 73d120
                (
Pierre-Yves Chibon 73d120
                    datetime.datetime(
Pierre-Yves Chibon 73d120
                        year, 2, 16, 8, 0, tzinfo=pytz.timezone("Asia/Dubai")
Pierre-Yves Chibon 73d120
                    )
Pierre-Yves Chibon 73d120
                    - datetime.datetime(
Pierre-Yves Chibon 73d120
                        1970, 1, 1, tzinfo=pytz.timezone("Asia/Dubai")
Pierre-Yves Chibon 73d120
                    )
Pierre-Yves Chibon 73d120
                ).total_seconds()
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Adam Williamson f99ac7
        # Create a single commit log
Adam Williamson f99ac7
        log = model.PagureLog(
Adam Williamson f99ac7
            user_id=1,
Pierre-Yves Chibon 73d120
            user_email="foo@bar.com",
Adam Williamson f99ac7
            project_id=1,
Pierre-Yves Chibon 73d120
            log_type="committed",
Pierre-Yves Chibon 73d120
            ref_id="githash",
Adam Williamson f99ac7
            date=dateobj.date(),
Pierre-Yves Chibon 73d120
            date_created=dateobj,
Adam Williamson f99ac7
        )
Adam Williamson f99ac7
        self.session.add(log)
Adam Williamson f99ac7
        self.session.commit()
Adam Williamson f99ac7
Adam Williamson 8a161a
        # Retrieve the user's stats with no timezone specified (==UTC)
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/user/pingou/activity/stats")
Adam Williamson f99ac7
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Adam Williamson f99ac7
        # date in output should be UTC date
Adam Williamson f99ac7
        self.assertDictEqual(data, {utcdate: 1})
Adam Williamson 8a161a
        # Now in timestamp format...
Pierre-Yves Chibon 73d120
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/activity/stats?format=timestamp"
Pierre-Yves Chibon 73d120
        )
Adam Williamson 8a161a
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Adam Williamson 8a161a
        # timestamp in output should be UTC ts
Adam Williamson 8a161a
        self.assertDictEqual(data, {utcts: 1})
Adam Williamson f99ac7
Adam Williamson 8a161a
        # Retrieve the user's stats with local timezone specified
Pierre-Yves Chibon 73d120
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/activity/stats?tz=Asia/Dubai"
Pierre-Yves Chibon 73d120
        )
Adam Williamson f99ac7
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Adam Williamson f99ac7
        # date in output should be local date
Adam Williamson f99ac7
        self.assertDictEqual(data, {localdate: 1})
Adam Williamson 8a161a
        # Now in timestamp format...
Pierre-Yves Chibon 73d120
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/activity/stats?format=timestamp&tz=Asia/Dubai"
Pierre-Yves Chibon 73d120
        )
Adam Williamson 8a161a
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Adam Williamson 8a161a
        # timestamp in output should be local ts
Adam Williamson 8a161a
        self.assertDictEqual(data, {localts: 1})
Adam Williamson f99ac7
Adam Williamson 8a161a
        # Retrieve the user's logs for 2018-02-15 with no timezone
Adam Williamson f99ac7
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/activity/%s?grouped=1" % utcdate
Pierre-Yves Chibon 73d120
        )
Adam Williamson f99ac7
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Adam Williamson f99ac7
        exp = {
Pierre-Yves Chibon 73d120
            "activities": [
Julen Landa Alustiza 0cafab
                {
Julen Landa Alustiza 0cafab
                    "description_mk": '

pingou committed on test#githash

'
Julen Landa Alustiza 0cafab
                }
Pierre-Yves Chibon 73d120
            ],
Pierre-Yves Chibon 73d120
            "date": utcdate,
Adam Williamson f99ac7
        }
Adam Williamson f99ac7
        self.assertEqual(data, exp)
Adam Williamson f99ac7
Adam Williamson 8a161a
        # Now retrieve the user's logs for 2018-02-16 with local time
Adam Williamson f99ac7
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/activity/%s?grouped=1&tz=Asia/Dubai"
Pierre-Yves Chibon 73d120
            % localdate
Pierre-Yves Chibon 73d120
        )
Adam Williamson f99ac7
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        exp["date"] = localdate
Adam Williamson f99ac7
        self.assertEqual(data, exp)
Adam Williamson f99ac7
Pierre-Yves Chibon 8fc633
Ryan Lerch 397681
class PagureFlaskApiUsertestrequests(tests.Modeltests):
Ryan Lerch 397681
    """ Tests for the user requests endpoints """
Ryan Lerch 397681
Ryan Lerch 397681
    maxDiff = None
Ryan Lerch 397681
Ryan Lerch 397681
    def setUp(self):
Ryan Lerch 397681
        """ Set up the environnment, ran before every tests. """
Ryan Lerch 397681
        super(PagureFlaskApiUsertestrequests, self).setUp()
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        pagure.config.config["REQUESTS_FOLDER"] = None
Ryan Lerch 397681
Ryan Lerch 397681
        tests.create_projects(self.session)
Ryan Lerch 397681
Ryan Lerch 397681
        # Create few pull-requests
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon 73d120
        forked_repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 930073
        pagure.lib.query.new_pull_request(
Ryan Lerch 397681
            session=self.session,
Ryan Lerch 397681
            repo_from=forked_repo,
Pierre-Yves Chibon 73d120
            branch_from="master",
Ryan Lerch 397681
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="open pullrequest by user foo on repo test",
Pierre-Yves Chibon 73d120
            user="foo",
Ryan Lerch 397681
        )
Pierre-Yves Chibon 65d34a
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test2")
Pierre-Yves Chibon 73d120
        forked_repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test2"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 930073
        pagure.lib.query.new_pull_request(
Ryan Lerch 397681
            session=self.session,
Ryan Lerch 397681
            repo_from=forked_repo,
Pierre-Yves Chibon 73d120
            branch_from="master",
Ryan Lerch 397681
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="open pullrequest by user foo on repo test2",
Pierre-Yves Chibon 73d120
            user="foo",
Ryan Lerch 397681
        )
Ryan Lerch 397681
        self.session.commit()
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon 73d120
        forked_repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 930073
        pagure.lib.query.new_pull_request(
Ryan Lerch 397681
            session=self.session,
Ryan Lerch 397681
            repo_from=forked_repo,
Pierre-Yves Chibon 73d120
            branch_from="master",
Ryan Lerch 397681
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="closed pullrequest by user foo on repo test",
Pierre-Yves Chibon 73d120
            user="foo",
Pierre-Yves Chibon 73d120
            status="Closed",
Ryan Lerch 397681
        )
Pierre-Yves Chibon 65d34a
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test2")
Pierre-Yves Chibon 73d120
        forked_repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test2"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 930073
        pagure.lib.query.new_pull_request(
Ryan Lerch 397681
            session=self.session,
Ryan Lerch 397681
            repo_from=forked_repo,
Pierre-Yves Chibon 73d120
            branch_from="master",
Ryan Lerch 397681
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="closed pullrequest by user foo on repo test2",
Pierre-Yves Chibon 73d120
            user="foo",
Pierre-Yves Chibon 73d120
            status="Closed",
Ryan Lerch 397681
        )
Ryan Lerch 397681
        self.session.commit()
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon 73d120
        forked_repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 930073
        pagure.lib.query.new_pull_request(
Ryan Lerch 397681
            session=self.session,
Ryan Lerch 397681
            repo_from=forked_repo,
Pierre-Yves Chibon 73d120
            branch_from="master",
Ryan Lerch 397681
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="merged pullrequest by user foo on repo test",
Pierre-Yves Chibon 73d120
            user="foo",
Pierre-Yves Chibon 73d120
            status="Merged",
Ryan Lerch 397681
        )
Pierre-Yves Chibon 65d34a
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test2")
Pierre-Yves Chibon 73d120
        forked_repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test2"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 930073
        pagure.lib.query.new_pull_request(
Ryan Lerch 397681
            session=self.session,
Ryan Lerch 397681
            repo_from=forked_repo,
Pierre-Yves Chibon 73d120
            branch_from="master",
Ryan Lerch 397681
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="merged pullrequest by user foo on repo test2",
Pierre-Yves Chibon 73d120
            user="foo",
Pierre-Yves Chibon 73d120
            status="Merged",
Ryan Lerch 397681
        )
Ryan Lerch 397681
        self.session.commit()
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon 73d120
        forked_repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 930073
        pagure.lib.query.new_pull_request(
Ryan Lerch 397681
            session=self.session,
Ryan Lerch 397681
            repo_from=forked_repo,
Pierre-Yves Chibon 73d120
            branch_from="master",
Ryan Lerch 397681
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="open pullrequest by user pingou on repo test",
Pierre-Yves Chibon 73d120
            user="pingou",
Ryan Lerch 397681
        )
Ryan Lerch 397681
        self.session.commit()
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test2")
Pierre-Yves Chibon 73d120
        forked_repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test2"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 930073
        pagure.lib.query.new_pull_request(
Ryan Lerch 397681
            session=self.session,
Ryan Lerch 397681
            repo_from=forked_repo,
Pierre-Yves Chibon 73d120
            branch_from="master",
Ryan Lerch 397681
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="open pullrequest by user pingou on repo test2",
Pierre-Yves Chibon 73d120
            user="pingou",
Ryan Lerch 397681
        )
Ryan Lerch 397681
        self.session.commit()
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon 73d120
        forked_repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 930073
        pagure.lib.query.new_pull_request(
Ryan Lerch 397681
            session=self.session,
Ryan Lerch 397681
            repo_from=forked_repo,
Pierre-Yves Chibon 73d120
            branch_from="master",
Ryan Lerch 397681
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="closed pullrequest by user pingou on repo test",
Pierre-Yves Chibon 73d120
            user="pingou",
Ryan Lerch 397681
            status="Closed",
Ryan Lerch 397681
        )
Ryan Lerch 397681
        self.session.commit()
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test2")
Pierre-Yves Chibon 73d120
        forked_repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test2"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 930073
        pagure.lib.query.new_pull_request(
Ryan Lerch 397681
            session=self.session,
Ryan Lerch 397681
            repo_from=forked_repo,
Pierre-Yves Chibon 73d120
            branch_from="master",
Ryan Lerch 397681
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="closed pullrequest by user pingou on repo test2",
Pierre-Yves Chibon 73d120
            user="pingou",
Ryan Lerch 397681
            status="Closed",
Ryan Lerch 397681
        )
Ryan Lerch 397681
        self.session.commit()
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon 73d120
        forked_repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 930073
        pagure.lib.query.new_pull_request(
Ryan Lerch 397681
            session=self.session,
Ryan Lerch 397681
            repo_from=forked_repo,
Pierre-Yves Chibon 73d120
            branch_from="master",
Ryan Lerch 397681
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="merged pullrequest by user pingou on repo test",
Pierre-Yves Chibon 73d120
            user="pingou",
Ryan Lerch 397681
            status="Merged",
Ryan Lerch 397681
        )
Ryan Lerch 397681
        self.session.commit()
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test2")
Pierre-Yves Chibon 73d120
        forked_repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
            self.session, "test2"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 930073
        pagure.lib.query.new_pull_request(
Ryan Lerch 397681
            session=self.session,
Ryan Lerch 397681
            repo_from=forked_repo,
Pierre-Yves Chibon 73d120
            branch_from="master",
Ryan Lerch 397681
            repo_to=repo,
Pierre-Yves Chibon 73d120
            branch_to="master",
Pierre-Yves Chibon 73d120
            title="merged pullrequest by user pingou on repo test2",
Pierre-Yves Chibon 73d120
            user="pingou",
Ryan Lerch 397681
            status="Merged",
Ryan Lerch 397681
        )
Ryan Lerch 397681
        self.session.commit()
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Ryan Lerch 397681
    def test_api_view_user_requests_filed(self, mockemail):
Ryan Lerch 397681
        """ Test the api_view_user_requests_filed method of the flask user
Ryan Lerch 397681
        api """
Ryan Lerch 397681
Ryan Lerch 397681
        # First we test without the status parameter. It should default to `open`
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/user/pingou/requests/filed")
Ryan Lerch 397681
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 2)
Pierre-Yves Chibon fc03a3
        self.assertEqual(
Pierre-Yves Chibon fc03a3
            sorted(data.keys()),
Pierre-Yves Chibon 73d120
            ["args", "pagination", "requests", "total_requests"],
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["user"]["name"], "pingou")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["user"]["name"], "pingou")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["status"], "Open")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["status"], "Open")
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][0]["title"],
Pierre-Yves Chibon 73d120
            "open pullrequest by user pingou on repo test2",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][1]["title"],
Pierre-Yves Chibon 73d120
            "open pullrequest by user pingou on repo test",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["status"], "open")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["page"], 1)
Ryan Lerch 397681
Ryan Lerch 397681
        # Next test with the status parameter set to `open`.
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/user/pingou/requests/filed?status=open")
Ryan Lerch 397681
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 2)
Pierre-Yves Chibon fc03a3
        self.assertEqual(
Pierre-Yves Chibon fc03a3
            sorted(data.keys()),
Pierre-Yves Chibon 73d120
            ["args", "pagination", "requests", "total_requests"],
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["user"]["name"], "pingou")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["user"]["name"], "pingou")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["status"], "Open")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["status"], "Open")
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][0]["title"],
Pierre-Yves Chibon 73d120
            "open pullrequest by user pingou on repo test2",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][1]["title"],
Pierre-Yves Chibon 73d120
            "open pullrequest by user pingou on repo test",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["status"], "open")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["page"], 1)
Ryan Lerch 397681
Ryan Lerch 397681
        # Next test with the status parameter set to `closed`.
Ryan Lerch 397681
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=closed"
Pierre-Yves Chibon 73d120
        )
Ryan Lerch 397681
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 2)
Pierre-Yves Chibon fc03a3
        self.assertEqual(
Pierre-Yves Chibon fc03a3
            sorted(data.keys()),
Pierre-Yves Chibon 73d120
            ["args", "pagination", "requests", "total_requests"],
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["user"]["name"], "pingou")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["user"]["name"], "pingou")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["status"], "Closed")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["status"], "Closed")
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][0]["title"],
Pierre-Yves Chibon 73d120
            "closed pullrequest by user pingou on repo test2",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][1]["title"],
Pierre-Yves Chibon 73d120
            "closed pullrequest by user pingou on repo test",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["status"], "closed")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["page"], 1)
Ryan Lerch 397681
Ryan Lerch 397681
        # Next test with the status parameter set to `merged`.
Ryan Lerch 397681
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=merged"
Pierre-Yves Chibon 73d120
        )
Ryan Lerch 397681
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 2)
Pierre-Yves Chibon fc03a3
        self.assertEqual(
Pierre-Yves Chibon fc03a3
            sorted(data.keys()),
Pierre-Yves Chibon 73d120
            ["args", "pagination", "requests", "total_requests"],
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["user"]["name"], "pingou")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["user"]["name"], "pingou")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["status"], "Merged")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["status"], "Merged")
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][0]["title"],
Pierre-Yves Chibon 73d120
            "merged pullrequest by user pingou on repo test2",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][1]["title"],
Pierre-Yves Chibon 73d120
            "merged pullrequest by user pingou on repo test",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["status"], "merged")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["page"], 1)
Ryan Lerch 397681
Ryan Lerch 397681
        # Finally, test with the status parameter set to `all`.
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/user/pingou/requests/filed?status=all")
Ryan Lerch 397681
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 6)
Pierre-Yves Chibon fc03a3
        self.assertEqual(
Pierre-Yves Chibon fc03a3
            sorted(data.keys()),
Pierre-Yves Chibon 73d120
            ["args", "pagination", "requests", "total_requests"],
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["user"]["name"], "pingou")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["user"]["name"], "pingou")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][2]["user"]["name"], "pingou")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][3]["user"]["name"], "pingou")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][4]["user"]["name"], "pingou")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][5]["user"]["name"], "pingou")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["status"], "Merged")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["status"], "Merged")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][2]["status"], "Closed")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][3]["status"], "Closed")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][4]["status"], "Open")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][5]["status"], "Open")
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][0]["title"],
Pierre-Yves Chibon 73d120
            "merged pullrequest by user pingou on repo test2",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][1]["title"],
Pierre-Yves Chibon 73d120
            "merged pullrequest by user pingou on repo test",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][2]["title"],
Pierre-Yves Chibon 73d120
            "closed pullrequest by user pingou on repo test2",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][3]["title"],
Pierre-Yves Chibon 73d120
            "closed pullrequest by user pingou on repo test",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][4]["title"],
Pierre-Yves Chibon 73d120
            "open pullrequest by user pingou on repo test2",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][5]["title"],
Pierre-Yves Chibon 73d120
            "open pullrequest by user pingou on repo test",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["status"], "all")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["page"], 1)
Ryan Lerch 397681
Pierre-Yves Chibon 254b06
        # Test page 2 with the status parameter set to `all`.
Pierre-Yves Chibon 254b06
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=all&page=2"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 254b06
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 254b06
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon fc03a3
        self.assertEqual(
Pierre-Yves Chibon fc03a3
            sorted(data.keys()),
Pierre-Yves Chibon 73d120
            ["args", "pagination", "requests", "total_requests"],
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["page"], 2)
Pierre-Yves Chibon 254b06
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Pierre-Yves Chibon 0ccdba
    def test_api_view_user_requests_filed_created(self, mockemail):
Pierre-Yves Chibon 0ccdba
        """ Test the api_view_user_requests_filed method of the flask user
Pierre-Yves Chibon 0ccdba
        api with the created parameter """
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        today = datetime.datetime.utcnow().date()
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=all&created=%s"
Pierre-Yves Chibon 73d120
            % (today.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 6)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        yesterday = today - datetime.timedelta(days=1)
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=all&created=%s"
Pierre-Yves Chibon 73d120
            % (yesterday.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 6)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        tomorrow = today + datetime.timedelta(days=1)
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=all&created=%s"
Pierre-Yves Chibon 73d120
            % (tomorrow.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=all&created=..%s"
Pierre-Yves Chibon 73d120
            % (today.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=all&created=..%s"
Pierre-Yves Chibon 73d120
            % (yesterday.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        thedaybefore = today - datetime.timedelta(days=1)
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=all&created=..%s"
Pierre-Yves Chibon 73d120
            % (thedaybefore.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=all&created=..%s"
Pierre-Yves Chibon 73d120
            % (tomorrow.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 6)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=all&created=%s..%s"
Pierre-Yves Chibon 73d120
            % (thedaybefore.isoformat(), tomorrow.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 6)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Pierre-Yves Chibon 0ccdba
    def test_api_view_user_requests_filed_updated(self, mockemail):
Pierre-Yves Chibon 0ccdba
        """ Test the api_view_user_requests_filed method of the flask user
Pierre-Yves Chibon 0ccdba
        api with the created parameter """
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        today = datetime.datetime.utcnow().date()
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=all&updated=%s"
Pierre-Yves Chibon 73d120
            % (today.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        yesterday = today - datetime.timedelta(days=1)
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=all&updated=%s"
Pierre-Yves Chibon 73d120
            % (yesterday.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        tomorrow = today + datetime.timedelta(days=1)
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=all&updated=%s"
Pierre-Yves Chibon 73d120
            % (tomorrow.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 6)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Pierre-Yves Chibon 0ccdba
    def test_api_view_user_requests_filed_closed(self, mockemail):
Pierre-Yves Chibon 0ccdba
        """ Test the api_view_user_requests_filed method of the flask user
Pierre-Yves Chibon 0ccdba
        api with the created parameter """
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        today = datetime.datetime.utcnow().date()
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=all&closed=%s"
Pierre-Yves Chibon 73d120
            % (today.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        yesterday = today - datetime.timedelta(days=1)
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=all&closed=%s"
Pierre-Yves Chibon 73d120
            % (yesterday.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        tomorrow = today + datetime.timedelta(days=1)
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/filed?status=all&closed=%s"
Pierre-Yves Chibon 73d120
            % (tomorrow.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Pierre-Yves Chibon 13b47e
    def test_api_view_user_requests_filed_foo(self, mockemail):
Pierre-Yves Chibon 13b47e
        """ Test the api_view_user_requests_filed method of the flask user
Pierre-Yves Chibon 13b47e
        api """
Pierre-Yves Chibon 13b47e
Pierre-Yves Chibon 13b47e
        # Default data returned
Pierre-Yves Chibon 13b47e
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/foo/requests/filed?status=all&per_page=6"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 13b47e
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 13b47e
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 13b47e
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 6)
Pierre-Yves Chibon 13b47e
        self.assertEqual(
Pierre-Yves Chibon 13b47e
            sorted(data.keys()),
Pierre-Yves Chibon 73d120
            ["args", "pagination", "requests", "total_requests"],
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 13b47e
        # There are 6 PRs, that's 1 page at 6 results per page
Pierre-Yves Chibon 73d120
        self.assertEqual(data["pagination"]["pages"], 1)
Pierre-Yves Chibon 13b47e
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Pierre-Yves Chibon 13b47e
    def test_api_view_user_requests_filed_foo_grp_access(self, mockemail):
Pierre-Yves Chibon 13b47e
        """ Test when the user has accessed to some PRs via a group. """
Pierre-Yves Chibon 13b47e
Pierre-Yves Chibon 13b47e
        # Add the user to a group
Pierre-Yves Chibon 13b47e
        msg = pagure.lib.query.add_group(
Pierre-Yves Chibon 13b47e
            self.session,
Pierre-Yves Chibon 73d120
            group_name="some_group",
Pierre-Yves Chibon 73d120
            display_name="Some Group",
Pierre-Yves Chibon 13b47e
            description=None,
Pierre-Yves Chibon 73d120
            group_type="bar",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 13b47e
            is_admin=False,
Pierre-Yves Chibon 13b47e
            blacklist=[],
Pierre-Yves Chibon 13b47e
        )
Pierre-Yves Chibon 13b47e
        self.session.commit()
Pierre-Yves Chibon 13b47e
        # Add the group to the project `test2`
Pierre-Yves Chibon 73d120
        project = pagure.lib.query._get_project(self.session, "test2")
Pierre-Yves Chibon 13b47e
        msg = pagure.lib.query.add_group_to_project(
Pierre-Yves Chibon 13b47e
            session=self.session,
Pierre-Yves Chibon 13b47e
            project=project,
Pierre-Yves Chibon 73d120
            new_group="some_group",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon 13b47e
        )
Pierre-Yves Chibon 13b47e
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "Group added")
Pierre-Yves Chibon 13b47e
        # Add foo to the group
Pierre-Yves Chibon 13b47e
        group = pagure.lib.query.search_groups(
Pierre-Yves Chibon 73d120
            self.session, group_name="some_group"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 13b47e
        result = pagure.lib.query.add_user_to_group(
Pierre-Yves Chibon 73d120
            self.session, "foo", group, "pingou", True
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 13b47e
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(result, "User `foo` added to the group `some_group`.")
Pierre-Yves Chibon 13b47e
Pierre-Yves Chibon 13b47e
        # Query the API for foo's filed PRs
Pierre-Yves Chibon 13b47e
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/foo/requests/filed?status=all&per_page=6"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 13b47e
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 13b47e
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 13b47e
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 6)
Pierre-Yves Chibon 13b47e
        self.assertEqual(
Pierre-Yves Chibon 13b47e
            sorted(data.keys()),
Pierre-Yves Chibon 73d120
            ["args", "pagination", "requests", "total_requests"],
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 13b47e
        # There are 6 PRs, that's 1 page at 6 results per page
Pierre-Yves Chibon 73d120
        self.assertEqual(data["pagination"]["pages"], 1)
Pierre-Yves Chibon 13b47e
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Ryan Lerch 397681
    def test_api_view_user_requests_actionable(self, mockemail):
Ryan Lerch 397681
        """ Test the api_view_user_requests_actionable method of the flask user
Ryan Lerch 397681
        api """
Ryan Lerch 397681
Ryan Lerch 397681
        # First we test without the status parameter. It should default to `open`
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/user/pingou/requests/actionable")
Ryan Lerch 397681
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 2)
Pierre-Yves Chibon fc03a3
        self.assertEqual(
Pierre-Yves Chibon fc03a3
            sorted(data.keys()),
Pierre-Yves Chibon 73d120
            ["args", "pagination", "requests", "total_requests"],
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["user"]["name"], "foo")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["user"]["name"], "foo")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["status"], "Open")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["status"], "Open")
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][0]["title"],
Pierre-Yves Chibon 73d120
            "open pullrequest by user foo on repo test2",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][1]["title"],
Pierre-Yves Chibon 73d120
            "open pullrequest by user foo on repo test",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["status"], "open")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["page"], 1)
Ryan Lerch 397681
Ryan Lerch 397681
        # Next test with the status parameter set to `open`.
Ryan Lerch 397681
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=open"
Pierre-Yves Chibon 73d120
        )
Ryan Lerch 397681
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 2)
Pierre-Yves Chibon fc03a3
        self.assertEqual(
Pierre-Yves Chibon fc03a3
            sorted(data.keys()),
Pierre-Yves Chibon 73d120
            ["args", "pagination", "requests", "total_requests"],
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["user"]["name"], "foo")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["user"]["name"], "foo")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["status"], "Open")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["status"], "Open")
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][0]["title"],
Pierre-Yves Chibon 73d120
            "open pullrequest by user foo on repo test2",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][1]["title"],
Pierre-Yves Chibon 73d120
            "open pullrequest by user foo on repo test",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["status"], "open")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["page"], 1)
Ryan Lerch 397681
Ryan Lerch 397681
        # Next test with the status parameter set to `closed`.
Ryan Lerch 397681
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=closed"
Pierre-Yves Chibon 73d120
        )
Ryan Lerch 397681
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 2)
Pierre-Yves Chibon fc03a3
        self.assertEqual(
Pierre-Yves Chibon fc03a3
            sorted(data.keys()),
Pierre-Yves Chibon 73d120
            ["args", "pagination", "requests", "total_requests"],
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["user"]["name"], "foo")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["user"]["name"], "foo")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["status"], "Closed")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["status"], "Closed")
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][0]["title"],
Pierre-Yves Chibon 73d120
            "closed pullrequest by user foo on repo test2",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][1]["title"],
Pierre-Yves Chibon 73d120
            "closed pullrequest by user foo on repo test",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["status"], "closed")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["page"], 1)
Ryan Lerch 397681
Ryan Lerch 397681
        # Next test with the status parameter set to `merged`.
Ryan Lerch 397681
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=merged"
Pierre-Yves Chibon 73d120
        )
Ryan Lerch 397681
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 2)
Pierre-Yves Chibon fc03a3
        self.assertEqual(
Pierre-Yves Chibon fc03a3
            sorted(data.keys()),
Pierre-Yves Chibon 73d120
            ["args", "pagination", "requests", "total_requests"],
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["user"]["name"], "foo")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["user"]["name"], "foo")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["status"], "Merged")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["status"], "Merged")
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][0]["title"],
Pierre-Yves Chibon 73d120
            "merged pullrequest by user foo on repo test2",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][1]["title"],
Pierre-Yves Chibon 73d120
            "merged pullrequest by user foo on repo test",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["status"], "merged")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["page"], 1)
Ryan Lerch 397681
Ryan Lerch 397681
        # Finally, test with the status parameter set to `all`.
Ryan Lerch 397681
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all"
Pierre-Yves Chibon 73d120
        )
Ryan Lerch 397681
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 6)
Pierre-Yves Chibon fc03a3
        self.assertEqual(
Pierre-Yves Chibon fc03a3
            sorted(data.keys()),
Pierre-Yves Chibon 73d120
            ["args", "pagination", "requests", "total_requests"],
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["user"]["name"], "foo")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["user"]["name"], "foo")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][2]["user"]["name"], "foo")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][3]["user"]["name"], "foo")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][4]["user"]["name"], "foo")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][5]["user"]["name"], "foo")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][0]["status"], "Merged")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][1]["status"], "Merged")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][2]["status"], "Closed")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][3]["status"], "Closed")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][4]["status"], "Open")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["requests"][5]["status"], "Open")
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][0]["title"],
Pierre-Yves Chibon 73d120
            "merged pullrequest by user foo on repo test2",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][1]["title"],
Pierre-Yves Chibon 73d120
            "merged pullrequest by user foo on repo test",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][2]["title"],
Pierre-Yves Chibon 73d120
            "closed pullrequest by user foo on repo test2",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][3]["title"],
Pierre-Yves Chibon 73d120
            "closed pullrequest by user foo on repo test",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][4]["title"],
Pierre-Yves Chibon 73d120
            "open pullrequest by user foo on repo test2",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(
Pierre-Yves Chibon 73d120
            data["requests"][5]["title"],
Pierre-Yves Chibon 73d120
            "open pullrequest by user foo on repo test",
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["status"], "all")
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["page"], 1)
Ryan Lerch 397681
Pierre-Yves Chibon 254b06
        # Test page 2 with the status parameter set to `all`.
Pierre-Yves Chibon 254b06
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all&page=2"
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 254b06
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 254b06
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon fc03a3
        self.assertEqual(
Pierre-Yves Chibon fc03a3
            sorted(data.keys()),
Pierre-Yves Chibon 73d120
            ["args", "pagination", "requests", "total_requests"],
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertEqual(data["args"]["page"], 2)
Ryan Lerch 397681
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Pierre-Yves Chibon 0ccdba
    def test_api_view_user_requests_actionable_created(self, mockemail):
Pierre-Yves Chibon 0ccdba
        """ Test the api_view_user_requests_filed method of the flask user
Pierre-Yves Chibon 0ccdba
        api with the created parameter """
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        today = datetime.datetime.utcnow().date()
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all&created=%s"
Pierre-Yves Chibon 73d120
            % (today.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 6)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        yesterday = today - datetime.timedelta(days=1)
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all&created=%s"
Pierre-Yves Chibon 73d120
            % (yesterday.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 6)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        tomorrow = today + datetime.timedelta(days=1)
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all&created=%s"
Pierre-Yves Chibon 73d120
            % (tomorrow.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all&created=..%s"
Pierre-Yves Chibon 73d120
            % (today.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all&created=..%s"
Pierre-Yves Chibon 73d120
            % (yesterday.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        thedaybefore = today - datetime.timedelta(days=1)
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all&created=..%s"
Pierre-Yves Chibon 73d120
            % (thedaybefore.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all&created=..%s"
Pierre-Yves Chibon 73d120
            % (tomorrow.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 6)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all&created=%s..%s"
Pierre-Yves Chibon 73d120
            % (thedaybefore.isoformat(), tomorrow.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 6)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Pierre-Yves Chibon 0ccdba
    def test_api_view_user_requests_actionable_updated(self, mockemail):
Pierre-Yves Chibon 0ccdba
        """ Test the api_view_user_requests_filed method of the flask user
Pierre-Yves Chibon 0ccdba
        api with the created parameter """
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        today = datetime.datetime.utcnow().date()
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all&updated=%s"
Pierre-Yves Chibon 73d120
            % (today.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        yesterday = today - datetime.timedelta(days=1)
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all&updated=%s"
Pierre-Yves Chibon 73d120
            % (yesterday.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        tomorrow = today + datetime.timedelta(days=1)
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all&updated=%s"
Pierre-Yves Chibon 73d120
            % (tomorrow.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 6)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.notify.send_email")
Pierre-Yves Chibon 0ccdba
    def test_api_view_user_requests_actionable_closed(self, mockemail):
Pierre-Yves Chibon 0ccdba
        """ Test the api_view_user_requests_filed method of the flask user
Pierre-Yves Chibon 0ccdba
        api with the created parameter """
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        today = datetime.datetime.utcnow().date()
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all&closed=%s"
Pierre-Yves Chibon 73d120
            % (today.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        yesterday = today - datetime.timedelta(days=1)
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all&closed=%s"
Pierre-Yves Chibon 73d120
            % (yesterday.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
        tomorrow = today + datetime.timedelta(days=1)
Pierre-Yves Chibon 0ccdba
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/requests/actionable?status=all&closed=%s"
Pierre-Yves Chibon 73d120
            % (tomorrow.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 0ccdba
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0ccdba
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        self.assertEqual(len(data["requests"]), 0)
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon 0ccdba
Pierre-Yves Chibon f8e0d1
class PagureFlaskApiUsertestissues(tests.Modeltests):
Pierre-Yves Chibon f8e0d1
    """ Tests for the user issues endpoints """
Pierre-Yves Chibon f8e0d1
Pierre-Yves Chibon f8e0d1
    maxDiff = None
Pierre-Yves Chibon f8e0d1
Pierre-Yves Chibon f8e0d1
    def setUp(self):
Pierre-Yves Chibon f8e0d1
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon f8e0d1
        super(PagureFlaskApiUsertestissues, self).setUp()
Pierre-Yves Chibon f8e0d1
Pierre-Yves Chibon 73d120
        pagure.config.config["REQUESTS_FOLDER"] = None
Pierre-Yves Chibon f8e0d1
Pierre-Yves Chibon f8e0d1
        tests.create_projects(self.session)
Pierre-Yves Chibon f8e0d1
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query._get_project(self.session, "test")
Pierre-Yves Chibon f8e0d1
Pierre-Yves Chibon f8e0d1
        # Create issues to play with
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.new_issue(
Pierre-Yves Chibon f8e0d1
            session=self.session,
Pierre-Yves Chibon f8e0d1
            repo=repo,
Pierre-Yves Chibon 73d120
            title="Test issue",
Pierre-Yves Chibon 73d120
            content="We should work on this",
Pierre-Yves Chibon 73d120
            user="pingou",
Pierre-Yves Chibon f8e0d1
        )
Pierre-Yves Chibon f8e0d1
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg.title, "Test issue")
Pierre-Yves Chibon f8e0d1
Pierre-Yves Chibon f8e0d1
    def test_user_issues_empty(self):
Pierre-Yves Chibon f8e0d1
        """ Return the list of issues associated with the specified user. """
Pierre-Yves Chibon f8e0d1
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/user/foo/issues")
Pierre-Yves Chibon f8e0d1
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 73d120
        for k in ["pagination_issues_assigned", "pagination_issues_created"]:
Pierre-Yves Chibon 73d120
            for k2 in ["first", "last"]:
Pierre-Yves Chibon 610db7
                self.assertIsNotNone(data[k][k2])
Pierre-Yves Chibon 610db7
                data[k][k2] = None
Pierre-Yves Chibon f8e0d1
        self.assertEqual(
Pierre-Yves Chibon f8e0d1
            data,
Pierre-Yves Chibon f8e0d1
            {
Pierre-Yves Chibon 73d120
                "args": {
Pierre-Yves Chibon 73d120
                    "assignee": True,
Pierre-Yves Chibon 73d120
                    "author": True,
Pierre-Yves Chibon 73d120
                    "closed": None,
Pierre-Yves Chibon 73d120
                    "created": None,
Pierre-Yves Chibon 73d120
                    "milestones": [],
Pierre-Yves Chibon 73d120
                    "no_stones": None,
Pierre-Yves Chibon 73d120
                    "order": None,
Pierre-Yves Chibon 73d120
                    "order_key": None,
Pierre-Yves Chibon 73d120
                    "page": 1,
Pierre-Yves Chibon 73d120
                    "since": None,
Pierre-Yves Chibon 73d120
                    "status": None,
Pierre-Yves Chibon 73d120
                    "tags": [],
Pierre-Yves Chibon 73d120
                    "updated": None,
Pierre-Yves Chibon 73d120
                },
Pierre-Yves Chibon 73d120
                "issues_assigned": [],
Pierre-Yves Chibon 73d120
                "issues_created": [],
Pierre-Yves Chibon 73d120
                "pagination_issues_assigned": {
Pierre-Yves Chibon 73d120
                    "first": None,
Pierre-Yves Chibon 73d120
                    "last": None,
Pierre-Yves Chibon 73d120
                    "next": None,
Pierre-Yves Chibon 73d120
                    "page": 1,
Pierre-Yves Chibon 73d120
                    "pages": 0,
Pierre-Yves Chibon 73d120
                    "per_page": 20,
Pierre-Yves Chibon 73d120
                    "prev": None,
Pierre-Yves Chibon 73d120
                },
Pierre-Yves Chibon 73d120
                "pagination_issues_created": {
Pierre-Yves Chibon 73d120
                    "first": None,
Pierre-Yves Chibon 73d120
                    "last": None,
Pierre-Yves Chibon 73d120
                    "next": None,
Pierre-Yves Chibon 73d120
                    "page": 1,
Pierre-Yves Chibon 73d120
                    "pages": 0,
Pierre-Yves Chibon 73d120
                    "per_page": 20,
Pierre-Yves Chibon 73d120
                    "prev": None,
Pierre-Yves Chibon 73d120
                },
Pierre-Yves Chibon 73d120
                "total_issues_assigned": 0,
Pierre-Yves Chibon 73d120
                "total_issues_assigned_pages": 1,
Pierre-Yves Chibon 73d120
                "total_issues_created": 0,
Pierre-Yves Chibon 73d120
                "total_issues_created_pages": 1,
Pierre-Yves Chibon 73d120
            },
Pierre-Yves Chibon f8e0d1
        )
Pierre-Yves Chibon f8e0d1
Pierre-Yves Chibon f8e0d1
    def test_user_issues(self):
Pierre-Yves Chibon f8e0d1
        """ Return the list of issues associated with the specified user. """
Pierre-Yves Chibon f8e0d1
Pierre-Yves Chibon 73d120
        output = self.app.get("/api/0/user/pingou/issues")
Pierre-Yves Chibon f8e0d1
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon f8e0d1
        issues = []
Pierre-Yves Chibon 73d120
        for issue in data["issues_created"]:
Pierre-Yves Chibon 73d120
            issue["date_created"] = "1513111778"
Pierre-Yves Chibon 73d120
            issue["last_updated"] = "1513111778"
Pierre-Yves Chibon 73d120
            issue["project"]["date_created"] = "1513111778"
Pierre-Yves Chibon 73d120
            issue["project"]["date_modified"] = "1513111778"
Pierre-Yves Chibon f8e0d1
            issues.append(issue)
Pierre-Yves Chibon 73d120
        data["issues_created"] = issues
Pierre-Yves Chibon 73d120
        for k in ["pagination_issues_assigned", "pagination_issues_created"]:
Pierre-Yves Chibon 73d120
            for k2 in ["first", "last"]:
Pierre-Yves Chibon 610db7
                self.assertIsNotNone(data[k][k2])
Pierre-Yves Chibon 610db7
                data[k][k2] = None
Pierre-Yves Chibon f8e0d1
        self.assertEqual(
Pierre-Yves Chibon f8e0d1
            data,
Pierre-Yves Chibon f8e0d1
            {
Pierre-Yves Chibon 73d120
                "args": {
Pierre-Yves Chibon 73d120
                    "assignee": True,
Pierre-Yves Chibon 73d120
                    "author": True,
Pierre-Yves Chibon 73d120
                    "closed": None,
Pierre-Yves Chibon 73d120
                    "created": None,
Pierre-Yves Chibon 73d120
                    "milestones": [],
Pierre-Yves Chibon 73d120
                    "no_stones": None,
Pierre-Yves Chibon 73d120
                    "order": None,
Pierre-Yves Chibon 73d120
                    "order_key": None,
Pierre-Yves Chibon 73d120
                    "page": 1,
Pierre-Yves Chibon 73d120
                    "since": None,
Pierre-Yves Chibon 73d120
                    "status": None,
Pierre-Yves Chibon f8e0d1
                    "tags": [],
Pierre-Yves Chibon 73d120
                    "updated": None,
Pierre-Yves Chibon 73d120
                },
Pierre-Yves Chibon 73d120
                "issues_assigned": [],
Pierre-Yves Chibon 73d120
                "issues_created": [
Pierre-Yves Chibon 73d120
                    {
Pierre-Yves Chibon 73d120
                        "assignee": None,
Pierre-Yves Chibon 73d120
                        "blocks": [],
Pierre-Yves Chibon 73d120
                        "close_status": None,
Pierre-Yves Chibon 73d120
                        "closed_at": None,
Pierre-Yves Chibon 73d120
                        "closed_by": None,
Pierre-Yves Chibon 73d120
                        "comments": [],
Pierre-Yves Chibon 73d120
                        "content": "We should work on this",
Pierre-Yves Chibon 73d120
                        "custom_fields": [],
Pierre-Yves Chibon 73d120
                        "date_created": "1513111778",
Pierre-Yves Chibon 73d120
                        "depends": [],
Pierre-Yves Chibon 73d120
                        "id": 1,
Pierre-Yves Chibon 73d120
                        "last_updated": "1513111778",
Pierre-Yves Chibon 73d120
                        "milestone": None,
Pierre-Yves Chibon 73d120
                        "priority": None,
Pierre-Yves Chibon 73d120
                        "private": False,
Pierre-Yves Chibon 73d120
                        "project": {
Pierre-Yves Chibon 73d120
                            "access_groups": {
Pierre-Yves Chibon 73d120
                                "admin": [],
Pierre-Yves Chibon 73d120
                                "commit": [],
Pierre-Yves Chibon 73d120
                                "ticket": [],
Pierre-Yves Chibon 73d120
                            },
Pierre-Yves Chibon 73d120
                            "access_users": {
Pierre-Yves Chibon 73d120
                                "admin": [],
Pierre-Yves Chibon 73d120
                                "commit": [],
Pierre-Yves Chibon 73d120
                                "owner": ["pingou"],
Pierre-Yves Chibon 73d120
                                "ticket": [],
Pierre-Yves Chibon 73d120
                            },
Pierre-Yves Chibon 73d120
                            "close_status": [
Pierre-Yves Chibon 73d120
                                "Invalid",
Pierre-Yves Chibon 73d120
                                "Insufficient data",
Pierre-Yves Chibon 73d120
                                "Fixed",
Pierre-Yves Chibon 73d120
                                "Duplicate",
Pierre-Yves Chibon 73d120
                            ],
Pierre-Yves Chibon 73d120
                            "custom_keys": [],
Pierre-Yves Chibon 73d120
                            "date_created": "1513111778",
Pierre-Yves Chibon 73d120
                            "date_modified": "1513111778",
Pierre-Yves Chibon 73d120
                            "description": "test project #1",
Pierre-Yves Chibon 73d120
                            "fullname": "test",
Pierre-Yves Chibon 73d120
                            "id": 1,
Pierre-Yves Chibon 73d120
                            "milestones": {},
Pierre-Yves Chibon 73d120
                            "name": "test",
Pierre-Yves Chibon 73d120
                            "namespace": None,
Pierre-Yves Chibon 73d120
                            "parent": None,
Pierre-Yves Chibon 73d120
                            "priorities": {},
Pierre-Yves Chibon 73d120
                            "tags": [],
Pierre-Yves Chibon 73d120
                            "url_path": "test",
Pierre-Yves Chibon 73d120
                            "user": {"fullname": "PY C", "name": "pingou"},
Pierre-Yves Chibon 73d120
                        },
Pierre-Yves Chibon 73d120
                        "status": "Open",
Pierre-Yves Chibon 73d120
                        "tags": [],
Pierre-Yves Chibon 73d120
                        "title": "Test issue",
Pierre-Yves Chibon 73d120
                        "user": {"fullname": "PY C", "name": "pingou"},
Pierre-Yves Chibon f8e0d1
                    }
Pierre-Yves Chibon 73d120
                ],
Pierre-Yves Chibon 73d120
                "pagination_issues_assigned": {
Pierre-Yves Chibon 73d120
                    "first": None,
Pierre-Yves Chibon 73d120
                    "last": None,
Pierre-Yves Chibon 73d120
                    "next": None,
Pierre-Yves Chibon 73d120
                    "page": 1,
Pierre-Yves Chibon 73d120
                    "pages": 0,
Pierre-Yves Chibon 73d120
                    "per_page": 20,
Pierre-Yves Chibon 73d120
                    "prev": None,
Pierre-Yves Chibon 73d120
                },
Pierre-Yves Chibon 73d120
                "pagination_issues_created": {
Pierre-Yves Chibon 73d120
                    "first": None,
Pierre-Yves Chibon 73d120
                    "last": None,
Pierre-Yves Chibon 73d120
                    "next": None,
Pierre-Yves Chibon 73d120
                    "page": 1,
Pierre-Yves Chibon 73d120
                    "pages": 1,
Pierre-Yves Chibon 73d120
                    "per_page": 20,
Pierre-Yves Chibon 73d120
                    "prev": None,
Pierre-Yves Chibon 73d120
                },
Pierre-Yves Chibon 73d120
                "total_issues_assigned": 0,
Pierre-Yves Chibon 73d120
                "total_issues_assigned_pages": 1,
Pierre-Yves Chibon 73d120
                "total_issues_created": 1,
Pierre-Yves Chibon 73d120
                "total_issues_created_pages": 1,
Pierre-Yves Chibon 73d120
            },
Pierre-Yves Chibon f8e0d1
        )
Pierre-Yves Chibon f8e0d1
Pierre-Yves Chibon 872898
    def test_user_issues_created(self):
Pierre-Yves Chibon 872898
        """ Return the list of issues associated with the specified user
Pierre-Yves Chibon 872898
        and play with the created filter. """
Pierre-Yves Chibon 872898
Pierre-Yves Chibon 872898
        today = datetime.datetime.utcnow().date()
Pierre-Yves Chibon 872898
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/issues?created=%s" % (today.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 872898
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 872898
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 872898
        self.assertEqual(data["total_issues_assigned"], 0)
Pierre-Yves Chibon 872898
        self.assertEqual(data["total_issues_created"], 1)
Pierre-Yves Chibon 872898
Pierre-Yves Chibon 872898
        yesterday = today - datetime.timedelta(days=1)
Pierre-Yves Chibon 872898
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/issues?created=%s" % (yesterday.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 872898
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 872898
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 872898
        self.assertEqual(data["total_issues_assigned"], 0)
Pierre-Yves Chibon 872898
        self.assertEqual(data["total_issues_created"], 1)
Pierre-Yves Chibon 872898
Pierre-Yves Chibon 872898
        tomorrow = today + datetime.timedelta(days=1)
Pierre-Yves Chibon 872898
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/issues?created=%s" % (tomorrow.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 872898
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 872898
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 872898
        self.assertEqual(data["total_issues_assigned"], 0)
Pierre-Yves Chibon 872898
        self.assertEqual(data["total_issues_created"], 0)
Pierre-Yves Chibon 872898
Pierre-Yves Chibon 872898
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/issues?created=..%s" % (yesterday.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 872898
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 872898
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 872898
        self.assertEqual(data["total_issues_assigned"], 0)
Pierre-Yves Chibon 872898
        self.assertEqual(data["total_issues_created"], 0)
Pierre-Yves Chibon 872898
Pierre-Yves Chibon 872898
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/issues?created=%s..%s"
Pierre-Yves Chibon 73d120
            % (yesterday.isoformat(), today.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 872898
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 872898
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 872898
        self.assertEqual(data["total_issues_assigned"], 0)
Pierre-Yves Chibon 872898
        self.assertEqual(data["total_issues_created"], 0)
Pierre-Yves Chibon 872898
Pierre-Yves Chibon 872898
        output = self.app.get(
Pierre-Yves Chibon 73d120
            "/api/0/user/pingou/issues?created=%s..%s"
Pierre-Yves Chibon 73d120
            % (yesterday.isoformat(), tomorrow.isoformat())
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 872898
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 872898
        data = json.loads(output.get_data(as_text=True))
Pierre-Yves Chibon 872898
        self.assertEqual(data["total_issues_assigned"], 0)
Pierre-Yves Chibon 872898
        self.assertEqual(data["total_issues_created"], 1)
Pierre-Yves Chibon 872898
Pierre-Yves Chibon f8e0d1
Pierre-Yves Chibon 73d120
if __name__ == "__main__":
Pierre-Yves Chibon 393f31
    unittest.main(verbosity=2)