Ejemplo n.º 1
0
    def test_delete_does_nothing_when_aircraft_does_not_exist(self):
        seen_datetime = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
        client_existing = Client([None, '127.0.0.1', seen_datetime])
        client_id = self.mapper.insert(client_existing)
        client_non_existing = Client([0, '127.0.0.1', seen_datetime])

        self.mapper.delete(client_non_existing)

        # assert that existing client was not affected
        client = self.mapper.fetch(client_id)
        self.assertIsNotNone(client)
Ejemplo n.º 2
0
    def test_update_updates_client_when_exists(self):
        seen_datetime = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
        client = Client([None, '127.0.0.1', seen_datetime])
        client_id = self.mapper.insert(client)

        client = self.mapper.fetch(client_id)
        client.ip = '127.0.0.2'
        self.mapper.update(client)

        # assert that ip column was updated
        client = self.mapper.fetch(client_id)
        self.assertEqual('127.0.0.2', client.ip)
Ejemplo n.º 3
0
    def test_map_returns_client_when_all_fields_exist(self):
        datetime_expected = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')

        client_expected = Client([None, self.data['ip'], datetime_expected])
        client_actual = self.mapper.map(self.data['ip'])

        self.assertEqual(str(client_expected), str(client_actual))
Ejemplo n.º 4
0
    def map(ip):
        client = Client([
            None, ip,
            datetime.strftime(datetime.utcnow(), '%Y-%m-%d %H:%M:%S')
        ])

        return client
Ejemplo n.º 5
0
    def test_fetch_identical_returns_client_when_exists(self):
        seen_datetime = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
        client = Client([None, '127.0.0.1', seen_datetime])

        self.mapper.insert(client)

        client = self.repository.fetch_identical(client)
        self.assertNotEqual(None, client)
Ejemplo n.º 6
0
    def test_init_sets_is_online_to_false_when_last_seen_is_more_than_threshold(
            self):
        self.data[2] = (
            datetime.datetime.utcnow() -
            datetime.timedelta(minutes=45)).strftime('%Y-%m-%d %H:%M:%S')
        client = Client(self.data)

        self.assertFalse(client.is_online)
Ejemplo n.º 7
0
    def test_init_fills_properties(self):
        client = Client(self.data)

        self.assertEqual(self.data[0], client.id)
        self.assertEqual(self.data[1], client.ip)
        self.assertEqual(
            datetime.datetime.strptime(self.data[2], '%Y-%m-%d %H:%M:%S'),
            client.last_seen)
Ejemplo n.º 8
0
 def setUp(self):
     timestamp = int(datetime.strftime(datetime.utcnow(), '%s'))
     self.aircraft = Aircraft([1, 'tail', None, timestamp, timestamp])
     self.client = Client(
         [1, '127.0.0.1',
          datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')])
     self.data = {'flight': 'foo', 'text': 'bar', 'timestamp': timestamp}
     self.mapper = MessageInputMapper()
Ejemplo n.º 9
0
    def fetch(self, client_id):
        self.adapter.execute('SELECT id, ip, last_seen FROM clients WHERE id = ?', (client_id,))
        result = self.adapter.fetchone()

        client = None
        if result:
            client = Client(result)

        return client
Ejemplo n.º 10
0
    def test_delete_all_deletes_clients_when_exist(self):
        seen_datetime = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
        client = Client([None, '127.0.0.1', seen_datetime])
        client_id = self.mapper.insert(client)

        self.mapper.delete_all()

        client = self.mapper.fetch(client_id)
        self.assertIsNone(client)
Ejemplo n.º 11
0
    def test_fetch_returns_client_when_exists(self):
        seen_datetime = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
        client = Client([None, '127.0.0.1', seen_datetime])

        client_id = self.mapper.insert(client)

        client = self.mapper.fetch(client_id)
        self.assertIsNotNone(client)
        self.assertIsNotNone(client_id)
Ejemplo n.º 12
0
    def test_fetch_identical_returns_none_when_client_does_not_exist(self):
        seen_datetime = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
        client = Client([None, '127.0.0.1', seen_datetime])

        client = self.repository.fetch_identical(client)
        self.assertEqual(None, client)
Ejemplo n.º 13
0
    def test_str_returns_expected_string(self):
        str_expected = 'ID: {}, IP: {}, Last Seen: {}, Is Online: {}'.format(
            self.data[0], self.data[1], self.data[2], True)
        client = Client(self.data)

        self.assertEqual(str_expected, str(client))
Ejemplo n.º 14
0
    def test_init_sets_is_online_to_true_when_last_seen_is_less_than_threshold(
            self):
        client = Client(self.data)

        self.assertTrue(client.is_online)
Ejemplo n.º 15
0
 def setUp(self):
     timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
     self.client = Client(
         [1, '127.0.0.1',
          datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')])
     self.data = [1, 2, 'foo', 'bar', timestamp]