def test_is_watched_returns_true_if_user_in_watchers_list(self): user_1 = UserFactory.build(id=1) user_2 = UserFactory.build(id=2) decision = DecisionFactory.build(organization=OrganizationFactory.build()) notice_type = NoticeTypeFactory.build() observed_item_1 = ObservedItemFactory.build(user=user_1, observed_object=decision, notice_type=notice_type) observed_item_2 = ObservedItemFactory.build(user=user_2, observed_object=decision, notice_type=notice_type) mock_item = MagicMock() mock_item.watchers.all = lambda: [observed_item_1, observed_item_2] self.assertTrue(is_watching(user_1, mock_item))
def test_is_watched_returns_true_if_user_in_watchers_list(self): user_1 = UserFactory.build(id=1) user_2 = UserFactory.build(id=2) decision = DecisionFactory.build( organization=OrganizationFactory.build()) notice_type = NoticeTypeFactory.build() observed_item_1 = ObservedItemFactory.build(user=user_1, observed_object=decision, notice_type=notice_type) observed_item_2 = ObservedItemFactory.build(user=user_2, observed_object=decision, notice_type=notice_type) mock_item = MagicMock() mock_item.watchers.all = lambda: [observed_item_1, observed_item_2] self.assertTrue(is_watching(user_1, mock_item))
def add_watchers(decision): users = UserFactory.build_batch(size=3) watchers = [] for index, user in enumerate(users): user.id = index notice_type = NoticeTypeFactory.build(id=index) decision.watchers.add( ObservedItemFactory.build(id=index, added=datetime.now(utc), user=user, observed_object=decision, notice_type=notice_type)) # decision.watchers = watchers return decision
def add_watchers(decision): users = UserFactory.build_batch(size=3) watchers = [] for index, user in enumerate(users): user.id = index notice_type = NoticeTypeFactory.build(id=index) decision.watchers.add( ObservedItemFactory.build( id=index, added=datetime.now(utc), user=user, observed_object=decision, notice_type=notice_type ) ) # decision.watchers = watchers return decision