예제 #1
0
 def setUp(self):
     super(TestEvent, self).setUp()
     self.object_under_test = Event(
         creation_time=Mock(datetime),
         content="This is a sentence #hashtag1 #hashtag2 @user1 @user2",
         categories={"hashtag1", "hashtag2"},
         people={"user1", "user2"})
예제 #2
0
class TestEvent(TestCase):
    def setUp(self):
        super(TestEvent, self).setUp()
        self.object_under_test = Event(
            creation_time=Mock(datetime),
            content="This is a sentence #hashtag1 #hashtag2 @user1 @user2",
            categories={"hashtag1", "hashtag2"},
            people={"user1", "user2"})

    def test_should_match_category_return_true_given_matching_category(self):
        matching_category = "hashtag1"
        self.assertTrue(
            self.object_under_test.matches_category(matching_category))

    def test_should_match_category_return_false_given_not_matching_category(
            self):
        not_matching_category = "random category"
        self.assertFalse(
            self.object_under_test.matches_category(not_matching_category))

    def test_should_match_person_return_true_given_matching_person(self):
        matching_user = "******"
        self.assertTrue(self.object_under_test.matches_person(matching_user))

    def test_should_match_person_return_false_given_not_matching_person(self):
        not_matching_user = "******"
        self.assertFalse(
            self.object_under_test.matches_person(not_matching_user))
예제 #3
0
    def setUp(self):
        super().setUp()
        self.object_under_test = JsonEncoder()

        self.events = [
            Event(datetime.datetime(2012, 4, 5), "Content", {"cat1", "cat2"}, {"all"}),
            Event(datetime.datetime(2014, 12, 12), "Yet another content", {"cat"}, {"all, john"}),
        ]
예제 #4
0
    def parse(self, message, creation_time=datetime.now()):
        words = self._split_by_whitespace(message)
        categories = self._with_matching_prefix("#", words)
        people = self._with_matching_prefix("@", words)

        return Event(creation_time=creation_time,
                     content=message,
                     categories=categories,
                     people=people)
    def test_should_not_duplicate_any_person(self):
        event_message = "Yet another @person event message #cat #cat @person"
        expected_event = Event(creation_time=self.date_mock,
                               content=event_message,
                               categories={"cat"},
                               people={"person"})

        actual_event = self.object_under_test.parse(event_message,
                                                    self.date_mock)

        self.assertEqual(actual_event, expected_event)
    def test_should_not_duplicate_any_category(self):
        event_message = "Yet another event message #cat #cat @john @michael"
        expected_event = Event(creation_time=self.date_mock,
                               content=event_message,
                               categories={"cat"},
                               people={"john", "michael"})

        actual_event = self.object_under_test.parse(event_message,
                                                    self.date_mock)

        self.assertEqual(actual_event.__dict__, expected_event.__dict__)
    def test_parsing_event(self):
        event_message = "Yet another event message #message #fancyhashtag @john @michael"
        expected_event = Event(creation_time=self.date_mock,
                               content=event_message,
                               categories={"message", "fancyhashtag"},
                               people={"john", "michael"})

        actual_event = self.object_under_test.parse(event_message,
                                                    self.date_mock)

        self.assertEqual(actual_event, expected_event)
    def test_neither_category_nor_person_should_be_recognized_when_not_whitespace_separated(
            self):
        event_message = "Another message#tag,@person ,#tag"
        expected_event = Event(creation_time=self.date_mock,
                               content=event_message,
                               categories={},
                               people={})

        actual_event = self.object_under_test.parse(event_message,
                                                    self.date_mock)

        self.assertEqual(actual_event, expected_event)
 def _create_event(self, categories, people):
     return Event(creation_time=Mock(datetime),
                  content="",
                  categories=categories,
                  people=people)