Exemplo n.º 1
0
Arquivo: tests.py Projeto: Feowl/API
    def test_register(self):
        contributors = Contributor.objects.all()
        nb_contributors = len(contributors)

        receive_sms(self.register_test_user_no, self.register_keyword)
        contributors = Contributor.objects.all()
        self.assertEqual(len(contributors), nb_contributors + 1)

        device = Device.objects.get(phone_number=self.register_test_user_no)
        contributor = Contributor.objects.get(name=self.register_test_user_no)
        self.assertEqual(contributor.refunds, 1)
        self.assertEqual(device.phone_number, self.register_test_user_no)
Exemplo n.º 2
0
    def test_help(self):
        devices = Device.objects.all()
        contributors = Contributor.objects.all()
        nb_devices = len(devices)
        nb_contributors = len(contributors)

        contributor = Contributor(name=self.unregister_test_user_name, email=self.unregister_test_user_email, password=self.unregister_test_user_password)
        contributor.save()
        device = Device(phone_number=self.help_no, contributor=contributor)
        device.save()
                            
        receive_sms(self.help_no, "help")
        devices = Device.objects.all()
        contributors = Contributor.objects.all()
        self.assertEqual(len(devices), nb_devices + 1)
        self.assertEqual(len(contributors), nb_contributors + 1)
Exemplo n.º 3
0
    def test_invalid(self):
        devices = Device.objects.all()
        nb_devices = len(devices)
        contributors = Contributor.objects.all()
        nb_contributors = len(contributors)

        #English SMS
        receive_sms("889383849", "lkjasdlkajs akjkdlaksjdui akjdlkasd")
        devices = Device.objects.all()
        contributors = Contributor.objects.all()
        self.assertEqual(len(devices), nb_devices + 1)
        self.assertEqual(len(contributors), nb_contributors + 1)

        #French SMS
        nb_messages = len(Message.objects.all())
        receive_sms("789383849", "ça a marché")
        messages = Message.objects.all()
        self.assertEqual(len(messages), nb_messages + 1)
Exemplo n.º 4
0
    def test_unregister(self):
        devices = Device.objects.all()
        nb_devices = len(devices)
        contributors = Contributor.objects.all()
        nb_contributors = len(contributors)

        #Registering a User
        receive_sms(self.unregister_test_user_no, "register")
        devices = Device.objects.all()
        contributors = Contributor.objects.all()
        self.assertEqual(len(devices), nb_devices + 1)
        self.assertEqual(len(contributors), nb_contributors + 1)
        #Unregistering a user
        receive_sms(self.unregister_test_user_no, self.unregister_keyword)

        devices = Device.objects.all()
        contributors = Contributor.objects.all()
        self.assertEqual(len(devices), nb_devices)
        self.assertEqual(len(contributors), nb_contributors)
Exemplo n.º 5
0
Arquivo: tests.py Projeto: Feowl/API
    def contibute_message(self, msg):
        no = "415738710432"
        receive_sms(no, "register")
        contributor = Contributor.objects.get(name=no)
        contributor.enquiry = datetime.today().date()
        contributor.save()
        total_reports = PowerReport.objects.all().count()

        receive_sms(no, msg)
        new_total_reports = PowerReport.objects.all().count()
        self.assertEqual(new_total_reports, total_reports)

        sms = Message.objects.latest("created")
        if sms.parsed == 2:
            parsed = "NO"
        elif sms.parsed == 0:
            parsed = "YES"
        else:
            parsed = "Maybe"
        print "--{0}-- Parsed = {1}".format(msg, parsed)
        return
Exemplo n.º 6
0
    def test_zcontribute(self):
        #contribute_msg = (self.contribute_keyword + " " +
                #self.contribute_area + " " + self.contribute_duration)
        contribute_msg = "pc douala2 100"

        # Missing enquiry - Contribution not accepted
        receive_sms(self.register_test_user_no, self.register_keyword)
        reports = PowerReport.objects.all()
        nb_reports = reports.count()
        receive_sms(self.register_test_user_no, contribute_msg)
        reports = PowerReport.objects.all()
        self.assertEqual(len(reports), nb_reports)

        # With enquiry from today - Contribution accepted
        contributor = Contributor.objects.get(name=self.register_test_user_no)
        contributor.enquiry = datetime.today().date()
        contributor.save()
        
        old_refund = contributor.refunds

        receive_sms(self.register_test_user_no, contribute_msg)
        reports = PowerReport.objects.all()
        self.assertEqual(len(reports), nb_reports + 1)
        contributor = Contributor.objects.get(name=self.register_test_user_no)
        new_refund = contributor.refunds
        self.assertEqual(new_refund, old_refund + 1)
        
        report = reports.latest("happened_at")
        self.assertEqual(report.has_experienced_outage, True)

        # Reset the response time in the db
        contributor.response = datetime.today().date() - timedelta(days=1)
        contributor.save()

        # Test the wrong message
        reports = PowerReport.objects.all()
        nb_reports = reports.count()
        receive_sms(self.register_test_user_no, "pc doulan malskd oskjajhads33 d akjs")
        reports = PowerReport.objects.all()
        self.assertEqual(len(reports), nb_reports)
        
        # Reset the response time in the db
        contributor.response = datetime.today().date() - timedelta(days=1)
        contributor.save()
        
        # Multiple message
        multi_contribute_msg = "pc doualaI 29, douala2 400, douala3 10, alger 403"
        reports = PowerReport.objects.all()
        nb_reports = len(reports)
        contributor = Contributor.objects.get(name=self.register_test_user_no)
        refund = contributor.refunds
        receive_sms(self.register_test_user_no, multi_contribute_msg)
        reports = PowerReport.objects.all()
        
        self.assertEqual(len(reports), nb_reports + 4)
        logger.info('Multiple Messages has been contributed')

        contributor = Contributor.objects.get(name=self.register_test_user_no)
        self.assertEqual(contributor.refunds, refund + 4)
        contributor.response = datetime.today().date() - timedelta(days=1)
        contributor.save()

        # Test the no method if the reports wrong
        nb_reports1 = PowerReport.objects.all().count()
        receive_sms(self.register_test_user_no, "pc no")
        nb_reports2 = PowerReport.objects.all().count()
        self.assertEqual(nb_reports2, nb_reports1 + 1)
        report = reports.latest("happened_at")
        self.assertEqual(report.has_experienced_outage, False)

        # Reset the response time in the db
        contributor.response = datetime.today().date() - timedelta(days=1)
        contributor.save()
        
        # Multiple message
        multi_contribute_msg = "pc douala1 29, akwa 400, Bilongue 10, BONAMOUSSADI 403"
        reports = PowerReport.objects.all()
        nb_reports = len(reports)
        contributor = Contributor.objects.get(name=self.register_test_user_no)
        refund = contributor.refunds
        receive_sms(self.register_test_user_no, multi_contribute_msg)
        reports = PowerReport.objects.all()
        
        self.assertEqual(len(reports), nb_reports + 4)
        logger.info('Multiple Messages has been contributed')