def setUp(self): UserViewTest.setUp(self) self.activity = UserActivity( user_id=self.user.id, title="New Activity" ) self.activity.add()
def setUp(self): UserTest.setUp(self) self.user_production = UserProduction( user_id=self.user.id, concept="Test Production", quantity=10, date=date.today() ) self.user_production.add() user_production2 = UserProduction( user_id=self.user.id, concept="Test Production", quantity=10, date=date.today() + timedelta(days=10) ) user_production2.add() self.user_activity = UserActivity( user_id=self.user.id, title="Test Activity" ) self.user_activity.add() self.order = Order( user_id=self.user.id, title="Test Activity", status="Cancelada", due_date=date.today() ) self.order.add() order2 = Order( user_id=self.user.id, title="Test Activity", status="Pendiente", due_date=date.today() + timedelta(days=10) ) order2.add()
def setUp(self): UserTest.setUp(self) self.activity = UserActivity( user_id=self.user.id, title="Test Activity", description="Test Description" ) self.activity.add()
class TestUpdateActivity(UserViewTest): def setUp(self): UserViewTest.setUp(self) self.activity = UserActivity( user_id=self.user.id, title="New Activity" ) self.activity.add() def test_should_update_activity_given_valid_activity_input_and_LUHP(self): self.login_user(self.admin_user) activity_input = dict( title="New Activity", description="Test Description" ) with self.client as client: client.post( url_for('user.update_activity', activity_id=self.activity.id), data=activity_input ) self.db.session.rollback() self.assertEqual(self.activity.title, "New Activity") def test_should_not_update_activity_given_invalid_activity_input_and_LUHP(self): self.login_user(self.admin_user) activity_input = dict( title="", description="Test Description" ) with self.client as client: client.post( url_for('user.update_activity', activity_id=self.activity.id), data=activity_input ) self.db.session.rollback() self.assertNotEqual(self.activity.title, "") def test_should_redirect_given_LUHNP(self): self.login_user(self.normal_user) with self.client as client: response = client.get( url_for('user.update_activity', activity_id=self.activity.id) ) self.assertStatus(response, 302)
def test_should_not_add_activity_given_invalid_activity(self): activity = UserActivity( user_id=self.user.id, title="", description="" ) activity.request.add() self.assertNotIn(activity, self.db.session)
def test_should_return_error_given_empty_title(self): activity = UserActivity( user_id=self.user.id, title="", description="Test Description" ) error = activity.validation.validate_empty_values() self.assertNotEqual(error, None)
def test_should_not_return_error_given_valid_activity(self): activity = UserActivity( user_id=self.user.id, title="Test Activity", description="" ) error = activity.validation.validate() self.assertEqual(error, None)
def assign_activity(id): if request.method == "POST": activity = UserActivity(user_id=id, title=request.form['title'], description=request.form['description']) error = activity.request.add() if not error: return redirect(url_for('user.profile', id=id)) flash(error) return render_template("user/activity/assign.html", activity_heads=activity_heads)