Ejemplo n.º 1
0
    def test_claim_pot_unclaimed(self):
        maker = PotMaker.create(name='bob',
                                number_of_pots_made=1,
                                total_weight_made=12,
                                number_of_cups_made=5,
                                largest_single_pot=2)
        State.create(state="FULL_TEAPOT",
                     timestamp=datetime(2016, 1, 1, 12, 0, 0),
                     num_of_cups=5,
                     weight=10)
        State.create(state="FULL_TEAPOT",
                     timestamp=datetime(2017, 1, 1, 12, 0, 0),
                     num_of_cups=2,
                     weight=5)
        result = self.app.post('/claimPot',
                               data=json.dumps({
                                   'potMaker': 'bob',
                               }))
        self.assertEqual(result.status_code, 200)
        data = json.loads(result.data)
        self.assertEqual(data['submitMessage'], 'Pot claimed, thanks, bob')

        updated_pot_maker = PotMaker.get_single_pot_maker('bob')
        self.assertEqual(updated_pot_maker.number_of_pots_made, 2)
        self.assertEqual(updated_pot_maker.total_weight_made, 17)
        self.assertEqual(updated_pot_maker.number_of_cups_made, 7)
        self.assertEqual(updated_pot_maker.largest_single_pot, 5)

        updated_state = State.get_latest_full_teapot()
        self.assertEqual(updated_state.claimed_by, maker)
Ejemplo n.º 2
0
    def test_tea_ready_claimed(self, mock_slack):
        maker = PotMaker.create(
            name='bob',
            number_of_pots_made=1,
            total_weight_made=12,
            number_of_cups_made=5,
            largest_single_pot=2
        )
        State.create(
            state="FULL_TEAPOT",
            timestamp=datetime.now().isoformat(),
            num_of_cups=3,
            claimed_by=maker
        )
        result = self.app.post("/teaReady")
        self.assertEqual(result.status_code, 200)
        mock_slack.post_message_to_room.assert_any_call(
            "The Teapot :teapot: is ready with 3 cups, thanks to bob"
        )
        reaction_message = \
            "Want a cup of tea from the next teapot ? " + \
            "React to this message to let everyone know!"
        mock_slack.post_message_to_room.assert_any_call(
            reaction_message, True)

        self.assertEqual(mock_slack.post_message_to_room.call_count, 2)
Ejemplo n.º 3
0
 def test_teapot_age(self, mock_time):
     mock_time.return_value = datetime(2016, 1, 1, 12, 5, 0)
     State.create(state="FULL_TEAPOT",
                  timestamp=datetime(2016, 1, 1, 12, 0, 0),
                  num_of_cups=2)
     result = self.app.get("/teapotAge", )
     self.assertEqual(result.status_code, 200)
     data = json.loads(result.data)
     self.assertEqual(data["teapotAge"], 5)
Ejemplo n.º 4
0
 def test_claim_pot_no_pot_maker(self):
     State.create(state="FULL_TEAPOT",
                  timestamp=datetime(2016, 1, 1, 12, 0, 0),
                  num_of_cups=2,
                  claimed_by=None)
     result = self.app.post('/claimPot', data=json.dumps({}))
     self.assertEqual(result.status_code, 200)
     data = json.loads(result.data)
     self.assertEqual(data['submitMessage'],
                      'You need to select a pot maker')
Ejemplo n.º 5
0
 def test_tea_webhook_data(self):
     State.create(state="TEAPOT FULL",
                  timestamp=datetime.now().isoformat(),
                  num_of_cups=3)
     State.create(state="TEAPOT EMPTY",
                  timestamp=datetime.now() - timedelta(weeks=1),
                  num_of_cups=2)
     result = self.app.post("/teabotWebhook")
     self.assertEqual(result.status_code, 200)
     data = json.loads(result.data)
     self.assertEqual(data["text"], "There are 3 cups left")
Ejemplo n.º 6
0
 def test_claim_pot_no_pot_maker(self):
     State.create(
         state="FULL_TEAPOT",
         timestamp=datetime(2016, 1, 1, 12, 0, 0),
         num_of_cups=2,
         claimed_by=None
     )
     result = self.app.post('/claimPot', data=json.dumps({}))
     self.assertEqual(result.status_code, 200)
     data = json.loads(result.data)
     self.assertEqual(
         data['submitMessage'], 'You need to select a pot maker')
Ejemplo n.º 7
0
 def test_teapot_age(self, mock_time):
     mock_time.return_value = datetime(2016, 1, 1, 12, 5, 0)
     State.create(
         state="FULL_TEAPOT",
         timestamp=datetime(2016, 1, 1, 12, 0, 0),
         num_of_cups=2
     )
     result = self.app.get(
         "/teapotAge",
     )
     self.assertEqual(result.status_code, 200)
     data = json.loads(result.data)
     self.assertEqual(data["teapotAge"], 5)
Ejemplo n.º 8
0
 def test_get_latest_state(self):
     State.create(
         state="TEAPOT_FULL",
         timestamp=datetime.now().isoformat(),
         num_of_cups=3
     )
     State.create(
         state="TEAPOT_EMPTY",
         timestamp=datetime.now() - timedelta(weeks=1),
         num_of_cups=0
     )
     result = State.get_newest_state()
     self.assertEqual(result.state, "TEAPOT_FULL")
     self.assertEqual(result.num_of_cups, 3)
Ejemplo n.º 9
0
    def test_tea_ready_no_claim(self, mock_slack):
        State.create(state="FULL_TEAPOT",
                     timestamp=datetime.now().isoformat(),
                     num_of_cups=3)
        result = self.app.post("/teaReady")
        self.assertEqual(result.status_code, 200)
        mock_slack.post_message_to_room.assert_any_call(
            "The Teapot :teapot: is ready with 3 cups")
        reaction_message = \
            "Want a cup of tea from the next teapot ? " + \
            "React to this message to let everyone know!"
        mock_slack.post_message_to_room.assert_any_call(reaction_message, True)

        self.assertEqual(mock_slack.post_message_to_room.call_count, 2)
Ejemplo n.º 10
0
 def test_claim_pot_already_claimed(self):
     maker = PotMaker.create(name='bob',
                             number_of_pots_made=1,
                             total_weight_made=12,
                             number_of_cups_made=5,
                             largest_single_pot=2)
     State.create(state="FULL_TEAPOT",
                  timestamp=datetime(2016, 1, 1, 12, 0, 0),
                  num_of_cups=2,
                  claimed_by=maker)
     result = self.app.post('/claimPot')
     self.assertEqual(result.status_code, 200)
     data = json.loads(result.data)
     self.assertEqual(data['submitMessage'], 'Pot has already been claimed')
Ejemplo n.º 11
0
 def test_tea_webhook_data(self):
     State.create(
         state="TEAPOT FULL",
         timestamp=datetime.now().isoformat(),
         num_of_cups=3
     )
     State.create(
         state="TEAPOT EMPTY",
         timestamp=datetime.now() - timedelta(weeks=1),
         num_of_cups=2
     )
     result = self.app.post("/teabotWebhook")
     self.assertEqual(result.status_code, 200)
     data = json.loads(result.data)
     self.assertEqual(data["text"], "There are 3 cups left")
Ejemplo n.º 12
0
 def test_human_teapot_state_cold_tea_one_cup(self):
     state = State.create(
         state="COLD_TEAPOT",
         timestamp=datetime.now().isoformat(),
         num_of_cups=1
     )
     result = _human_teapot_state(state)
     self.assertEqual(result, "There is 1 cup left but the teas cold :(")
Ejemplo n.º 13
0
 def test_human_teapot_state_good_tea_many_cups(self):
     state = State.create(
         state="TEAPOT_FULL",
         timestamp=datetime.now().isoformat(),
         num_of_cups=2
     )
     result = _human_teapot_state(state)
     self.assertEqual(result, "There are 2 cups left")
Ejemplo n.º 14
0
    def test_tea_ready_no_claim(self, mock_slack):
        State.create(
            state="FULL_TEAPOT",
            timestamp=datetime.now().isoformat(),
            num_of_cups=3
        )
        result = self.app.post("/teaReady")
        self.assertEqual(result.status_code, 200)
        mock_slack.post_message_to_room.assert_any_call(
            "The Teapot :teapot: is ready with 3 cups"
        )
        reaction_message = \
            "Want a cup of tea from the next teapot ? " + \
            "React to this message to let everyone know!"
        mock_slack.post_message_to_room.assert_any_call(
            reaction_message, True)

        self.assertEqual(mock_slack.post_message_to_room.call_count, 2)
Ejemplo n.º 15
0
 def test_claim_pot_already_claimed(self):
     maker = PotMaker.create(
         name='bob',
         number_of_pots_made=1,
         total_weight_made=12,
         number_of_cups_made=5,
         largest_single_pot=2
     )
     State.create(
         state="FULL_TEAPOT",
         timestamp=datetime(2016, 1, 1, 12, 0, 0),
         num_of_cups=2,
         claimed_by=maker
     )
     result = self.app.post('/claimPot')
     self.assertEqual(result.status_code, 200)
     data = json.loads(result.data)
     self.assertEqual(data['submitMessage'], 'Pot has already been claimed')
Ejemplo n.º 16
0
    def test_tea_ready_claimed(self, mock_slack):
        maker = PotMaker.create(name='bob',
                                number_of_pots_made=1,
                                total_weight_made=12,
                                number_of_cups_made=5,
                                largest_single_pot=2)
        State.create(state="FULL_TEAPOT",
                     timestamp=datetime.now().isoformat(),
                     num_of_cups=3,
                     claimed_by=maker)
        result = self.app.post("/teaReady")
        self.assertEqual(result.status_code, 200)
        mock_slack.post_message_to_room.assert_any_call(
            "The Teapot :teapot: is ready with 3 cups, thanks to bob")
        reaction_message = \
            "Want a cup of tea from the next teapot ? " + \
            "React to this message to let everyone know!"
        mock_slack.post_message_to_room.assert_any_call(reaction_message, True)

        self.assertEqual(mock_slack.post_message_to_room.call_count, 2)
Ejemplo n.º 17
0
    def test_claim_pot_unclaimed(self):
        maker = PotMaker.create(
            name='bob',
            number_of_pots_made=1,
            total_weight_made=12,
            number_of_cups_made=5,
            largest_single_pot=2
        )
        State.create(
            state="FULL_TEAPOT",
            timestamp=datetime(2016, 1, 1, 12, 0, 0),
            num_of_cups=5,
            weight=10
        )
        State.create(
            state="FULL_TEAPOT",
            timestamp=datetime(2017, 1, 1, 12, 0, 0),
            num_of_cups=2,
            weight=5
        )
        result = self.app.post(
            '/claimPot',
            data=json.dumps({
                'potMaker': 'bob',
            })
        )
        self.assertEqual(result.status_code, 200)
        data = json.loads(result.data)
        self.assertEqual(data['submitMessage'], 'Pot claimed, thanks, bob')

        updated_pot_maker = PotMaker.get_single_pot_maker(
            'bob'
        )
        self.assertEqual(updated_pot_maker.number_of_pots_made, 2)
        self.assertEqual(updated_pot_maker.total_weight_made, 17)
        self.assertEqual(updated_pot_maker.number_of_cups_made, 7)
        self.assertEqual(updated_pot_maker.largest_single_pot, 5)

        updated_state = State.get_latest_full_teapot()
        self.assertEqual(updated_state.claimed_by, maker)
Ejemplo n.º 18
0
 def test_latest_full_teapot(self):
     State.create(
         state="FULL_TEAPOT",
         timestamp=datetime(2015, 1, 1).isoformat(),
         num_of_cups=3
     )
     State.create(
         state="FULL_TEAPOT",
         timestamp=datetime(2016, 1, 1).isoformat(),
         num_of_cups=4
     )
     State.create(
         state="FULL_TEAPOT",
         timestamp=datetime(2017, 1, 1).isoformat(),
         num_of_cups=5
     )
     result = State.get_latest_full_teapot()
     self.assertEqual(result.num_of_cups, 5)
Ejemplo n.º 19
0
 def test_get_number_of_new_teapots(self):
     State.create(
         state="FULL_TEAPOT",
         timestamp=datetime.now().isoformat(),
         num_of_cups=3
     )
     State.create(
         state="FULL_TEAPOT",
         timestamp=datetime.now() - timedelta(weeks=1),
         num_of_cups=0
     )
     State.create(
         state="EMPTY_TEAPOT",
         timestamp=datetime.now() - timedelta(weeks=1),
         num_of_cups=0
     )
     result = State.get_number_of_new_teapots()
     self.assertEqual(result, 2)
Ejemplo n.º 20
0
 def test_human_teapot_state_good_tea_many_cups(self):
     state = State.create(state="TEAPOT_FULL",
                          timestamp=datetime.now().isoformat(),
                          num_of_cups=2)
     result = _human_teapot_state(state)
     self.assertEqual(result, "There are 2 cups left")
Ejemplo n.º 21
0
 def test_human_teapot_state_cold_tea_one_cup(self):
     state = State.create(state="COLD_TEAPOT",
                          timestamp=datetime.now().isoformat(),
                          num_of_cups=1)
     result = _human_teapot_state(state)
     self.assertEqual(result, "There is 1 cup left but the teas cold :(")