コード例 #1
0
	def test_posts(self):
		#testing db is empty
		assert User.query.count() is 0
		assert Post.query.count() is 0

        	u1 = User('testuser1', 'testpassword1')
        	u2 = User('testuser2', 'testpassword2')
        	ua1 = User('testadmin1', 'testpassword1', True)
        	ua2 = User('testadmin2', 'testpassword2', True)

		db.session.add(u1)
        	db.session.add(u2)
		db.session.add(ua1)
		db.session.add(ua2)
        	db.session.commit()
		assert User.query.count() is 4

		#need to first create followers for future posts testing
		#ensure there is currently no one following each other
        	assert u1.unfollow(u2) is None
        	assert u2.unfollow(u1) is None
		assert ua1.unfollow(ua2) is None
		assert ua2.unfollow(ua1) is None
		assert ua1.unfollow(u1) is None
		assert ua2.unfollow(u2) is None
		#make users follow each other and check success (follow returns self on success)
		assert u1.follow(u2) is not None
		assert u1.check_following(u2)
		assert u1.followed.count() is 1
		assert u2 in u1.get_followers()
		assert u1 in u2.get_followed()

		assert ua1.follow(ua2) is not None
		assert ua1.check_following(ua2)
		assert ua1.followed.count() is 1
		assert ua2 in ua1.get_followers()
		assert ua1 in ua2.get_followed()
		
		assert ua1.follow(u1) is not None
		assert ua1.check_following(u1)
		assert ua1.followed.count() == 2
		assert u1 in ua1.get_followers()
		assert ua1 in u1.get_followed()

		#test creating posts
		assert u1.create_post("This is user1's post!") is not None
		assert len(u1.get_posts()) is 1
		assert (u1.get_posts()[0].message == "This is user1's post!")
		assert u1.get_posts()[0].owner == u1.username

		assert u2.create_post("This is user2's post!") is not None
		assert len(u2.get_posts()) is 1
		assert (u2.get_posts()[0].message == "This is user2's post!")
		assert u2.get_posts()[0].owner == u2.username
		
		assert ua1.create_post("This is admin1's post!") is not None
		assert len(ua1.get_posts()) is 1
		assert (ua1.get_posts()[0].message == "This is admin1's post!")
		assert ua1.get_posts()[0].owner == ua1.username

		#test fetching followers posts
		assert len(u1.get_followers_posts()) is 1
		assert (u1.get_followers_posts()[0].message == "This is admin1's post!")
		assert u1.get_followers_posts()[0].owner == ua1.username
		assert len(u1.get_following_posts()) is 1
		assert (u1.get_following_posts()[0].message == "This is user2's post!")
		assert u1.get_following_posts()[0].owner == u2.username
		assert len(u2.get_followers_posts()) is 1
		assert (u2.get_followers_posts()[0].message == "This is user1's post!")
		assert u2.get_followers_posts()[0].owner == u1.username
		assert len(u2.get_following_posts()) is 0
		assert len(ua1.get_followers_posts()) is 0
		assert len(ua1.get_following_posts()) is 1
		assert (ua1.get_following_posts()[0].message == "This is user1's post!")
		assert ua1.get_following_posts()[0].owner == u1.username

		#unfollow
		assert u1.unfollow(u2) is not None
		assert ua1.unfollow(ua2) is not None
		assert ua1.unfollow(u1) is not None
		assert not u1.check_following(u2)
		assert not ua1.check_following(ua2)
		assert not ua1.check_following(u2)		
		
		#test fetching followers posts
		assert len(u1.get_following_posts()) is 0
		assert len(u1.get_followers_posts()) is 0
		assert len(u2.get_following_posts()) is 0
		assert len(u2.get_followers_posts()) is 0
		assert len(ua1.get_following_posts()) is 0
		assert len(ua1.get_followers_posts()) is 0
コード例 #2
0
def reload_db():
	from cris.courses.model import Course
	from cris.reviews.model import Review
	from cris.instructors.model import Instructor
	from cris.users.model import User

	db.drop_all()
	db.create_all()

	oo = Course('Comp2150', 'Object Orientation', 'Calendar Description: Design and development of object-oriented software. Topics will ' +
	'include inheritance, polymorphism, data abstraction and encapsulation. Examples will be drawn from several programming languages (Lab required).' +
	'Prerequisite: COMP 2140 and 2160 This course is a prerequisite for: COMP 3010, COMP 3350 and COMP 4290', 'Science', 'Fall')

	aut = Course('Comp3030', 'Automata Theory and Formal Languages', 'Calendar Description: An introduction to automata theory, grammars, formal languages' +
	'and their applications. Topics: finite automata, regular expressions and their properties;' +
	'context-free grammars, pushdown automata and properties of context-free languages;' +
	'turing machines. Applications: lexical analysis, text editing, machine design, syntax' +
	'analysis, parser generation.' +
	'Prerequisites: COMP 2080 and COMP 2140. This course is a prerequisite for: COMP 4310', 'Science', 'Winter')

	aa = Course('Comp3170', 'Analysis of Algorithms and Data Structures', 'Calendar Description: Fundamental Algorithms for sorting, searching, storage' +
	'management, graphs, databases and computational geometry. Correctness and Analysis' +
	'of those Algorithms using specific data structures. An introduction to lower bounds and' +
	'intractability. Prerequisites: COMP 2080 and COMP 2140. This course is a prerequisite for: COMP 4340 and COMP 4420', 'Science', 'Fall')
	
	ai = Course('Comp3190', 'Artificial Intelligence', 'Calendar Description: Principles of artificial intelligence; problem solving, knowledge' +
	'representation and manipulation; the application of these principles to the solution of hard' +
	'problems. Prerequisite: COMP 2140. This course is a prerequisite for: COMP 4190, COMP 4200 and COMP 4360.', 'Science', 'Winter')
	
	se1 = Course('Comp3350', 'Software Engineering 1', 'Calendar Description: Introduction to software engineering. Software life cycle' +
	'models, system and software requirements analysis, specifications, software design,' +
	'testing, and maintenance, software quality. Prerequisite: COMP 2150. This course is a prerequisite for: COMP 4050, COMP 4350 and COMP 4560', 'Science', 'Fall')
	
	os1 = Course('Comp3430', 'Operating Systems 1', 'Calendar Description: Operating systems, their design, implementation, and usage (Lab ' +
	'required). Prerequisite: COMP 2140 and COMP 2280 Recommended: COMP 2160 ' +
	'This course is a prerequisite for: COMP 4430, COMP 4510, COMP 4550 and COMP 4580', 'Science', 'Fall')

	se2 = Course('Comp4350', 'Software Engineering 2', 'Calendar Description: Advanced treatment of software development methods. Topics' +
	'will be selected from requirements gathering, design methodologies, prototyping,' +
	'software verification and validation. Prerequisite: COMP 3350.', 'Science', 'Winter')
	
	h1 = Course('Hist1200', 'An Introduction to the History of Western Civilization', 'Calendar Description: An introductory survey of the cultural' +
	' history of the Western world from the ancient Greeks to the present. Students may not hold credit for HIST 1200 and any of: HIST 1201 or HIST 1350', 'Arts', 'Fall')
	
	h2 = Course('Hist2080', 'The Byzantine Empire and the Slavic World', 'A study of the rise and fall of the "later Roman Empire" and of its relations with Russia, Bulgaria, Serbia and the west (i.e., in the crusades), 800-1261 A.D. ',
	'Arts', 'Fall')
	
	e1 = Course('Engl2090', 'Literature of the Seventeenth Century', 'A survey of poetry, prose and drama by major and minor writers in historical context. Students may not hold credit for both ENGL 2090 and ENGL 2091 ' +
	'. Prerequisite: [a grade of "C" or better in ENGL 1200 or ENGL 1201 or ENGL 1300 or ENGL 1301] or [a grade of "C" or better in each of ENGL 1310 and ENGL 1340]. ',
	'Arts', 'Winter')
	
	e2 = Course('Eng7010', 'The Engineering Design Process', 'Consideration of the Engineering Design process and the logic upon which it is based. Explores both the history and possible future directions of the process from technical, social and environmental points of view.',
	'Graduate', 'Winter')
	
	review1 = Review('Comp4350', 4, 'This was a hard course that required a lot of background research and work.', 0.75, 3, 4)
	review2 = Review('Comp2150', 4, 'I learned alot from this course and I can now make a simple program.', 0.50, 2, 4)
	review3 = Review('Comp4350', 3, 'Take this course if you do not want to sleep for like a week at the end of March', 0.50, 2, 4)
	review4 = Review('Comp3430', 5, 'Threads are fun!', 0.75, 3, 4)
	review5 = Review('Comp3030', 5, 'Finite state machines are pretty easy', 1.0, 1, 0);

        prof1 = Instructor('John Braico')
        prof2 = Instructor('Mike Zapp')
        prof3 = Instructor('Alan Marshall')
        prof4 = Instructor('Christina Penner')
        prof5 = Instructor('John Anderson')
        prof6 = Instructor('Pourang Irani')
        prof7 = Instructor('James Young')
        prof8 = Instructor('John McDonald')
        prof9 = Instructor('Franz Ferdinand')
        prof10 = Instructor('Jean-Luc Picard')
        prof11 = Instructor('Dilbert')
    
	admin = User('admin', 'default', True)
	test_user = User('test', 'password')	
	james = User('james', 'j123')
	chris = User('chris', 'c123') 
	sam = User('sam', 's123')

	post1 = Post("sam", "Just finished having some cookies and punch at the Comp Sci Staff Lounge!")
	post2 = Post("chris", "@Sam - I prefer beer and pizza!!")	
	post3 = Post("james", "Finally finished my SE2 project! I can finally relax!!")

	db.session.add(oo)
	db.session.add(aut)
	db.session.add(aa)
	db.session.add(ai)
	db.session.add(se1)
	db.session.add(os1)
	db.session.add(se2)
	db.session.add(h1)
	db.session.add(h2)
	db.session.add(e1)
	db.session.add(e2)

	db.session.add(review1)
	db.session.add(review2)
	db.session.add(review3)
	db.session.add(review4)
	db.session.add(review5)
	
	db.session.add(prof1)
	db.session.add(prof2)
	db.session.add(prof3)
	db.session.add(prof4)
	db.session.add(prof5)
	db.session.add(prof6)
	db.session.add(prof7)

	db.session.add(admin)
	db.session.add(test_user)
	db.session.add(james)
	db.session.add(chris)
	db.session.add(sam)
	
	db.session.add(post1)
	db.session.add(post2)
	db.session.add(post3)

	db.session.commit()

 	prof1.teach(oo)
	prof1.teach(aut)
	prof2.teach(se2)
	prof2.teach(ai)
	prof3.teach(se1)
	prof3.teach(os1)
	prof4.teach(aa)
	prof8.teach(h1)
	prof9.teach(h2)
	prof10.teach(e1)
	prof11.teach(e2)
	
	sam.follow(james)
	chris.follow(sam)
コード例 #3
0
	def test_followers(self):
		#testing db is empty
		assert User.query.count() is 0

        	u1 = User('testuser1', 'testpassword1')
        	u2 = User('testuser2', 'testpassword2')
        	ua1 = User('testadmin1', 'testpassword1', True)
        	ua2 = User('testadmin2', 'testpassword2', True)

		db.session.add(u1)
        	db.session.add(u2)
		db.session.add(ua1)
		db.session.add(ua2)
        	db.session.commit()
		assert User.query.count() is 4

		#ensure there is currently no one following each other
        	assert u1.unfollow(u2) is None
        	assert u2.unfollow(u1) is None
		assert ua1.unfollow(ua2) is None
		assert ua2.unfollow(ua1) is None
		assert ua1.unfollow(u1) is None
		assert ua2.unfollow(u2) is None
		#make users follow each other and check success (follow returns self on success)
		assert u1.follow(u2) is not None
		assert u1.check_following(u2)
		assert u1.followed.count() is 1
		assert u2 in u1.get_followers()
		assert u1 in u2.get_followed()

		assert ua1.follow(ua2) is not None
		assert ua1.check_following(ua2)
		assert ua1.followed.count() is 1
		assert ua2 in ua1.get_followers()
		assert ua1 in ua2.get_followed()
		
		assert ua1.follow(u1) is not None
		assert ua1.check_following(u1)
		assert ua1.followed.count() == 2
		assert u1 in ua1.get_followers()
		assert ua1 in u1.get_followed()

		#check doing same follows does not succeed (follow returns None on failure)
		assert u1.follow(u2) is None
		assert ua1.follow(ua2) is None
		assert ua1.follow(u1) is None
		#test unfollow
		assert u1.unfollow(u2) is not None
		assert ua1.unfollow(ua2) is not None
		assert ua1.unfollow(u1) is not None
		assert not u1.check_following(u2)
		assert not ua1.check_following(ua2)
		assert not ua1.check_following(u2)