Example #1
0
    def test_messages_paging(self):
        reporter = GithubReporter('TOKEN', 'foo', 'bar', 12, 'abc123')
        client_session = FakeClientSession(
            url_map={
                ('https://api.github.com/repos/foo/bar/pulls/12/comments', 'get'):
                FakeClientResponse(json.dumps([{
                    'path': 'file1',
                    'position': 2,
                    'body': 'hello'
                }],
                                              sort_keys=True),
                                   headers={
                                       'link':
                                       '<https://api.github.com/repos/foo/bar/'
                                       'pulls/12/comments?page=1>; rel="next"'
                                   }),
                ('https://api.github.com/repos/foo/bar/pulls/12/comments?page=1', 'get'):
                FakeClientResponse(
                    json.dumps([{
                        'path': 'file2',
                        'position': 3,
                        'body': 'world'
                    }],
                               sort_keys=True))
            })

        loop = asyncio.get_event_loop()
        existing_messages = loop.run_until_complete(
            reporter.get_existing_messages(client_session))

        self.assertEqual(2, len(existing_messages))
        self.assertIn(('file1', 2, 'hello'), existing_messages)
        self.assertIn(('file2', 3, 'world'), existing_messages)
    def test_messages_paging(self):
        reporter = GithubReporter('TOKEN', 'foo', 'bar', 12, 'abc123')
        client_session = FakeClientSession(url_map={
            ('https://api.github.com/repos/foo/bar/pulls/12/comments', 'get'):
                FakeClientResponse(json.dumps([{
                    'path': 'file1',
                    'position': 2,
                    'body': 'hello'
                }], sort_keys=True),
                headers={
                    'link': '<https://api.github.com/repos/foo/bar/'
                            'pulls/12/comments?page=1>; rel="next"'
                }),
            ('https://api.github.com/repos/foo/bar/pulls/12/comments?page=1',
             'get'):
                FakeClientResponse(json.dumps([{
                    'path': 'file2',
                    'position': 3,
                    'body': 'world'
                }], sort_keys=True))
        })

        loop = asyncio.get_event_loop()
        existing_messages = loop.run_until_complete(
            reporter.get_existing_messages(client_session))

        self.assertEqual(2, len(existing_messages))
        self.assertIn(('file1', 2, 'hello'), existing_messages)
        self.assertIn(('file2', 3, 'world'), existing_messages)
    def test_create_line_map(self):
        reporter = GithubReporter('TOKEN', 'foo', 'bar', 12, 'abc123', False)
        client_session = FakeClientSession(url_map={
            ('https://api.github.com/repos/foo/bar/pulls/12', 'get'):
                FakeClientResponse(GithubReporterTest.github_patch)
        })

        loop = asyncio.get_event_loop()
        line_map = loop.run_until_complete(
            reporter.create_line_to_position_map(client_session))

        self.assertEqual(2, len(line_map))
        self.assertIn('some_dir/some_file', line_map)
        self.assertIn('another_file', line_map)
        self.assertEqual(3, line_map['some_dir/some_file'][40])
        self.assertEqual(7, line_map['some_dir/some_file'][41])
        self.assertEqual(None, line_map['some_dir/some_file'].get(50, None))
        self.assertEqual(12, line_map['some_dir/some_file'][59])
    def test_create_line_map(self):
        reporter = GithubReporter('TOKEN', 'foo', 'bar', 12, 'abc123')
        client_session = FakeClientSession(url_map={
            ('https://api.github.com/repos/foo/bar/pulls/12', 'get'):
                FakeClientResponse(GithubReporterTest.github_patch)
        })

        loop = asyncio.get_event_loop()
        line_map = loop.run_until_complete(
            reporter.create_line_to_position_map(client_session))

        self.assertEqual(2, len(line_map))
        self.assertIn('some_dir/some_file', line_map)
        self.assertIn('another_file', line_map)
        self.assertEqual(3, line_map['some_dir/some_file'][40])
        self.assertEqual(7, line_map['some_dir/some_file'][41])
        self.assertEqual(None, line_map['some_dir/some_file'].get(50, None))
        self.assertEqual(12, line_map['some_dir/some_file'][59])