Пример #1
0
    def test_changed_user_to_none(self):
        # GIVEN local opportunity with non-empty responsible user
        self.local_db['opportunity_111']['RESPONSIBLE_USER_ID'] = 111
        # WHEN RESPONSIBLE_USER_ID changed to None
        insightly_response_chain = [
            [dict(self.local_db['opportunity_111'], RESPONSIBLE_USER_ID=None)],
            [],  # No new notes
        ]
        patch('insightly_slack_notify.insightly_get',
              Mock(side_effect=insightly_response_chain)).start()

        # AND notify_changed_opportunities() is called
        insightly_slack_notify.notify_changed_opportunities()

        # THEN one slack message should be sent
        insightly_slack_notify.slack_post.assert_called_once_with(
            config.SLACK_CHANNEL_URL,
            json={
                'text':
                dedent('Opportunity op111 changed:\n'
                       'Responsible user changed\n'
                       'Url: https://googleapps.insight.ly'
                       '/opportunities/details/111\n'
                       'Responsible user: None')
            })

        # AND local db opportunity should get updated
        assert (self.local_db['opportunity_111']['RESPONSIBLE_USER_ID'] is
                None)
Пример #2
0
    def test_changed_pipeline(self):
        # WHEN PIPELINE_ID and STAGE_ID changed
        insightly_response_chain = [
            [dict(self.local_db['opportunity_111'], PIPELINE_ID=222, STAGE_ID=222)],
            [],  # No new notes
            {'PIPELINE_NAME': 'New pipe'},
            {'STAGE_NAME': 'New stage'}
        ]
        patch('insightly_slack_notify.insightly_get', Mock(side_effect=insightly_response_chain)).start()

        # AND notify_changed_opportunities() is called
        insightly_slack_notify.notify_changed_opportunities()

        # THEN one slack message should be sent
        insightly_slack_notify.slack_post.assert_called_once_with(
            config.SLACK_CHANNEL_URL,
            json={'text': dedent(
                'Opportunity op111 changed:\n'
                'Pipeline changed to New pipe (New stage)\n'
                'Url: https://googleapps.insight.ly/opportunities/details/111\n'
                'Responsible user: None')})

        # AND local db opportunity should get updated
        assert(self.local_db['opportunity_111']['PIPELINE_ID'] == 222)
        assert(self.local_db['opportunity_111']['STAGE_ID'] == 222)
Пример #3
0
    def test_changed_user(self):
        # WHEN RESPONSIBLE_USER_ID changed
        insightly_response_chain = [
            [dict(self.local_db['opportunity_111'], RESPONSIBLE_USER_ID=333)],
            [],  # No new notes
            {
                'FIRST_NAME': 'First',
                'LAST_NAME': 'Last',
                'EMAIL_ADDRESS': '*****@*****.**'
            },
        ]
        patch('insightly_slack_notify.insightly_get',
              Mock(side_effect=insightly_response_chain)).start()

        # AND notify_changed_opportunities() is called
        insightly_slack_notify.notify_changed_opportunities()

        # THEN one slack message should be sent
        insightly_slack_notify.slack_post.assert_called_once_with(
            config.SLACK_CHANNEL_URL,
            json={
                'text':
                dedent('Opportunity op111 changed:\n'
                       'Responsible user changed\n'
                       'Url: https://googleapps.insight.ly'
                       '/opportunities/details/111\n'
                       'Responsible user: First Last [email protected]')
            })

        # AND local db opportunity should get updated
        assert (self.local_db['opportunity_111']['RESPONSIBLE_USER_ID'] == 333)
Пример #4
0
    def test_changed_category_to_none(self):
        # WHEN CATEGORY_ID changed to None
        insightly_response_chain = [
            [dict(self.local_db['opportunity_111'], CATEGORY_ID=None)],
            [],  # No new notes
            {
                'CATEGORY_NAME': 'Old category'
            },
        ]
        patch('insightly_slack_notify.insightly_get',
              Mock(side_effect=insightly_response_chain)).start()

        # AND notify_changed_opportunities() is called
        insightly_slack_notify.notify_changed_opportunities()

        # THEN one slack message should be sent
        insightly_slack_notify.slack_post.assert_called_once_with(
            config.SLACK_CHANNEL_URL,
            json={
                'text':
                dedent('Opportunity op111 changed:\n'
                       'Category changed from Old category to None\n'
                       'Url: https://googleapps.insight.ly'
                       '/opportunities/details/111\n'
                       'Responsible user: None')
            })

        # AND local db opportunity should get updated
        assert (self.local_db['opportunity_111']['CATEGORY_ID'] is None)
Пример #5
0
    def test_changed_bid_amount(self):
        # WHEN BID_AMOUNT changed
        insightly_response_chain = [
            [dict(self.local_db['opportunity_111'], BID_AMOUNT=2)],
            [],  # No new notes
        ]
        patch('insightly_slack_notify.insightly_get',
              Mock(side_effect=insightly_response_chain)).start()

        # AND notify_changed_opportunities() is called
        insightly_slack_notify.notify_changed_opportunities()

        # THEN one slack message should be sent
        insightly_slack_notify.slack_post.assert_called_once_with(
            config.SLACK_CHANNEL_URL,
            json={
                'text':
                dedent('Opportunity op111 changed:\n'
                       'Bid amount changed from 1 to 2\n'
                       'Url: https://googleapps.insight.ly'
                       '/opportunities/details/111\n'
                       'Responsible user: None')
            })

        # AND local db opportunity should get updated
        assert (self.local_db['opportunity_111']['BID_AMOUNT'] == 2)
Пример #6
0
    def test_changed_pipeline(self):
        # WHEN PIPELINE_ID and STAGE_ID changed
        insightly_response_chain = [
            [
                dict(self.local_db['opportunity_111'],
                     PIPELINE_ID=222,
                     STAGE_ID=222)
            ],
            [],  # No new notes
            {
                'PIPELINE_NAME': 'Old pipe'
            },
            {
                'STAGE_NAME': 'Old stage'
            },
            {
                'PIPELINE_NAME': 'New pipe'
            },
            {
                'STAGE_NAME': 'New stage'
            }
        ]
        patch('insightly_slack_notify.insightly_get',
              Mock(side_effect=insightly_response_chain)).start()

        # AND notify_changed_opportunities() is called
        insightly_slack_notify.notify_changed_opportunities()

        # THEN one slack message should be sent
        insightly_slack_notify.slack_post.assert_called_once_with(
            config.SLACK_CHANNEL_URL,
            json={
                'text':
                dedent('Opportunity op111 changed:\n'
                       'Pipeline changed from Old pipe (Old stage) '
                       'to New pipe (New stage)\n'
                       'Url: https://googleapps.insight.ly'
                       '/opportunities/details/111\n'
                       'Responsible user: None')
            })

        # AND local db opportunity should get updated
        assert (self.local_db['opportunity_111']['PIPELINE_ID'] == 222)
        assert (self.local_db['opportunity_111']['STAGE_ID'] == 222)
Пример #7
0
    def test_added_note(self):
        # WHEN new note was added on the server.
        insightly_response_chain = [
            [self.local_db['opportunity_111']],  # opportunity not changed
            [NOTE_TEMPLATE],
        ]
        patch('insightly_slack_notify.insightly_get', Mock(side_effect=insightly_response_chain)).start()

        # AND notify_changed_opportunities() is called
        insightly_slack_notify.notify_changed_opportunities()

        # THEN one slack message should be sent
        insightly_slack_notify.slack_post.assert_called_once_with(
            config.SLACK_CHANNEL_URL,
            json={'text': dedent(
                'Opportunity op111 changed:\n'
                'New note added: lol2\n'
                'Url: https://googleapps.insight.ly/opportunities/details/111\n'
                'Responsible user: None')})
Пример #8
0
    def test_changed_bid_amount(self):
        # WHEN BID_AMOUNT changed
        insightly_response_chain = [
            [dict(self.local_db['opportunity_111'], BID_AMOUNT=2)],
            [],  # No new notes
        ]
        patch('insightly_slack_notify.insightly_get', Mock(side_effect=insightly_response_chain)).start()

        # AND notify_changed_opportunities() is called
        insightly_slack_notify.notify_changed_opportunities()

        # THEN one slack message should be sent
        insightly_slack_notify.slack_post.assert_called_once_with(
            config.SLACK_CHANNEL_URL,
            json={'text': dedent(
                'Opportunity op111 changed:\n'
                'Bid amount changed to 2\n'
                'Url: https://googleapps.insight.ly/opportunities/details/111\n'
                'Responsible user: None')})

        # AND local db opportunity should get updated
        assert(self.local_db['opportunity_111']['BID_AMOUNT'] == 2)
Пример #9
0
    def test_changed_category_to_none(self):
        # WHEN CATEGORY_ID changed to None
        insightly_response_chain = [
            [dict(self.local_db['opportunity_111'], CATEGORY_ID=None)],
            [],  # No new notes
        ]
        patch('insightly_slack_notify.insightly_get', Mock(side_effect=insightly_response_chain)).start()

        # AND notify_changed_opportunities() is called
        insightly_slack_notify.notify_changed_opportunities()

        # THEN one slack message should be sent
        insightly_slack_notify.slack_post.assert_called_once_with(
            config.SLACK_CHANNEL_URL,
            json={'text': dedent(
                'Opportunity op111 changed:\n'
                'Category changed to None\n'
                'Url: https://googleapps.insight.ly/opportunities/details/111\n'
                'Responsible user: None')})

        # AND local db opportunity should get updated
        assert(self.local_db['opportunity_111']['CATEGORY_ID'] is None)
Пример #10
0
    def test_changed_user(self):
        # WHEN RESPONSIBLE_USER_ID changed
        insightly_response_chain = [
            [dict(self.local_db['opportunity_111'], RESPONSIBLE_USER_ID=333)],
            [],  # No new notes
            {'FIRST_NAME': 'First', 'LAST_NAME': 'Last', 'EMAIL_ADDRESS': '*****@*****.**'},
        ]
        patch('insightly_slack_notify.insightly_get', Mock(side_effect=insightly_response_chain)).start()

        # AND notify_changed_opportunities() is called
        insightly_slack_notify.notify_changed_opportunities()

        # THEN one slack message should be sent
        insightly_slack_notify.slack_post.assert_called_once_with(
            config.SLACK_CHANNEL_URL,
            json={'text': dedent(
                'Opportunity op111 changed:\n'
                'Responsible user changed\n'
                'Url: https://googleapps.insight.ly/opportunities/details/111\n'
                'Responsible user: First Last [email protected]')})

        # AND local db opportunity should get updated
        assert(self.local_db['opportunity_111']['RESPONSIBLE_USER_ID'] == 333)
Пример #11
0
    def test_added_note(self):
        # WHEN new note was added on the server.
        insightly_response_chain = [
            [self.local_db['opportunity_111']],  # opportunity not changed
            [NOTE_TEMPLATE],
        ]
        patch('insightly_slack_notify.insightly_get',
              Mock(side_effect=insightly_response_chain)).start()

        # AND notify_changed_opportunities() is called
        insightly_slack_notify.notify_changed_opportunities()

        # THEN one slack message should be sent
        insightly_slack_notify.slack_post.assert_called_once_with(
            config.SLACK_CHANNEL_URL,
            json={
                'text':
                dedent('Opportunity op111 changed:\n'
                       'New note added: lol2\n'
                       'Text: body\n'
                       'Url: https://googleapps.insight.ly'
                       '/opportunities/details/111\n'
                       'Responsible user: None')
            })