Ejemplo n.º 1
0
	def test_scrape(self):
		views.announce(self._build_announce_request_object(ip='1.1.1.1',
			port='1234', left='0', event='completed'))
		views.announce(self._build_announce_request_object(ip='2.2.2.2',
			port='1234', left='200'))

		# Scrape with info_hash specified
		query_string = { 'info_hash': SAMPLE_HASH }
		request = Request(EnvironBuilder(
			method='GET', query_string=query_string
		).get_environ())
		response_data = bencode.bdecode(views.scrape(request).data)
		self.assertEqual(response_data, {
			'files': {
				SAMPLE_HASH: {
					'complete': 1,
					'downloaded': 1,
					'incomplete': 1,
				}
			},
		})

		# Scrape with no info_hash specified
		request = Request(EnvironBuilder(method='GET').get_environ())
		response_data = bencode.bdecode(views.scrape(request).data)
		self.assertEqual(response_data.get('files').get(SAMPLE_HASH), {
				'complete': 1,
				'downloaded': 1,
				'incomplete': 1,
		})
Ejemplo n.º 2
0
	def test_announce(self):
		response_data = bencode.bdecode(views.announce(
			self._build_announce_request_object(ip='1.1.1.1', port='1234')
		).data)

		self.assert_(
			utils.compact('1.1.1.1', 1234)in response_data.get('peers')
		)
Ejemplo n.º 3
0
	def test_failure(self):
		# Announce with no info_hash specified
		request = Request(EnvironBuilder(method='GET').get_environ())
		response_data = bencode.bdecode(views.announce(request).data)
		failure = {
			'failure reason': 'Missing info_hash',
			'failure code': 101,
		}
		self.assertEqual(response_data, failure)
Ejemplo n.º 4
0
	def test_post_announce(self):
		# Try HTTP POST to announce instead of GET
		request = Request(EnvironBuilder(method='POST').get_environ())
		response_data = bencode.bdecode(views.announce(request).data)
		failure = {
			'failure reason':
				'Invalid request type: client request was not a HTTP GET',
			'failure code': 100
		}
		self.assertEqual(response_data, failure)
Ejemplo n.º 5
0
	def test_bad_info_hash(self):
		"""
		Announcing with an info_hash that's not registed should give a failure
		"""
		request = self._build_announce_request_object(
			info_hash='\x98H\x16\xfd2\x96"\x87n\x14\x90v4&No3.\x9f\xb2'
		)
		response_data = bencode.bdecode(views.announce(request).data)
		failure = {
			'failure reason': 'info_hash not found in the database',
			'failure code': 200,
		}
		self.assertEqual(response_data, failure)