Ejemplo n.º 1
0
class JetpackTest(TestCase):

	def setUp(self):
		self.to_delete = []
		self.user = create_test_user(username=TEST_USERNAME)
		self.jetpack = Jet(name=TEST_JETPACK_NAME, creator=self.user)
		self.jetpack.save()
		self.version = JetVersion(jetpack=self.jetpack, name='first', author=self.user)
		self.version.save()

	def tearDown(self):
		self.user.delete()
		for o in self.to_delete:
			try:
				o.delete()
			except:
				print "Object %s can't be deleted" % str(o)

	def test_jetpack_creation(self):
		jetpack = Jet.objects.get(name=TEST_JETPACK_NAME)
		self.failUnless(jetpack)

	def test_first_as_base(self):
		"""
		First is base
		"""
		# first created version is base one
		self.failUnless(self.jetpack.base_version)
		self.assertEqual(self.jetpack.base_version.name, 'first')

	def test_version_numbering(self):
		self.assertEqual(self.jetpack.base_version.fullname, 'first.0')

	def test_switch_base(self):
		"""
		There is only one base version per Jetpack
		"""
		# next base version 
		first_base_id = self.jetpack.base_version.id
		second_base = JetVersion(
			jetpack=self.jetpack, name='second', is_base=True, author=self.user
		)
		second_base.save()
		self.assertEqual(second_base.name, self.jetpack.base_version.name)
		
		first_base = JetVersion.objects.get(pk=first_base_id)
		self.assertEqual(first_base.is_base, False)

	def test_assign_capability(self):
		capability = Cap(name="Capability assigned", creator=self.user)
		capability.save()
		version = CapVersion(capability=capability, name='0.0', author=self.user)
		version.save()
		self.jetpack.base_version.capabilities.add(version)
		self.failUnless(version in self.jetpack.base_version.capabilities.all())
		
	def test_increase_counter(self):
		second_version=JetVersion(jetpack=self.jetpack, name='first', author=self.user)
		second_version.save()
		self.assertEqual(second_version.counter,1)
Ejemplo n.º 2
0
	def test_switch_base(self):
		"""
		There is only one base version per Jetpack
		"""
		# next base version 
		first_base_id = self.jetpack.base_version.id
		second_base = JetVersion(
			jetpack=self.jetpack, name='second', is_base=True, author=self.user
		)
		second_base.save()
		self.assertEqual(second_base.name, self.jetpack.base_version.name)
		
		first_base = JetVersion.objects.get(pk=first_base_id)
		self.assertEqual(first_base.is_base, False)
Ejemplo n.º 3
0
	def setUp(self):
		self.to_delete = []
		self.user = create_test_user(username=TEST_USERNAME)
		self.jetpack = Jet(name=TEST_JETPACK_NAME, creator=self.user)
		self.jetpack.save()
		self.version = JetVersion(jetpack=self.jetpack, name='first', author=self.user)
		self.version.save()
Ejemplo n.º 4
0
def item_create(r, type):
	"""
	Create new item (Jetpack/Capability)
	This is a result of a popup window with just name and description
	Version will be saved in the item_version_create
	"""
	Klass = Jet if type=="jetpack" else Cap
	item = Klass(
		creator=r.user,
		name=r.POST.get("%s_name" % type),
		description=r.POST.get("%s_description" % type)
	)
	# TODO: validate
	item.save()

	if type == 'jetpack':
		version = JetVersion(
			jetpack=item, 
			author=r.user,
			content='',
			description='',
			manifest=simplejson.dumps({
				"contributors": [],
				#"url": '',
				#'license': '',
				'version': '0.0.0',
				#'dependencies': [],
				#'lib': 'lib',
				#'tests': 'tests',
				#'packages': 'packages',
				'main': 'main',
				'name': item.slug,
				'fullName': item.name,
				'description': item.description,
				'author': r.user.get_profile().get_name()
			})
		) 
	elif type == "capability":
		version = CapVersion(capability=item, author=r.user) 

	version.save()
	
	return render_to_response("json/%s_created.json" % type, {type: item},
				context_instance=RequestContext(r),
				mimetype='application/json')
Ejemplo n.º 5
0
	def test_increase_counter(self):
		second_version=JetVersion(jetpack=self.jetpack, name='first', author=self.user)
		second_version.save()
		self.assertEqual(second_version.counter,1)