<commit_before>from tastypie.test import ResourceTestCase
from django.core.urlresolvers import reverse
import json
from hotsocket.models import Recharge


class TestRechargeResource(ResourceTestCase):

    def test_url_configured(self):
        """
        Testing the basic url is configured
        """
        url = reverse('api_dispatch_list',
                      kwargs={'resource_name': 'hotsocket/recharge',
                      'api_name': 'v1'})
        self.assertEqual(url, "/api/v1/hotsocket/recharge/")

    def test_post_url(self):
        url_recharge = reverse('api_dispatch_list',
                               kwargs={'resource_name': 'hotsocket/recharge',
                               'api_name': 'v1'})

        response = self.api_client.post(url_recharge,
                                         format="json",
                                         data={
                                         "denomination": 10,
                                         "product_code": "AIRTIME",
                                         "notes": "Grassroots Random Winner",
                                         "msisdn": 27821231231
                                         })

        msisdn_recharge = Recharge.objects.get(msisdn=27821231231)
        self.assertEqual(msisdn_recharge.product_code, "AIRTIME")
        self.assertEqual(msisdn_recharge.denomination, 10)
        self.assertEqual(msisdn_recharge.notes, "Grassroots Random Winner")
        self.assertEqual(msisdn_recharge.msisdn, 27821231231)<commit_msg>created unittests for multiple file uploads<commit_after>from tastypie.test import ResourceTestCase
from django.core.urlresolvers import reverse
import json
from hotsocket.models import Recharge


class TestRechargeResource(ResourceTestCase):

    def test_url_configured(self):
        """
        Testing the basic url is configured
        """
        url = reverse('api_dispatch_list',
                      kwargs={'resource_name': 'hotsocket/recharge',
                      'api_name': 'v1'})
        self.assertEqual(url, "/api/v1/hotsocket/recharge/")

    def test_single_post_url(self):
        url_recharge = reverse('api_dispatch_list',
                               kwargs={'resource_name': 'hotsocket/recharge',
                               'api_name': 'v1'})

        response = self.api_client.post(url_recharge,
                                         format="json",
                                         data={
                                         "denomination": 10,
                                         "product_code": "AIRTIME",
                                         "notes": "Grassroots Random Winner",
                                         "msisdn": 27821231231
                                         })

        msisdn_recharge = Recharge.objects.get(msisdn=27821231231)
        self.assertEqual(msisdn_recharge.product_code, "AIRTIME")
        self.assertEqual(msisdn_recharge.denomination, 10)
        self.assertEqual(msisdn_recharge.notes, "Grassroots Random Winner")
        self.assertEqual(msisdn_recharge.msisdn, 27821231231)


    def test_multiple_posts(self):
        url_recharge = reverse('api_dispatch_list',
                               kwargs={'resource_name': 'hotsocket/recharge',
                               'api_name': 'v1'})

        data = {
                    "objects": [
                        {
                            "denomination": 10,
                            "product_code": "AIRTIME",
                            "notes": "Grassroots Random Winner",
                            "msisdn": 27821231231
                        },
                        {
                            "denomination": 50,
                            "product_code": "AIRTIME",
                            "notes": "Grassroots Random Winner 2",
                            "msisdn": 27821231232
                        }
                    ]
                }

        response = self.api_client.patch(url_recharge,
                                         format="json",
                                         data=data)

        msisdn_recharge = Recharge.objects.get(msisdn=27821231231)
        self.assertEqual(msisdn_recharge.product_code, "AIRTIME")
        self.assertEqual(msisdn_recharge.denomination, 10)
        self.assertEqual(msisdn_recharge.notes, "Grassroots Random Winner")
        self.assertEqual(msisdn_recharge.msisdn, 27821231231)

        msisdn_recharge = Recharge.objects.get(msisdn=27821231232)
        self.assertEqual(msisdn_recharge.product_code, "AIRTIME")
        self.assertEqual(msisdn_recharge.denomination, 50)
        self.assertEqual(msisdn_recharge.notes, "Grassroots Random Winner 2")
        self.assertEqual(msisdn_recharge.msisdn, 27821231232)
{'fraction_non_alphanumeric': 0.08742714404662781, 'fraction_numerical': 0.03268109908409659, 'mean_word_length': 1.484488107549121, 'pattern_counts': {'":': 17, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5972940', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1197, 'n_words': 196}