Esempio n. 1
0
class AdddonDeleteTest(TestCase):
    def create_test_superuser(self):
        self.client = Client()
        self.username = '******'
        self.email = '*****@*****.**'
        self.password = '******'
        User.objects.create_superuser(self.username, self.email, self.password)
        self.client.login(username=self.username, password=self.password)

    def setUp(self):
        self.event = Event()
        self.addon = Addon()

    def tearDown(self):
        self.event = None
        self.addon = None
        self.client = None
        self.username = None
        self.email = None
        self.password = None

    def create_instances(self):
        self.event.title = 'Test Event'
        self.event.save()
        self.addon.title = 'Test Addon'
        self.addon.event = self.event
        self.addon.save()

    def test_delete_addon_method(self):
        self.create_instances()
        addon_pk = self.addon.pk

        logger.info('Testing new delete method of Addon model.')
        self.addon.delete(from_db=True)
        with self.assertRaises(Addon.DoesNotExist):
            Addon.objects.get(pk=addon_pk)
        with self.assertRaises(Addon.DoesNotExist):
            Addon.objects.get(title='Test Addon')
        logger.info('Complete.')

    def test_delete_addon_view(self):
        self.create_instances()
        self.create_test_superuser()
        addon_pk = self.addon.pk
        delete_addon_link = reverse('event.delete_addon',
                                    kwargs={
                                        'event_id': self.event.id,
                                        'addon_id': addon_pk
                                    })

        response = self.client.get(delete_addon_link)
        logger.info('Testing new delete addon view.')
        self.assertEqual(response.status_code, 302)
        with self.assertRaises(Addon.DoesNotExist):
            Addon.objects.get(pk=addon_pk)
        with self.assertRaises(Addon.DoesNotExist):
            Addon.objects.get(title='Test Addon')
        logger.info('Complete.')
Esempio n. 2
0
class AdddonDeleteTest(TestCase):

    def create_test_superuser(self):
        self.client = Client()
        self.username = '******'
        self.email = '*****@*****.**'
        self.password = '******'
        User.objects.create_superuser(self.username, self.email, self.password)
        self.client.login(username=self.username, password=self.password)

    def setUp(self):
        self.event = Event()
        self.addon = Addon()

    def tearDown(self):
        self.event = None
        self.addon = None
        self.client = None
        self.username = None
        self.email = None
        self.password = None

    def create_instances(self):
        self.event.title = 'Test Event'
        self.event.save()
        self.addon.title = 'Test Addon'
        self.addon.event = self.event
        self.addon.save()

    def test_delete_addon_method(self):
        self.create_instances()
        addon_pk = self.addon.pk

        logger.info('Testing new delete method of Addon model.')
        self.addon.delete(from_db=True)
        with self.assertRaises(Addon.DoesNotExist):
            Addon.objects.get(pk=addon_pk)
        with self.assertRaises(Addon.DoesNotExist):
            Addon.objects.get(title='Test Addon')
        logger.info('Complete.')

    def test_delete_addon_view(self):
        self.create_instances()
        self.create_test_superuser()
        addon_pk = self.addon.pk
        delete_addon_link = reverse(
            'event.delete_addon',
            kwargs={'event_id': self.event.id, 'addon_id': addon_pk})

        response = self.client.get(delete_addon_link)
        logger.info('Testing new delete addon view.')
        self.assertEqual(response.status_code, 302)
        with self.assertRaises(Addon.DoesNotExist):
            Addon.objects.get(pk=addon_pk)
        with self.assertRaises(Addon.DoesNotExist):
            Addon.objects.get(title='Test Addon')
        logger.info('Complete.')
Esempio n. 3
0
def do_event_import(event_object_dict):
    """Creates and Event and Place for the given event_object_dict
    """
    event = Event()
    place = Place()

    # assure the correct fields get the right value types
    color_set = TypeColorSet.objects.all()[0]  # default color set
    for field in EVENT_FIELDS:
        if field in event_object_dict:
            if field == "type":
                try:
                    event_type = Type.objects.get(name=event_object_dict[field])
                except Type.DoesNotExist:
                    event_type = Type(
                                    name=event_object_dict[field],
                                    slug=slugify(event_object_dict[field]),
                                    color_set=color_set
                                    )
            else:
                field_type = Event._meta.get_field_by_name(field)[0]
                if isinstance(field_type, models.DateTimeField):
                    setattr(event, field, datetime.strptime(event_object_dict[field], VALID_DATE_FORMAT))
                elif isinstance(field_type, models.BooleanField):
                    if event_object_dict[field].lower() == "false" or event_object_dict[field] == "0":
                        setattr(event, field, False)
                    else:
                        setattr(event, field, True)
                else:  # assume its a string
                    if field_type.max_length:
                        setattr(event, field, unicode(event_object_dict[field])[:field_type.max_length])
                    else:
                        setattr(event, field, unicode(event_object_dict[field]))

    for field in PLACE_FIELDS:
        if field in event_object_dict:
            p_field = field.replace('place__', '')
            field_type = Place._meta.get_field_by_name(p_field)[0]
            if isinstance(field_type, models.DateTimeField):
                setattr(place, p_field, datetime.strptime(event_object_dict[field], VALID_DATE_FORMAT))
            elif isinstance(field_type, models.BooleanField):
                setattr(place, p_field, bool(ast.literal_eval(event_object_dict[field])))
            else:  # assume its a string
                if field_type.max_length:
                    setattr(place, p_field, unicode(event_object_dict[field])[:field_type.max_length])
                else:
                    setattr(place, p_field, unicode(event_object_dict[field]))

    event_type.save()
    place.save()

    event.type = event_type
    event.place = place
    event.save()

    return event
Esempio n. 4
0
def do_event_import(event_object_dict):
    """Creates and Event and Place for the given event_object_dict
    """
    event = Event()
    place = Place()

    # assure the correct fields get the right value types
    color_set = TypeColorSet.objects.all()[0]  # default color set
    for field in EVENT_FIELDS:
        if field in event_object_dict:
            if field == "type":
                try:
                    event_type = Type.objects.get(name=event_object_dict[field])
                except Type.DoesNotExist:
                    event_type = Type(
                                    name=event_object_dict[field],
                                    slug=slugify(event_object_dict[field]),
                                    color_set=color_set
                                    )
            else:
                field_type = Event._meta.get_field_by_name(field)[0]
                if isinstance(field_type, models.DateTimeField):
                    setattr(event, field, datetime.strptime(event_object_dict[field], VALID_DATE_FORMAT))
                elif isinstance(field_type, models.BooleanField):
                    if event_object_dict[field].lower() == "false" or event_object_dict[field] == "0":
                        setattr(event, field, False)
                    else:
                        setattr(event, field, True)
                else:  # assume its a string
                    if field_type.max_length:
                        setattr(event, field, unicode(event_object_dict[field])[:field_type.max_length])
                    else:
                        setattr(event, field, unicode(event_object_dict[field]))

    for field in PLACE_FIELDS:
        if field in event_object_dict:
            p_field = field.replace('place__', '')
            field_type = Place._meta.get_field_by_name(p_field)[0]
            if isinstance(field_type, models.DateTimeField):
                setattr(place, p_field, datetime.strptime(event_object_dict[field], VALID_DATE_FORMAT))
            elif isinstance(field_type, models.BooleanField):
                setattr(place, p_field, bool(ast.literal_eval(event_object_dict[field])))
            else:  # assume its a string
                if field_type.max_length:
                    setattr(place, p_field, unicode(event_object_dict[field])[:field_type.max_length])
                else:
                    setattr(place, p_field, unicode(event_object_dict[field]))

    event_type.save()
    place.save()

    event.type = event_type
    event.place = place
    event.save()

    return event
Esempio n. 5
0
 def setUp(self):
     self.event = Event()
     self.addon = Addon()
Esempio n. 6
0
 def setUp(self):
     self.event = Event()
     self.addon = Addon()