Пример #1
0
 def test1_create_contact(self):
     """
     Gets the contact and checks that its name is the one we set in setUp
     """
     create_contact(name='Contact 1', phone='12345678')
     contact = Contact.objects.all().last()
     self.assertTrue(isinstance(contact,
                                Contact))  # Check if it is a contact
     self.assertEqual(contact.name,
                      'Contact 1')  # Check if its name is Contact 1
Пример #2
0
    def test5_contact_campaign_methods(self):
        """
        Creates a contact and checks if it has been added to the campaign.
        """
        contact = create_contact(name='Contact 5', phone='12412455')
        campaign = create_campaign(name='Campaign')

        # Check if they were created correctly
        self.assertTrue(isinstance(contact, Contact))
        self.assertTrue(isinstance(campaign, Campaign))

        response = contact.add_to_campaign(campaign.id)

        # This command returns a text, we have to see if the text has been correctly returned
        self.assertEqual(
            response,
            _("Contact %s (ID: %s) added to campaign") %
            (contact.name, contact.id))

        # We have to check if a ContactCampaignStatus with campaign.id and contact.id exists
        self.assertTrue(
            ContactCampaignStatus.objects.filter(contact=contact,
                                                 campaign=campaign).exists())

        # Then we have to see that it's only one. This would fail otherwise. Then we have to see that the status is
        # the default one
        ccs = ContactCampaignStatus.objects.get(contact=contact,
                                                campaign=campaign)
        self.assertEqual(
            ccs.status,
            1)  # Default is always 1, which means not contacted yet

        # We need to try to add the contact again, that should raise a normal exception
        with self.assertRaises(Exception):
            contact.add_to_campaign(campaign.id)
Пример #3
0
    def test4_contact_debtor_methods(self):
        """
        Checks if the is_debtor method works
        """
        contact = create_contact(name='Contact 4', phone='12312321')
        product = create_product('newspaper', 500)
        invoice = create_simple_invoice(contact, 'R', product)
        invoice.creation_date = invoice.creation_date - timedelta(30)
        invoice.expiration_date = invoice.expiration_date - timedelta(
            30)  # This will be a forced expired invoice
        invoice.save()

        # Just to check if every objects is correctly created
        self.assertTrue(isinstance(contact, Contact))
        self.assertTrue(isinstance(product, Product))
        self.assertTrue(isinstance(invoice, Invoice))

        # First we check if the contact is debtor
        self.assertTrue(contact.is_debtor())

        # That function depends on this one.
        self.assertEqual(contact.expired_invoices_count(), 1)

        # Get expired invoices should return a queryset with the one that we created before
        expired_invoices = contact.get_expired_invoices()
        self.assertIn(invoice, expired_invoices)

        # The debt should be exactly the amount of the invoice (for now it is the amount of the product's price)
        self.assertEqual(contact.get_debt(), product.price)
Пример #4
0
 def test3_contact_unicode_method(self):
     """
     Check the unicode method. This test uses a contact that will only be used in this one.
     """
     contact = create_contact(name='Contact 3', phone='12345567')
     self.assertTrue(isinstance(contact, Contact))
     self.assertEqual(contact.name, contact.__unicode__())
Пример #5
0
    def test6_others(self):
        subtype = create_subtype(name='Subtype 1')
        count = subtype.get_contact_count()
        self.assertEqual(count, 0)

        product = create_product('news', 500)
        # test for default
        self.assertEqual(product.get_type(), _("Subscription"))
        product.type = 'N'
        self.assertEqual(product.get_type(), _("Newsletter"))
        self.assertEqual(product.get_weekday(), 'N/A')

        basic_print = str(product)
        self.assertEqual(basic_print, 'news, newsletter')

        # very simple, no expired
        contact = create_contact(name='Contact 6', phone='12412455')
        subs_expired = contact.get_subscriptions_with_expired_invoices()
        assert not subs_expired

        gender = contact.get_gender()
        self.assertEqual(gender, 'N/A')

        newsletters = contact.get_newsletters()
        assert not newsletters
Пример #6
0
 def setUp(self):
     contact = create_contact(name="la diaria", phone="29000808")
     subscription = create_subscription(contact)
     subscription.active = False
     subscription.start_date = date.today()
     subscription.status = "OK"
     subscription.save()
     address = create_address('Fake Street 123', contact)
     product1 = create_product(name="newspaper", price=350)
     subscription.add_product(product1, address)
Пример #7
0
    def test2_rename_contact_name(self):
        """
        Simple operation to see if that contact allows to change names.
        """
        contact = create_contact(name='Contact 2', phone='12345567')
        contact.name = 'Renamed Contact'
        contact.save()

        # Check if the object is a contact
        self.assertTrue(isinstance(contact, Contact))

        # Check if the contact's name has actually changed
        self.assertEqual(contact.name, 'Renamed Contact')
Пример #8
0
    def setUp(self):
        c1 = create_contact('contact 1', '123456', '*****@*****.**')
        a1 = create_address('Fake Street 123', c1)
        c2 = create_contact('contact 2', '234567', '*****@*****.**')
        a2 = create_address('Fake Street 234', c2)
        c3 = create_contact('contact 3', '345567', '*****@*****.**')
        a3 = create_address('Fake Street 345', c3)
        c4 = create_contact('contact 4', '456789', '*****@*****.**')
        a4 = create_address('Fake Street 456', c4)
        product1 = create_product('newspaper', 500)
        product2 = create_product('digital subscription', 250)
        product3 = create_product('magazine', 300)
        newsletter = create_product('amazing newsletter', 0)
        newsletter.type = 'N'
        newsletter.save()
        create_route(56, "Digital")

        # Then we need to create subscriptions for these people
        s1 = create_subscription(c1)
        s2 = create_subscription(c2)
        s3 = create_subscription(c3)
        s4 = create_subscription(c4)

        # Finally we need to add products to the subscriptions
        s1.add_product(product1, a1)
        s1.add_product(product2, a1)

        s2.add_product(product2, a2)

        s3.add_product(product1, a3)

        s4.add_product(product1, a4)
        s4.add_product(product2, a4)
        s4.add_product(product3, a4)

        # We will also subscribe 2 people to our amazing newsletter
        c1.add_newsletter(newsletter.id)
        c2.add_newsletter(newsletter.id)
Пример #9
0
    def test7_others_classes(self):
        # ADDRESS_TYPE_CHOICES = (
        # ('digital', _('Digital')),
        # ('physical', _('Physical'))
        contact = create_contact(name='Contact 9', phone='12412455')
        address = create_address('Araucho 1390',
                                 contact,
                                 address_type='physical')
        self.assertEqual(
            str(address),
            space_join(
                'Araucho 1390',
                space_join(getattr(settings, 'DEFAULT_CITY', None),
                           getattr(settings, 'DEFAULT_STATE', None)),
            ))

        address_type = address.get_type()
        self.assertEqual(address_type, _('Physical'))
Пример #10
0
    def test_1subscription_can_be_billed(self):
        contact = create_contact('cliente1', 29000808)
        subscription = create_subscription(contact)
        address = create_address('Treinta y Tres 1479',
                                 contact,
                                 address_type='physical')

        product = Product.objects.get(slug="newspaper")
        route_1 = Route.objects.get(number=1)

        subscription.add_product(
            product=product,
            address=address,
            route=
            route_1,  # if the setting to require a route is activated, this is mandatory
        )

        self.assertTrue(subscription.active)
        self.assertFalse(contact.is_debtor())
        invoice = bill_subscription(subscription.id, date.today(), 10)

        self.assertTrue(isinstance(invoice, Invoice))
        self.assertEqual(invoice.amount, product.price)
Пример #11
0
    def test_5_metodos_simples(self):
        # SUBSCRIPTION_PAYMENT_METHODS = (
        # ('O', 'Other'),
        # ('D', 'Debit'),
        # ('S', 'Cash payment'),
        contact = create_contact('cliente11', 21312)
        first_act = contact.get_first_active_subscription()
        self.assertFalse(first_act)  # None
        subscription = create_subscription(contact)
        self.assertTrue(subscription.active)
        has_active_sub = contact.has_active_subscription(True)
        self.assertEqual(has_active_sub, 1)
        first_act = contact.get_first_active_subscription()
        self.assertTrue(first_act)  # None

        open_issues = contact.has_no_open_issues()
        self.assertEqual(open_issues, True)

        prod_count = subscription.get_product_count()
        self.assertEqual(prod_count, 0)

        product1 = create_product('newspaper', 500)
        address = create_address('Araucho 1390',
                                 contact,
                                 address_type='physical')

        subscription.add_product(product1, address)
        status = 'A'
        contact.add_product_history(subscription, product1, status)

        # default name
        billing_name = subscription.get_billing_name()
        self.assertEqual(billing_name, 'cliente11')

        # default phone
        billing_phone = subscription.get_billing_phone()
        self.assertEqual(billing_phone, '21312')

        freq0 = subscription.get_frequency_discount()
        self.assertEqual(freq0, 0)

        # check that definitions exists
        subscription.frequency = 3  # white box test
        freq3 = subscription.get_frequency_discount()
        self.assertEqual(freq3, getattr(settings, "DISCOUNT_3_MONTHS", 0))

        subscription.frequency = 6  # white box test
        freq6 = subscription.get_frequency_discount()
        self.assertEqual(freq6, getattr(settings, "DISCOUNT_6_MONTHS", 0))

        subscription.frequency = 12  # white box test
        freq12 = subscription.get_frequency_discount()
        self.assertEqual(freq12, getattr(settings, "DISCOUNT_12_MONTHS", 0))

        first_day = subscription.get_first_day_of_the_week()
        # default value is 6 :: white box test
        self.assertEqual(first_day, 6)

        product2 = create_product('newspaper3', 1500)
        product2.weekday = 1
        subscription.add_product(product2, address)

        self.assertEqual(subscription.product_summary(), {
            product1.id: '1',
            product2.id: '1'
        })
Пример #12
0
    def test_4cliente_activo_debe_tener_ejemplares(self):

        contact = create_contact(u'cliente2asd', 21312)
        contact.save()
Пример #13
0
 def test_3cliente_que_no_tiene_email_debe_tener_email_en_blanco(self):
     contact = create_contact('cliente1', 21312)
     contact.no_email, contact.email = True, '*****@*****.**'
     # self.assertRaises(ValidationError, contact.save)
     contact.email = None
     contact.save()
Пример #14
0
 def test_1_contact_is_active_and_is_not_debtor(self):
     contact = create_contact('cliente1', 21312)
     subscription = create_subscription(contact)
     self.assertTrue(subscription.active)
     self.assertFalse(contact.is_debtor())