Esempio n. 1
0
    def test_use_bbox_instead_of_lat_long(self):
        # Arrange
        lat = 1
        long = 2
        bbox = [59.811225, 20.623165, 70.07531, 31.569525]
        bot = EverywordBot("consumer_key",
                           "consumer_secret",
                           "access_token",
                           "token_secret",
                           "test/test_source.txt",
                           "index_file",
                           lat=lat,
                           long=long,
                           bbox=bbox)
        bot._get_current_line = lambda index: "word"
        stub = TwitterStub()
        bot.twitter.update_status = stub.twitter_update_status

        # Act
        bot.post()

        # Assert
        self.assertNotEqual(stub.lat, 1)
        self.assertNotEqual(stub.long, 2)
        self.assertTrue(bbox[0] <= stub.lat <= bbox[2])
        self.assertTrue(bbox[1] <= stub.long <= bbox[3])
Esempio n. 2
0
    def test__get_current_index_file_not_exist(self):
        # Arrange
        bot = EverywordBot("consumer_key", "consumer_secret", "access_token",
                           "token_secret", "_source_file", "no_index_file")

        # Act
        index = bot._get_current_index()

        # Assert
        self.assertEqual(index, 0)
Esempio n. 3
0
    def test__get_current_index_file_not_exist(self):
        # Arrange
        bot = EverywordBot("consumer_key", "consumer_secret",
                           "access_token", "token_secret",
                           "_source_file", "no_index_file")

        # Act
        index = bot._get_current_index()

        # Assert
        self.assertEqual(index, 0)
Esempio n. 4
0
    def test__increment_index(self):
        # Arrange
        bot = EverywordBot("consumer_key", "consumer_secret",
                           "access_token", "token_secret",
                           "_source_file", "test/test_index.txt")

        # Act
        bot._increment_index(0)

        # Assert
        index = bot._get_current_index()
        self.assertEqual(index, 1)
Esempio n. 5
0
    def test__get_current_line(self):
        # Arrange
        bot = EverywordBot("consumer_key", "consumer_secret",
                           "access_token", "token_secret",
                           "test/test_source.txt", "index_file")
        index = 1

        # Act
        line = bot._get_current_line(index)

        # Assert
        self.assertEqual(line, "word2")
Esempio n. 6
0
    def test__increment_index(self):
        # Arrange
        bot = EverywordBot("consumer_key", "consumer_secret", "access_token",
                           "token_secret", "_source_file",
                           "test/test_index.txt")

        # Act
        bot._increment_index(0)

        # Assert
        index = bot._get_current_index()
        self.assertEqual(index, 1)
Esempio n. 7
0
    def test__get_current_line_no_more_words(self):
        # Arrange
        bot = EverywordBot("consumer_key", "consumer_secret", "access_token",
                           "token_secret", "test/test_source.txt",
                           "index_file")
        index = 3

        # Act / Assert
        with self.assertRaises(EOFError) as context:
            bot._get_current_line(index)

        self.assertIn("No more words", str(context.exception))
Esempio n. 8
0
    def test__get_current_line(self):
        # Arrange
        bot = EverywordBot("consumer_key", "consumer_secret", "access_token",
                           "token_secret", "test/test_source.txt",
                           "index_file")
        index = 1

        # Act
        line = bot._get_current_line(index)

        # Assert
        self.assertEqual(line, "word2")
Esempio n. 9
0
    def test__random_point_in(self):
        # Arrange
        bbox = [59.811225, 20.623165, 70.07531, 31.569525]
        bot = EverywordBot("consumer_key", "consumer_secret",
                           "access_token", "token_secret",
                           "test/test_source.txt", "index_file")

        # Act
        lat, long = bot._random_point_in(bbox)

        # Assert
        self.assertTrue(bbox[0] <= lat <= bbox[2])
        self.assertTrue(bbox[1] <= long <= bbox[3])
Esempio n. 10
0
    def test__random_point_in(self):
        # Arrange
        bbox = [59.811225, 20.623165, 70.07531, 31.569525]
        bot = EverywordBot("consumer_key", "consumer_secret", "access_token",
                           "token_secret", "test/test_source.txt",
                           "index_file")

        # Act
        lat, long = bot._random_point_in(bbox)

        # Assert
        self.assertTrue(bbox[0] <= lat <= bbox[2])
        self.assertTrue(bbox[1] <= long <= bbox[3])
    def test__post(self):
        # Arrange
        bot = EverywordBot("consumer_key", "consumer_secret",
                           "access_token", "token_secret",
                           "test/test_source.txt", "test/test_index.txt")
        bot.twitter.update_status = stub_twitter_update_status
        index_before = bot._get_current_index()

        # Act
        bot.post()

        # Assert
        index_after = bot._get_current_index()
        self.assertEqual(index_before + 1, index_after)
Esempio n. 12
0
    def test__prefix(self):
        # Arrange
        bot = EverywordBot("consumer_key", "consumer_secret",
                           "access_token", "token_secret",
                           "test/test_source.txt", "index_file",
                           prefix="aardvark ")
        bot._get_current_line = lambda index: "word"
        stub = TwitterStub()
        bot.twitter.update_status = stub.twitter_update_status

        # Act
        bot.post()

        # Assert
        self.assertEqual(stub.status, "aardvark word")
Esempio n. 13
0
    def test__suffix(self):
        # Arrange
        bot = EverywordBot("consumer_key",
                           "consumer_secret",
                           "access_token",
                           "token_secret",
                           "test/test_source.txt",
                           "index_file",
                           suffix=" zebra")
        bot._get_current_line = lambda index: "word"
        stub = TwitterStub()
        bot.twitter.update_status = stub.twitter_update_status

        # Act
        bot.post()

        # Assert
        self.assertEqual(stub.status, "word zebra")
Esempio n. 14
0
    def test_use_bbox_instead_of_lat_long(self):
        # Arrange
        lat = 1
        long = 2
        bbox = [59.811225, 20.623165, 70.07531, 31.569525]
        bot = EverywordBot("consumer_key", "consumer_secret",
                           "access_token", "token_secret",
                           "test/test_source.txt", "index_file",
                           lat=lat, long=long, bbox=bbox)
        bot._get_current_line = lambda index: "word"
        stub = TwitterStub()
        bot.twitter.update_status = stub.twitter_update_status

        # Act
        bot.post()

        # Assert
        self.assertNotEqual(stub.lat, 1)
        self.assertNotEqual(stub.long, 2)
        self.assertTrue(bbox[0] <= stub.lat <= bbox[2])
        self.assertTrue(bbox[1] <= stub.long <= bbox[3])
Esempio n. 15
0
    def test__post(self):
        # Arrange
        bot = EverywordBot("consumer_key", "consumer_secret", "access_token",
                           "token_secret", "test/test_source.txt",
                           "test/test_index.txt")
        stub = TwitterStub()
        bot.twitter.update_status = stub.twitter_update_status
        index_before = bot._get_current_index()

        # Act
        bot.post()

        # Assert
        index_after = bot._get_current_index()
        self.assertEqual(index_before + 1, index_after)