Esempio n. 1
0
    def setUp(self):
        self.crowd = Crowd(name='test_crowd')
        self.crowd.save()

        self.user = UserProfile(username='******',
                                email='*****@*****.**',
                                password='******',
                                crowd=self.crowd)
        self.user.save()

        # Include an appropriate `Authorization:` header on all requests.
        self.token = Token(user=self.user)
        self.token.save()

        self.category = Category(created_by=self.user,
                                 name='test_category',
                                 color='red',
                                 crowd=self.crowd)
        self.category.save()

        self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key)
        self.viewset = PostViewSet.as_view({
            'get': 'retrieve',
            'put': 'update',
            'patch': 'partial_update',
            'delete': 'destroy'
        })
Esempio n. 2
0
def buildnewpost():
    u = User(user_name="اضعر فرهادی")
    db.session.add(u)
    c1 = Category(cat_name="فرم ها")
    db.session.add(c1)
    c2 = Category(cat_name="وضعیت کلاس ها")
    db.session.add(c2)
    c3 = Category(cat_name="سرفصل دروس")
    db.session.add(c3)
    c4 = Category(cat_name="رشته های موجود")
    db.session.add(c4)
    c5 = Category(cat_name="آرشیو اخبار")
    db.session.add(c5)

    p = Post(
        post_title="همایش",
        post_content="همایش بزرگ مهندسین کامپیوتر در سرزمین دنیای کامپیوتر",
        post_date="2017/6/12",
        author=u,
        cat=c2)
    db.session.add(p)

    t = Tags(tagname="کامپیوتر")
    db.session.add(t)
    t.tags.append(p)
    db.session.commit()
Esempio n. 3
0
def buildPosts():
    posts = []
    con = """
    The new ComposerLinter subclass has been created, if you maintain or use a linter that uses Composer to install the dependency. Consider having that linter use ComposerLinter to get added
  benifits!

  JRuby <http://jruby.org/> support has been added! Any linter that uses the RubyLinter subclass will have search for jruby if no other ruby executable is found.

  You may have also noted SublimeLinter run a little faster lately. That's because in the last update we switched to the new usage of the async eventlisteners. You shouldn't see any negative effects but if you do please reach out to use in our Issue Tracker <https://github.com/SublimeLinter/SublimeLinter3/issues>

  Thank you for the continued support of SublimeLinter! We are extremely appreciative of your usage, support, and contributions.


    """
    for i in range(1, 6):
        u = User(user_name="ahmad " + str(i), password="******")

        db.session.add(u)

        p = Post(post_title="title" + str(i),
                 post_content=con + "",
                 post_date="2017",
                 author_id=i,
                 category_id=i)

        db.session.add(p)
        c = Category(cat_name="catgo " + str(i))
        db.session.add(c)
        admin = User('admin', '*****@*****.**')
        # posts.append(p)

    db.session.commit()
    return posts
Esempio n. 4
0
    def handle(self, *args, **kwargs):
        quantity = kwargs['quantity']
        api_off = ApiOff()
        for category in CATEGORIES:
            try:
                model_category = Category.objects.get(name=category)
            except:
                model_category = Category(name=category)
                model_category.save()

            products = api_off.research_products(category, quantity)
            for product in products:
                try:
                    model = Product(**product, category=model_category)
                    model.save()
                except:
                    continue
Esempio n. 5
0
def add_category(request, list_id):
    if request.method == "POST":
        if 'addList' in request.POST:
            list = Category(user=request.user)
            form = AddCategoryForm(instance=list, data=request.POST)
            if form.is_valid():
                updated = form.save()
                return open_money(request, updated.id)
    form = AddCategoryForm()
    return open_money(request, list_id)
def category_add(request):
    '''view for adding categories
    
        on http request GET returns the form
        on http request POST creates the category and redirects to categories view

        author: Levi Schubert
    '''

    if request.method == 'GET':
        category_form = CategoryForm()
        template_name = 'website/category_add.html'
        return render(request, template_name, {'category_form': category_form})

    elif request.method == 'POST':
        form_data = request.POST

        c = Category(name=form_data['name'], )
        c.save()
        return HttpResponseRedirect(f'/categories')
Esempio n. 7
0
def share_a_site():
    if request.method == 'GET':
        return render_template('site/share_a_site.html', is_authed=True)
    elif request.method == 'POST':
        title = request.form['site_title']
        desc = request.form['site_desc']
        url = request.form['site_url']
        category_name = request.form['site_category']

        user = User.query.filter_by(
            username=session['username']
        ).first()

        category = Category.query.filter_by(
            name=category_name
        ).first()

        if category is None:
            category = Category(user, category_name)

        site = Site(user, title, desc, url, category)
        db.session.add(site)
        db.session.commit()
        return redirect(url_for('index'))
Esempio n. 8
0
    def setUp(self):
        self.crowd = Crowd(name='test_crowd')
        self.crowd.save()

        self.user = UserProfile(username='******', email='*****@*****.**',
                                password='******', crowd=self.crowd)
        self.user.save()

        # Include an appropriate `Authorization:` header on all requests.
        self.token = Token(user=self.user)
        self.token.save()

        self.category = Category(created_by=self.user,
                                 name='test_category',
                                 color='red', crowd=self.crowd)
        self.category.save()

        self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key)
        self.viewset = PostViewSet.as_view({
            'get': 'retrieve',
            'put': 'update',
            'patch': 'partial_update',
            'delete': 'destroy'
        })
Esempio n. 9
0
class PostTests(APITestCase):
    def setUp(self):
        self.crowd = Crowd(name='test_crowd')
        self.crowd.save()

        self.user = UserProfile(username='******',
                                email='*****@*****.**',
                                password='******',
                                crowd=self.crowd)
        self.user.save()

        # Include an appropriate `Authorization:` header on all requests.
        self.token = Token(user=self.user)
        self.token.save()

        self.category = Category(created_by=self.user,
                                 name='test_category',
                                 color='red',
                                 crowd=self.crowd)
        self.category.save()

        self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key)
        self.viewset = PostViewSet.as_view({
            'get': 'retrieve',
            'put': 'update',
            'patch': 'partial_update',
            'delete': 'destroy'
        })

    def _get_response(self, urllib_mock, content_type):
        urllib_mock.headers.get.return_value = content_type
        return urllib_mock

    @mock.patch('website.models.Post._new_post_email')
    @mock.patch('urllib3.PoolManager')
    def test_create_text_post(self, urllib_mock, new_post_mock):
        urllib_mock = self._get_response(urllib_mock, 'text/html')
        url = reverse('post-list')
        data = {'category': self.category.id, 'title': 'test post'}
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual('text', response.data['type'])
        self.assertEqual(self.crowd.id, response.data['crowd']['id'])
        self.assertEqual(self.user.id, response.data['user']['id'])

        # Ensure we can get the post back
        get_response = self.client.get('{}{}/'.format(url,
                                                      response.data['id']))

        self.assertEqual(get_response.status_code, status.HTTP_200_OK)
        self.assertEqual(self.crowd.id, get_response.data['crowd']['id'])
        self.assertEqual(self.user.id, get_response.data['user']['id'])

    @mock.patch('website.models.Post._new_post_email')
    @mock.patch('urllib3.PoolManager')
    def test_create_url_post(self, urllib_mock, new_post_mock):
        urllib_mock = self._get_response(urllib_mock, 'text/html')
        url = reverse('post-list')
        data = {
            'category': self.category.id,
            'title': 'test post',
            'url': 'http://google.com/'
        }
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual('link', response.data['type'])
        self.assertEqual('http://google.com/', response.data['url'])
Esempio n. 10
0
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
from django.utils import timezone

from website.models import Product, Category, PurchaseOrder

# Create default instances using the app's models

category_list = [Category(1, 'Appliances'), Category(2, 'Bedroom Furniture')]

product_list = [
    Product(barcode='7891234123459',
            slug=None,
            title='Bread toaster',
            description='Lorem ipsum',
            image='bread_toaster.jpg',
            price=35.999,
            category_id=category_list[0].id),
    Product(barcode='2012345012349',
            slug=None,
            title='Wardrobe',
            description='Lorem ipsum',
            image='wardrobe.jpeg',
            price=55.990,
            category_id=category_list[1].id),
    Product(barcode='5901234123457',
            slug=None,
            title='Mattress',
            description='Lorem ipsum',
            image='mattress.jpg',
            price=800.724,
Esempio n. 11
0
    def test_repr(self):
        """ Test Category __repr__ method """

        expected_result = 'Category(description=Test123)'
        category = Category(description=self.description)
        self.assertEqual(repr(category), expected_result)
Esempio n. 12
0
    def test_instance(self):
        """ Test category Category constructor """

        category = Category(description=self.description)
        self.assertIsInstance(category, Category)
Esempio n. 13
0
class PostTests(APITestCase):
    def setUp(self):
        self.crowd = Crowd(name='test_crowd')
        self.crowd.save()

        self.user = UserProfile(username='******', email='*****@*****.**',
                                password='******', crowd=self.crowd)
        self.user.save()

        # Include an appropriate `Authorization:` header on all requests.
        self.token = Token(user=self.user)
        self.token.save()

        self.category = Category(created_by=self.user,
                                 name='test_category',
                                 color='red', crowd=self.crowd)
        self.category.save()

        self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key)
        self.viewset = PostViewSet.as_view({
            'get': 'retrieve',
            'put': 'update',
            'patch': 'partial_update',
            'delete': 'destroy'
        })

    def _get_response(self, urllib_mock, content_type):
        urllib_mock.headers.get.return_value = content_type
        return urllib_mock

    @mock.patch('website.models.Post._new_post_email')
    @mock.patch('urllib3.PoolManager')
    def test_create_text_post(self, urllib_mock, new_post_mock):
        urllib_mock = self._get_response(urllib_mock, 'text/html')
        url = reverse('post-list')
        data = {'category': self.category.id, 'title': 'test post'}
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual('text', response.data['type'])
        self.assertEqual(self.crowd.id, response.data['crowd']['id'])
        self.assertEqual(self.user.id, response.data['user']['id'])

        # Ensure we can get the post back
        get_response = self.client.get(
            '{}{}/'.format(url, response.data['id']))

        self.assertEqual(get_response.status_code, status.HTTP_200_OK)
        self.assertEqual(self.crowd.id, get_response.data['crowd']['id'])
        self.assertEqual(self.user.id, get_response.data['user']['id'])

    @mock.patch('website.models.Post._new_post_email')
    @mock.patch('urllib3.PoolManager')
    def test_create_url_post(self, urllib_mock, new_post_mock):
        urllib_mock = self._get_response(urllib_mock, 'text/html')
        url = reverse('post-list')
        data = {'category': self.category.id, 'title': 'test post',
                'url': 'http://google.com/'}
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual('link', response.data['type'])
        self.assertEqual('http://google.com/', response.data['url'])
Esempio n. 14
0
 def test_repr(self):
     category = Category(description=self.description)
     expected_result = self.description
     self.assertEqual(repr(category), expected_result)
Esempio n. 15
0
 def test_str(self):
     expected_result = self.description
     category = Category(description=self.description)
     self.assertEqual(str(category), expected_result)
Esempio n. 16
0
 def test_instance(self):
     category = Category(description=self.description)
     self.assertIsInstance(category, Category)