Exemple #1
0
    def test_fetch_from_cache_no_entries(self):
        """Test when activities, attachments and messages contain no JSON-like data"""

        issues_page_1 = read_file(
            'data/launchpad/launchpad_issues_page_1_no_entries')
        issue_1 = read_file('data/launchpad/launchpad_issue_1_no_entries')
        issue_1_comments = read_file(
            'data/launchpad/launchpad_issue_1_comments_no_entries')
        issue_1_attachments = read_file(
            'data/launchpad/launchpad_issue_1_attachments_no_entries')
        issue_1_activities = read_file(
            'data/launchpad/launchpad_issue_1_activities_no_entries')

        httpretty.register_uri(
            httpretty.GET,
            LAUNCHPAD_PACKAGE_PROJECT_URL +
            "?modified_since=1970-01-01T00%3A00%3A00%2B00%3A00&ws.op=searchTasks"
            "&omit_duplicates=false&order_by=date_last_updated&status=Confirmed&status=Expired"
            "&status=Fix+Committed&status=Fix+Released"
            "&status=In+Progress&status=Incomplete&status=Incomplete+%28with+response%29"
            "&status=Incomplete+%28without+response%29"
            "&status=Invalid&status=New&status=Opinion&status=Triaged"
            "&status=Won%27t+Fix"
            "&ws.size=1",
            body=issues_page_1,
            status=200)

        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/1",
                               body=issue_1,
                               status=200)

        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/1/messages",
                               body=issue_1_comments,
                               status=410)
        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/1/attachments",
                               body=issue_1_attachments,
                               status=410)
        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/1/activity",
                               body=issue_1_activities,
                               status=410)

        cache = Cache(self.tmp_path)
        launchpad = Launchpad('mydistribution',
                              consumer_key=CONSUMER_KEY,
                              api_token=OAUTH_TOKEN,
                              package='mypackage',
                              items_per_page=2,
                              cache=cache)
        issues = [issues for issues in launchpad.fetch()]

        issues_from_cache = [issues for issues in launchpad.fetch_from_cache()]

        self.assertDictEqual(issues[0]['data'], issues_from_cache[0]['data'])
Exemple #2
0
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        launchpad = Launchpad('mydistribution',
                              consumer_key=CONSUMER_KEY,
                              api_token=OAUTH_TOKEN,
                              package="mypackage")

        with self.assertRaises(CacheError):
            _ = [cache_issues for cache_issues in launchpad.fetch_from_cache()]
Exemple #3
0
    def test_fetch_from_empty_cache(self):
        """Test if there are not any issues returned when the cache is empty"""

        cache = Cache(self.tmp_path)
        launchpad = Launchpad('mydistribution',
                              consumer_key=CONSUMER_KEY,
                              api_token=OAUTH_TOKEN,
                              package="mypackage",
                              cache=cache)

        cache_issues = [
            cache_issues for cache_issues in launchpad.fetch_from_cache()
        ]

        self.assertEqual(len(cache_issues), 0)
Exemple #4
0
    def test_fetch_from_cache(self):
        """Test whether a list of issues is returned from cache"""

        issues_page_1 = read_file('data/launchpad/launchpad_issues_page_1')
        issues_page_2 = read_file('data/launchpad/launchpad_issues_page_2')
        issues_page_3 = read_file('data/launchpad/launchpad_issues_page_3')

        issue_1 = read_file('data/launchpad/launchpad_issue_1')
        issue_2 = read_file('data/launchpad/launchpad_issue_2')
        issue_3 = read_file('data/launchpad/launchpad_issue_3')

        issue_1_activities_next_1 = read_file(
            'data/launchpad/launchpad_issue_1_activities_next_1')
        issue_1_activities_next_2 = read_file(
            'data/launchpad/launchpad_issue_1_activities_next_2')

        issue_1_comments_next_1 = read_file(
            'data/launchpad/launchpad_issue_1_comments_next_1')
        issue_1_comments_next_2 = read_file(
            'data/launchpad/launchpad_issue_1_comments_next_2')

        issue_1_attachments_next_1 = \
            read_file('data/launchpad/launchpad_issue_1_attachments_next_1')
        issue_1_attachments_next_2 = \
            read_file('data/launchpad/launchpad_issue_1_attachments_next_2')

        issue_2_activities = read_file(
            'data/launchpad/launchpad_issue_2_activities')
        issue_2_comments = read_file(
            'data/launchpad/launchpad_issue_2_comments')

        user_1 = read_file('data/launchpad/launchpad_user_1')

        empty_issue_comments = read_file(
            'data/launchpad/launchpad_empty_issue_comments')
        empty_issue_attachments = read_file(
            'data/launchpad/launchpad_empty_issue_attachments')
        empty_issue_activities = read_file(
            'data/launchpad/launchpad_empty_issue_activities')

        httpretty.register_uri(
            httpretty.GET,
            LAUNCHPAD_PACKAGE_PROJECT_URL +
            "?modified_since=1970-01-01T00%3A00%3A00%2B00%3A00&ws.op=searchTasks"
            "&omit_duplicates=false&order_by=date_last_updated&status=Confirmed&status=Expired"
            "&status=Fix+Committed&status=Fix+Released"
            "&status=In+Progress&status=Incomplete&status=Incomplete+%28with+response%29"
            "&status=Incomplete+%28without+response%29"
            "&status=Invalid&status=New&status=Opinion&status=Triaged"
            "&status=Won%27t+Fix"
            "&ws.size=1&memo=2&ws.start=2",
            body=issues_page_3,
            status=200)
        httpretty.register_uri(
            httpretty.GET,
            LAUNCHPAD_PACKAGE_PROJECT_URL +
            "?modified_since=1970-01-01T00%3A00%3A00%2B00%3A00&ws.op=searchTasks"
            "&omit_duplicates=false&order_by=date_last_updated&status=Confirmed&status=Expired"
            "&status=Fix+Committed&status=Fix+Released"
            "&status=In+Progress&status=Incomplete&status=Incomplete+%28with+response%29"
            "&status=Incomplete+%28without+response%29"
            "&status=Invalid&status=New&status=Opinion&status=Triaged"
            "&status=Won%27t+Fix"
            "&ws.size=1&memo=1&ws.start=1",
            body=issues_page_2,
            status=200)
        httpretty.register_uri(
            httpretty.GET,
            LAUNCHPAD_PACKAGE_PROJECT_URL +
            "?modified_since=1970-01-01T00%3A00%3A00%2B00%3A00&ws.op=searchTasks"
            "&omit_duplicates=false&order_by=date_last_updated&status=Confirmed&status=Expired"
            "&status=Fix+Committed&status=Fix+Released"
            "&status=In+Progress&status=Incomplete&status=Incomplete+%28with+response%29"
            "&status=Incomplete+%28without+response%29"
            "&status=Invalid&status=New&status=Opinion&status=Triaged"
            "&status=Won%27t+Fix"
            "&ws.size=1&ws.start=0",
            body=issues_page_1,
            status=200)

        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/1",
                               body=issue_1,
                               status=200)
        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/2",
                               body=issue_2,
                               status=200)
        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/3",
                               body=issue_3,
                               status=200)

        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/1/messages",
                               body=issue_1_comments_next_2,
                               params={
                                   'ws.size': 2,
                                   'memo': 2,
                                   'ws.start': 2
                               },
                               status=200)
        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/1/messages",
                               body=issue_1_comments_next_1,
                               params={
                                   'ws.size': 2,
                                   'orderby': '-datecreated',
                                   'ws.start': 0
                               },
                               status=200)

        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/2/messages",
                               body=issue_2_comments,
                               status=200)
        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/3/messages",
                               body=empty_issue_comments,
                               status=200)
        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/1/attachments",
                               body=issue_1_attachments_next_2,
                               params={
                                   'orderby': '-datecreated',
                                   'ws.size': 2,
                                   'memo': 2,
                                   'ws.start': 2
                               },
                               status=200)
        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/1/attachments",
                               body=issue_1_attachments_next_1,
                               params={
                                   'orderby': '-datecreated',
                                   'ws.size': 2,
                                   'ws.start': 0
                               },
                               status=200)
        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/2/attachments",
                               body=empty_issue_attachments,
                               status=200)
        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/3/attachments",
                               body=empty_issue_attachments,
                               status=200)

        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/1/activity",
                               body=issue_1_activities_next_2,
                               params={
                                   'orderby': '-datecreated',
                                   'ws.size': 2,
                                   'memo': 2,
                                   'ws.start': 2
                               },
                               status=200)
        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/1/activity",
                               body=issue_1_activities_next_1,
                               params={
                                   'orderby': '-datecreated',
                                   'ws.size': 2,
                                   'ws.start': 0
                               },
                               status=200)

        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/2/activity",
                               body=issue_2_activities,
                               status=200)
        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/bugs/3/activity",
                               body=empty_issue_activities,
                               status=200)

        httpretty.register_uri(httpretty.GET,
                               LAUNCHPAD_API_URL + "/~user",
                               body=user_1,
                               status=200)

        # First, we fetch the bugs from the server and store them in a cache
        cache = Cache(self.tmp_path)
        launchpad = Launchpad('mydistribution',
                              consumer_key=CONSUMER_KEY,
                              api_token=OAUTH_TOKEN,
                              package="mypackage",
                              cache=cache,
                              items_per_page=2)
        issues = [issues for issues in launchpad.fetch()]

        # Now, we get the bugs from the cache.
        cache_issues = [
            cache_issues for cache_issues in launchpad.fetch_from_cache()
        ]

        del issues[0]['timestamp']
        del cache_issues[0]['timestamp']
        del issues[1]['timestamp']
        del cache_issues[1]['timestamp']
        del issues[2]['timestamp']
        del cache_issues[2]['timestamp']

        self.assertEqual(len(issues), len(cache_issues))
        self.assertDictEqual(issues[0], cache_issues[0])
        self.assertDictEqual(issues[1], cache_issues[1])
        self.assertDictEqual(issues[2], cache_issues[2])