def test_rss_remote_error(self):
        # Create Mocks
        self._response.status_code = 500

        cdr = {
            'provider': 'test_provider',
            'correlation': '2',
            'order': '1234567890',
            'offering': 'test_offering',
            'product_class': 'SaaS',
            'description': 'The description',
            'cost_currency': 'EUR',
            'cost_value': '10',
            'tax_value': '0.0',
            'time_stamp': '10-05-13T10:00:00Z',
            'customer': 'test_customer',
            'event': 'One time',
            'type': 'C'
        }
        cdrs = [cdr, cdr]

        rss_ad = rss_adaptor.RSSAdaptor()
        rss_ad.send_cdr(cdrs)

        # Decrement correlation number for every cdr
        calls = call(query={'_id': ObjectId(b"111111111111")}, update={'$inc': {'correlation_number': -1}})
        rss_adaptor.get_database_connection().wstore_organization.find_and_modify.assert_has_calls([calls, calls], any_order=True)
        # Save the failed cdrs
        rss_adaptor.Context.objects.all.assert_called_once_with()
        rss_adaptor.Context.objects.all()[0].failed_cdrs.extend.assert_called_once_with(cdrs)
        rss_adaptor.Context.objects.all()[0].save.assert_called_once_with()
    def test_rss_client(self):
        # Create mocks
        self._response.status_code = 201

        rss_ad = rss_adaptor.RSSAdaptor()

        rss_ad.send_cdr([{
            'provider': 'test_provider',
            'correlation': '2',
            'order': '1234567890',
            'offering': 'test_offering',
            'product_class': 'SaaS',
            'description': 'The description',
            'cost_currency': 'EUR',
            'cost_value': '10',
            'tax_value': '0.0',
            'time_stamp': '10-05-13T10:00:00Z',
            'customer': 'test_customer',
            'event': 'One time',
            'type': 'C'
        }])

        rss_adaptor.requests.post.assert_called_once_with(
            'http://testhost.com/rssHost/rss/cdrs',
            json=[{
                'cdrSource': '*****@*****.**',
                'productClass': 'SaaS',
                'correlationNumber': '2',
                'timestamp': '10-05-13T10:00:00Z',
                'application': 'test_offering',
                'transactionType': 'C',
                'event': 'One time',
                'referenceCode': '1234567890',
                'description': 'The description',
                'chargedAmount': '10',
                'chargedTaxAmount': '0.0',
                'currency': 'EUR',
                'customerId': 'test_customer',
                'appProvider': 'test_provider'
            }],
            headers={
                'content-type': 'application/json',
                'X-Nick-Name': 'wstore',
                'X-Roles': 'admin',
                'X-Email': '*****@*****.**'
            })

        rss_adaptor.get_database_connection.assert_not_called()
        rss_adaptor.Context.objects.all.assert_not_called()