コード例 #1
0
 def test_should_post_node_mapping_to_elasticsearch_when_no_sync_info_exists(
         self, mock_post, mock_put, *_):
     mock_post.return_value = FakeResponse({}, status_code=HTTP_200_OK)
     mock_put.return_value = FakeResponse({}, status_code=HTTP_200_OK)
     url = '%s/delivery_node/' % settings.ELASTIC_SEARCH.MAPPING
     list_nodes_to_update()
     mock_post.assert_called_with(url, json=DELIVERY_NODE_MAPPING)
コード例 #2
0
    def test_should_respond_with_json_data_and_status_code_passed(self):
        expected_json = {"key": "value"}
        expected_status_code = 1

        fake_response = FakeResponse(expected_json, expected_status_code)
        
        self.assertEqual(fake_response.json(), expected_json)
        self.assertEqual(fake_response.status_code, expected_status_code)
コード例 #3
0
ファイル: test_fake_response.py プロジェクト: z0x010/eums
    def test_should_respond_with_json_data_and_status_code_passed(self):
        expected_json = {"key": "value"}
        expected_status_code = 1

        fake_response = FakeResponse(expected_json, expected_status_code)

        self.assertEqual(fake_response.json(), expected_json)
        self.assertEqual(fake_response.status_code, expected_status_code)
コード例 #4
0
    def test_should_include_all_nodes_on_first_sync(self, mock_put, mock_post):
        mock_post.return_value = FakeResponse({}, status_code=HTTP_200_OK)
        mock_put.return_value = FakeResponse({}, status_code=HTTP_200_OK)
        self.assertEqual(SyncInfo.objects.count(), 0)
        node_one = DeliveryNodeFactory()
        node_two = DeliveryNodeFactory()

        nodes_to_sync = list_nodes_to_update()

        self.assertEqual(len(nodes_to_sync), 2)
        self.assertIn(node_one, nodes_to_sync)
        self.assertIn(node_two, nodes_to_sync)
コード例 #5
0
ファイル: test_runnable.py プロジェクト: yaroing/eums
    def test_should_build_contact_with_details_from_contacts_service(self, mock_get):
        contact_id = '54335c56b3ae9d92f038abb0'
        fake_contact_json = {'firstName': "test", 'lastName': "user1", 'phone': "+256 782 443439", '_id': contact_id}
        fake_response = FakeResponse(fake_contact_json, 200)
        node = NodeFactory(contact_person_id=contact_id)
        mock_get.return_value = fake_response

        contact = node.build_contact()

        self.assertEqual(contact, fake_contact_json)
        mock_get.assert_called_with("%s%s/" % (settings.CONTACTS_SERVICE_URL, contact_id))
コード例 #6
0
    def test_should_build_contact_with_details_from_contacts_service(self):
        contact_id = '54335c56b3ae9d92f038abb0'
        fake_contact_json = {
            'firstName': "test",
            'lastName': "user1",
            'phone': "+256 782 443439",
            '_id': contact_id
        }
        fake_response = FakeResponse(fake_contact_json, 200)
        consignee = ConsigneeFactory(contact_person_id=contact_id)
        when(requests).get("%s%s/" % (settings.CONTACTS_SERVICE_URL,
                                      contact_id)).thenReturn(fake_response)

        contact = consignee.build_contact()

        self.assertEqual(contact, fake_contact_json)
        self.assertEqual(consignee.contact, contact)
コード例 #7
0
    def test_should_not_fetch_contact_from_contacts_service_if_contact_was_already_built(
            self):
        contact_id = '54335c56b3ae9d92f038abb1'
        fake_contact_json = {
            'firstName': "test",
            'lastName': "user1",
            'phone': "+256 782 443439",
            '_id': contact_id
        }
        fake_response = FakeResponse(fake_contact_json, 200)
        consignee = ConsigneeFactory(contact_person_id=contact_id)
        when(requests).get("%s%s/" % (settings.CONTACTS_SERVICE_URL,
                                      contact_id)).thenReturn(fake_response)

        consignee.build_contact()
        consignee.build_contact()

        verify(requests, times=1).get(
            "%s%s/" % (settings.CONTACTS_SERVICE_URL, contact_id))
コード例 #8
0
ファイル: runs.py プロジェクト: z0x010/eums
def post(data=None):
    global last_run_id
    last_run_id += 1
    phone = data.get('phone', '+256 772 123456')
    response = FakeResponse([{"run": last_run_id, "phone": phone}], 201)
    return response