コード例 #1
0
    def test_status(self):
        mock = FlagServiceMock()
        bs = BeerService('*****@*****.**', DataService(mock))

        self.assertEqual(1, bs.status())

        mock.data['*****@*****.**']['coffee|perday'] = 10
        mock.data['*****@*****.**']['coffee|remaining'] = 10
        self.assertEqual(5, bs.status())

        mock.data['*****@*****.**']['coffee|perday'] = 10
        mock.data['*****@*****.**']['coffee|remaining'] = None
        self.assertEqual(5, bs.status())

        mock.data['*****@*****.**']['coffee|perday'] = 10
        mock.data['*****@*****.**']['coffee|remaining'] = 5
        three_years_ago = (datetime.datetime.now() - datetime.timedelta(days=3 * 365)).strftime(DATETIME_FORMAT)
        mock.data['*****@*****.**']['coffee|last'] = three_years_ago
        self.assertEqual(5, bs.status())

        mock.data['*****@*****.**']['coffee|perday'] = 10
        mock.data['*****@*****.**']['coffee|remaining'] = 5
        one_day_ago = (datetime.datetime.now() - datetime.timedelta(days=1)).strftime(DATETIME_FORMAT)
        mock.data['*****@*****.**']['coffee|last'] = one_day_ago
        self.assertEqual(5, bs.status())

        mock.data['*****@*****.**']['coffee|perday'] = 10
        mock.data['*****@*****.**']['coffee|remaining'] = 5
        mock.data['*****@*****.**']['coffee|last'] = datetime.datetime.now().strftime(DATETIME_FORMAT)
        self.assertEqual(2, bs.status())

        mock.data['*****@*****.**']['coffee|perday'] = 10
        mock.data['*****@*****.**']['coffee|remaining'] = 2
        mock.data['*****@*****.**']['coffee|last'] = datetime.datetime.now().strftime(DATETIME_FORMAT)
        self.assertEqual(1, bs.status())

        mock.data['*****@*****.**']['coffee|perday'] = 10
        mock.data['*****@*****.**']['coffee|remaining'] = 1
        mock.data['*****@*****.**']['coffee|last'] = datetime.datetime.now().strftime(DATETIME_FORMAT)
        self.assertEqual(0, bs.status())

        mock.data['*****@*****.**']['coffee|perday'] = 1
        mock.data['*****@*****.**']['coffee|remaining'] = 1
        mock.data['*****@*****.**']['coffee|last'] = datetime.datetime.now().strftime(DATETIME_FORMAT)
        self.assertEqual(0, bs.status())

        mock.data['*****@*****.**']['coffee|perday'] = 1
        mock.data['*****@*****.**']['coffee|remaining'] = 0
        mock.data['*****@*****.**']['coffee|last'] = datetime.datetime.now().strftime(DATETIME_FORMAT)
        self.assertEqual(0, bs.status())

        mock.data['*****@*****.**']['coffee|perday'] = 10
        mock.data['*****@*****.**']['coffee|remaining'] = 0
        mock.data['*****@*****.**']['coffee|last'] = datetime.datetime.now().strftime(DATETIME_FORMAT)
        self.assertEqual(0, bs.status())
コード例 #2
0
    def test_dispense_mixed(self):
        mock = FlagServiceMock()
        bs = BeerService('*****@*****.**', DataService(mock))
        cs = CoffeeService('*****@*****.**', DataService(mock))

        self.assertEqual(1, bs.status())
        self.assertEqual(2, cs.status())
        bs.dispensed()
        self.assertEqual(0, bs.status())
        self.assertEqual(0, cs.status())

        mock.data['*****@*****.**']['coffee|remaining'] = 4
        self.assertEqual(2, bs.status())
        self.assertEqual(4, cs.status())
        cs.dispensed()
        self.assertEqual(3, mock.data['*****@*****.**']['coffee|remaining'])
        self.assertEqual(1, bs.status())
        self.assertEqual(3, cs.status())
        bs.dispensed()
        self.assertEqual(1, mock.data['*****@*****.**']['coffee|remaining'])
        self.assertEqual(0, bs.status())
        self.assertEqual(1, cs.status())
        cs.dispensed()
        self.assertEqual(0, mock.data['*****@*****.**']['coffee|remaining'])
        self.assertEqual(0, bs.status())
        self.assertEqual(0, cs.status())
コード例 #3
0
    def test_total_beers_when_dispensed(self):
        mock = FlagServiceMock()
        bs = BeerService('*****@*****.**', DataService(mock))

        self.assertEqual(1, bs.status())
        self.assertEqual(0, bs.total_beers())
        bs.dispensed()
        self.assertEqual(1, bs.total_beers())
        bs.dispensed()
        self.assertEqual(1, bs.total_beers())

        mock.data['*****@*****.**']['coffee|remaining'] = 4
        self.assertEqual(1, bs.total_beers())
        bs.dispensed()
        self.assertEqual(2, bs.total_beers())
        bs.dispensed()
        self.assertEqual(3, bs.total_beers())
        bs.dispensed()
        self.assertEqual(3, bs.total_beers())