Exemple #1
0
    async def test_client_handle_errors(self, mock):
        """Testing error handling"""
        mock.get(WorldOverview.get_url(), status=403)
        with self.assertRaises(Forbidden):
            await self.client.fetch_world_list()

        mock.get(WorldOverview.get_url(), status=404)
        with self.assertRaises(NetworkError):
            await self.client.fetch_world_list()

        mock.get(NewsEntry.get_list_url(), exception=aiohttp.ClientError())
        with self.assertRaises(NetworkError):
            await self.client.fetch_world_list()

        mock.post(NewsEntry.get_list_url(), exception=aiohttp.ClientOSError())
        with self.assertRaises(NetworkError):
            await self.client.fetch_recent_news(30)
Exemple #2
0
def test_office_finder_valid(all_office_details, client):
    url = api_client.exporting.endpoints['lookup-by-postcode'].format(
        postcode='ABC123')

    with requests_mock.mock() as mock:
        mock.get(url, json=all_office_details)
        response = client.get(reverse('office-finder'), {'postcode': 'ABC123'})

    assert response.status_code == 200

    assert response.context_data['office_details'] == {
        'address': ('The International Trade Centre\n'
                    '5 Merus Court\n'
                    'Meridian Business Park\n'
                    'Leicester\n'
                    'LE19 1RJ'),
        'is_match':
        True,
        'region_id':
        'east_midlands',
        'name':
        'DIT East Midlands',
        'address_street': ('The International Trade Centre, '
                           '5 Merus Court, '
                           'Meridian Business Park'),
        'address_city':
        'Leicester',
        'address_postcode':
        'LE19 1RJ',
        'email':
        '*****@*****.**',
        'phone':
        '0345 052 4001',
        'phone_other':
        '',
        'phone_other_comment':
        '',
        'website':
        None
    }

    assert response.context_data['other_offices'] == [{
        'address': ('The International Trade Centre\n'
                    '10 New Street\n'
                    'Midlands Business Park\n'
                    'Birmingham\n'
                    'B20 1RJ'),
        'is_match':
        False,
        'region_id':
        'west_midlands',
        'name':
        'DIT West Midlands',
        'address_street': ('The International Trade Centre, '
                           '10 New Street, '
                           'Midlands Business Park'),
        'address_city':
        'Birmingham',
        'address_postcode':
        'B20 1RJ',
        'email':
        '*****@*****.**',
        'phone':
        '0208 555 4001',
        'phone_other':
        '',
        'phone_other_comment':
        '',
        'website':
        None
    }]
Exemple #3
0
 async def test_client_fetch_leaderboards(self, mock):
     """Testing fetching the leaderboards"""
     content = self.load_resource(FILE_LEADERBOARD_CURRENT)
     mock.get(Leaderboard.get_url("Antica"), status=200, body=content)
     response = await self.client.fetch_leaderboard("Antica")
     self.assertIsInstance(response.data, Leaderboard)
Exemple #4
0
 async def test_client_fetch_forum_board(self, mock):
     """Testing fetching a forum board"""
     content = self.load_resource(FILE_BOARD_THREAD_LIST)
     mock.get(BoardEntry.get_url(1), status=200, body=content)
     response = await self.client.fetch_forum_board(1)
     self.assertIsInstance(response.data, ForumBoard)
Exemple #5
0
 async def test_client_fetch_forum_world_boards(self, mock):
     """Testing fetching the world boards"""
     content = self.load_resource(FILE_WORLD_BOARDS)
     mock.get(BoardEntry.get_world_boards_url(), status=200, body=content)
     response = await self.client.fetch_forum_world_boards()
     self.assertIsInstance(response.data[0], BoardEntry)
Exemple #6
0
 async def test_client_fetch_event_calendar(self, mock):
     """Testing fetching the auction history"""
     content = self.load_resource(FILE_EVENT_CALENDAR)
     mock.get(EventSchedule.get_url(), status=200, body=content)
     response = await self.client.fetch_event_schedule()
     self.assertIsInstance(response.data, EventSchedule)
Exemple #7
0
 async def test_client_fetch_auction(self, mock):
     """Testing fetching an auction"""
     content = self.load_resource(FILE_AUCTION_FINISHED)
     mock.get(Auction.get_url(134), status=200, body=content)
     response = await self.client.fetch_auction(134)
     self.assertIsInstance(response.data, Auction)