Esempio n. 1
0
 def test_should_have_at_least_one_direction(self):
     self.assertGreaterEqual(len(
         Station(Faker().word, {
             'd': TimeTableStub(tuple())
         }).get_directions()),
                             1,
                             msg='Should have at least one direction')
Esempio n. 2
0
 def test_should_have_time_table_for_direction(self):
     self.assertIsInstance(
         Station(
             Faker().word,
             {'abc123': TimeTableStub(tuple())}
         ).time_tables['abc123'],
         TimeTable
     )
Esempio n. 3
0
class StationTest(unittest.TestCase):
    def setUp(self) -> None:
        self.station = Station(Faker().word, {'d': TimeTableStub(tuple())})

    def tearDown(self) -> None:
        del self.station

    @mock.patch('time_table.time_table.TimeTable')
    def test_should_have_name(self, mock_time_table):
        mock_time_table.get_departure_times.return_value = (4234, '6576',
                                                            45645)

        station_name = Faker().word
        self.assertEqual(station_name,
                         Station(station_name, {
                             Faker().word: mock_time_table
                         }).get_name(),
                         msg=f'Should be {station_name}')

    def test_should_know_actual_hour(self):
        self.assertEqual(datetime.datetime.now().strftime('%H:%M'),
                         self.station.get_current_time())

    def test_should_have_at_least_one_direction(self):
        self.assertGreaterEqual(len(
            Station(Faker().word, {
                'd': TimeTableStub(tuple())
            }).get_directions()),
                                1,
                                msg='Should have at least one direction')

    def test_should_have_time_table_for_direction(self):
        self.assertIsInstance(
            Station(Faker().word, {
                'abc123': TimeTableStub(tuple())
            }).time_tables['abc123'], TimeTable)

    def test_should_return_next_departure_time_depending_on_direction(self):
        station = Station(Faker().word, {'abc123': TimeTableStub(tuple())})
        self.assertGreater(
            Clock.get_hour_in_seconds(
                station.get_next_departure_time('abc123')), Clock.get_time())

    def test_should_raise_error_for_unknown_direction(self):
        with self.assertRaises(ValueError):
            self.station.get_next_departure_time(Faker().word)
Esempio n. 4
0
	def setUp(self):
		"""This method is run once before _each_ test method is executed"""
		self.station = Station()
		self.bike = Bike()
		self.bike2 = Bike()
		self.bike3 = Bike()
		self.bike4 = Bike()
		self.bike5 = Bike()
		self.bike6 = Bike()
Esempio n. 5
0
    def test_should_have_name(self, mock_time_table):
        mock_time_table.get_departure_times.return_value = (4234, '6576', 45645)

        station_name = Faker().word
        self.assertEqual(
            station_name,
            Station(station_name, {Faker().word: mock_time_table}).get_name(),
            msg=f'Should be {station_name}'
        )
Esempio n. 6
0
import unittest

import mock
from faker import Faker

from clock import Clock
from station.station import Station
from time_table.time_table import TimeTable


class Route:
    def __init__(self, route_name: str, stations: tuple):
        self.stations = {station.get_name(): station for station in stations}
        self.route_name = route_name


if __name__ == '__main__':
    directions = {
        'Gdańsk': TimeTable((345, 6546, 75688, 6537)),
        'Reda': TimeTable((45465, 8678, 9758))
    }

    station = Station('Rumia', directions)
    route = Route('Reda - Gdańsk', (station, ))

    print('Następny pociąg ze stacji {} do stacji {} odjedzie o godzinie {}'.
          format('Rumia', 'Gdańsk',
                 route.stations['Rumia'].get_next_departure_time('Gdańsk')))
Esempio n. 7
0
class TestPerson(object):

	@classmethod
	def setup_class(klass):
		"""This method is run once for each class before any tests are run"""

	@classmethod
	def teardown_class(klass):
		"""This method is run once for each class _after_ all tests are run"""

	def setUp(self):
		"""This method is run once before _each_ test method is executed"""
		self.person = Person()
		self.bike = Bike()
		self.bike2 = Bike()
		self.station = Station()

	def teardown(self):
		"""This method is run once after _each_ test method is executed"""
		pass
	
	def test_person_has_no_bikes(self):
		assert_equal(len(self.person.bikes), 0)

	def test_person_can_have_a_bike(self):
		self.person.rides(self.bike)
		assert_equal(len(self.person.bikes), 1)
		assert_in(self.bike, self.person.bikes)

	def test_person_cannot_ride_a_broken_bike(self):
		self.bike.break_bike()
		assert_equal(self.person.rides(self.bike), "Cannot ride a broken bike")

	def test_person_can_release_a_bike(self):
		self.person.rides(self.bike)
		self.person.release(self.bike)
		assert_equal(len(self.person.bikes), 0)

	def test_person_can_have_only_one_bike(self):
		assert_equal(self.person.capacity, 1)

	def test_person_is_not_full(self):
		assert_equal(self.person.has_bike(), "doesn\'t have any bike")

	def test_person_has_a_bike(self):
		self.person.rides(self.bike)
		assert_equal(self.person.has_bike(), "has one bike")

	def test_person_cannot_have_two_bikes(self):
		self.person.rides(self.bike)
		self.person.rides(self.bike2)
		assert_equal(self.person.rides(self.bike2), "Cannot ride more than one bike")

	def test_person_falls_and_bike_is_broken(self):
		self.person.rides(self.bike)
		self.person.falls_from(self.bike)
		assert_true(self.bike.broken)

	def test_person_cannot_rent_if_station_has_no_bikes(self):
		assert_equal(self.person.rent_from(self.bike, self.station), "There are no bikes here")

	def test_person_can_rent_bike_from_station(self):
		self.station.dock(self.bike)
		self.person.rent_from(self.bike, self.station)
		assert_in(self.bike, self.person.bikes)
		assert_not_in(self.bike, self.station.bikes)

	def test_cannot_rent_a_broken_bike_from_the_station(self):
		self.bike.break_bike()
		self.station.dock(self.bike)
		assert_equal(self.person.rent_from(self.bike, self.station), "This bike is broken")

	def test_person_can_return_bike(self):
		self.station.dock(self.bike)
		self.person.rent_from(self.bike, self.station)
		self.person.return_to(self.bike, self.station)
		assert_in(self.bike, self.station.bikes)
Esempio n. 8
0
class TestStation(object):

	@classmethod
	def setup_class(klass):
		"""This method is run once for each class before any tests are run"""

	@classmethod
	def teardown_class(klass):
		"""This method is run once for each class _after_ all tests are run"""

	def setUp(self):
		"""This method is run once before _each_ test method is executed"""
		self.station = Station()
		self.bike = Bike()
		self.bike2 = Bike()
		self.bike3 = Bike()
		self.bike4 = Bike()
		self.bike5 = Bike()
		self.bike6 = Bike()

	def teardown(self):
		"""This method is run once after _each_ test method is executed"""
		pass

	def test_station_can_dock_maximum_five_bikes(self):
		assert_equal(self.station.capacity, 5)

	def test_station_is_not_full(self):
		self.station.dock(self.bike)
		self.station.dock(self.bike2)
		assert_equal(self.station.is_full(), "not full")

	def test_station_can_be_full(self):
		self.station.dock(self.bike)
		self.station.dock(self.bike2)
		self.station.dock(self.bike3)
		self.station.dock(self.bike4)
		self.station.dock(self.bike5)
		assert_equal(self.station.is_full(), "full")

	def test_station_cannot_dock_more_than_five_bikes(self):
		self.station.dock(self.bike)
		self.station.dock(self.bike2)
		self.station.dock(self.bike3)
		self.station.dock(self.bike4)
		self.station.dock(self.bike5)
		assert_equal(self.station.dock(self.bike6), "Cannot dock any more bikes")
Esempio n. 9
0
 def test_should_return_next_departure_time_depending_on_direction(self):
     station = Station(Faker().word, {'abc123': TimeTableStub(tuple())})
     self.assertGreater(
         Clock.get_hour_in_seconds(
             station.get_next_departure_time('abc123')), Clock.get_time())
Esempio n. 10
0
 def setUp(self) -> None:
     self.station = Station(Faker().word, {'d': TimeTableStub(tuple())})