Esempio n. 1
0
def create_organization(data, party):
    organization = Organization()
    organization.party = party
    organization.startDate = date.today()
    organization.endDate = date.max
    organization.name = data.get('name')
    organization.infoText = data.get('infoText')
    organization.save()
    return organization
Esempio n. 2
0
 def setUp(self):
     self.user_cache = get_user_model()(email="*****@*****.**")
     self.user_cache.set_password("123")
     self.user_cache.save()
     self.factory = RequestFactory()
     business = Organization(
         user=self.user_cache,
         name="Name",
         inn=146465464654,
         ogrn=146465464654,
         address_1="address",
         address_2="address",
         state="State",
         country="ru",
         email="*****@*****.**",
         phone="+37494303029",
     )
     business.save()
Esempio n. 3
0
class TestOrganizationProductAPIView(TestCase):
    def setUp(self):
        self.user_cache = get_user_model().objects.create_user(
            email="*****@*****.**",
            password='******',
            phone='+79261473805',
        )
        self.organization_cache = Organization(
            user=self.user_cache,
            name="Name",
            inn=146465464654,
            ogrn=146465464654,
            address_1="address",
            address_2="address",
            state="State",
            country="ru",
            email="*****@*****.**",
            phone="+37494303029",
        )
        self.category_cache = Category.objects.create(name="Category title")

        self.organization_cache.save()
        self.factory = RequestFactory()
        self.client = Client(HTTP_HOST='example.com')
        self.client.login(username=self.user_cache.email, password='******')

    def get_test_data(self):
        return {
            'name': 'Product name',
            'category': str(self.category_cache.pk),
            'description': 'Some long smart text goes here',
            'price': '188.12',
            'quantity': '3',
            'kind': '1',
            'organization': str(self.organization_cache.pk),
            'is_featured': '1',
            'is_popular': '0',
            'image': create_in_memory_test_image()
        }

    def test_correct_create(self):
        data = self.get_test_data()
        response = self.client.post(reverse('api-products-list'), data=data)
        response.render()
Esempio n. 4
0
 def handle(self, new=False, **options):
     #new = options.get('new', None)
     if new:
         import os
         db_file_path = os.path.join(BASE_DIR,'db.sqlite3')
         core_migrations_path = os.path.join(BASE_DIR,'core/migrations')
         photologue_migrations_path = os.path.join(BASE_DIR,'photologue/migrations')
         manage_file_path = os.path.join(BASE_DIR, 'manage.py')
         photo_file_path = os.path.join(BASE_DIR, 'mediaroot/photo')
         doc_file_path = os.path.join(BASE_DIR, 'mediaroot/filer_public')
         markdown_extension_file_path = os.path.join(BASE_DIR, 'simpleeditor/markdown_extension/simpleeditor.py')
         import site
         SITE_PACKAGE_DIR = [x for x in site.getsitepackages() if ('dist-packages' in x) or ('site-packages' in x)][0]
         markdown_extension_path = os.path.join(SITE_PACKAGE_DIR, 'markdown/extensions')
         import subprocess
         print 'removing existing databases...'
         p=subprocess.Popen(["rm -f "+db_file_path],stdin=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         (out,err) = p.communicate()
         if err != '':
              print err
              return
         print 'removing existing migrations...'
         p2=subprocess.Popen(["rm -r -f "+core_migrations_path],stdin=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         (out,err) = p2.communicate()
         if err != '':
              print err
              return
         p3=subprocess.Popen(["rm -r -f "+photologue_migrations_path],stdin=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         (out,err) = p3.communicate()
         if err != '':
              print err
              return
         print 'removing existing photo files...'
         
         p5=subprocess.Popen(["rm -r -f "+photo_file_path],stdin=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         (out,err) = p5.communicate()
         if err != '':
              print err
              return
         p6=subprocess.Popen(["git rm --ignore-unmatch -r -f "+photo_file_path],stdin=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         (out,err) = p6.communicate()
         if err != '':
              print err
              return
         print 'removing existing document files...'
         
         p5=subprocess.Popen(["rm -r -f "+doc_file_path],stdin=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         (out,err) = p5.communicate()
         if err != '':
              print err
              return
         p6=subprocess.Popen(["git rm --ignore-unmatch -r -f "+doc_file_path],stdin=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         (out,err) = p6.communicate()
         if err != '':
              print err
              return
         print 'syncing database...'
         p4=subprocess.Popen(["python "+manage_file_path+" syncdb"],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         p4.stdin.write("yes\n")
         p4.stdin.flush()
         p4.stdin.write("[email protected]\n")
         p4.stdin.flush()
         print 'Email: [email protected]'
         (out,err) = p4.communicate()
         if err != '':
              print err
              return
         print 'setting up photologue...'
         print 'creating size \'admin_thumbnail\''
         p4=subprocess.Popen(["python "+manage_file_path+" plcreatesize admin_thumbnail"],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         p4.stdin.write("100\n")#width
         p4.stdin.write("100\n")#height
         p4.stdin.write("yes\n")#crop to fit
         p4.stdin.write("yes\n")#pre cache
         p4.stdin.write("yes\n")#increment count
         print 'creating size \'activity_cover_small\''
         p4=subprocess.Popen(["python "+manage_file_path+" plcreatesize activity_cover_small"],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         p4.stdin.write("100\n")#width
         p4.stdin.write("100\n")#height
         p4.stdin.write("yes\n")#crop to fit
         p4.stdin.write("yes\n")#pre cache
         p4.stdin.write("yes\n")#increment count
         print 'creating size \'activity_cover_medium\''
         p4=subprocess.Popen(["python "+manage_file_path+" plcreatesize activity_cover_medium"],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         p4.stdin.write("180\n")#width
         p4.stdin.write("180\n")#height
         p4.stdin.write("no\n")#crop to fit
         p4.stdin.write("yes\n")#pre cache
         p4.stdin.write("yes\n")#increment count
         print 'creating size \'activity_cover_large\''
         p4=subprocess.Popen(["python "+manage_file_path+" plcreatesize activity_cover_large"],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         p4.stdin.write("320\n")#width
         p4.stdin.write("320\n")#height
         p4.stdin.write("no\n")#crop to fit
         p4.stdin.write("yes\n")#pre cache
         p4.stdin.write("yes\n")#increment count
         print 'creating size \'photo_small\''
         p4=subprocess.Popen(["python "+manage_file_path+" plcreatesize photo_small"],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         p4.stdin.write("100\n")#width
         p4.stdin.write("100\n")#height
         p4.stdin.write("yes\n")#crop to fit
         p4.stdin.write("yes\n")#pre cache
         p4.stdin.write("yes\n")#increment count
         print 'creating size \'photo_medium\''
         p4=subprocess.Popen(["python "+manage_file_path+" plcreatesize photo_medium"],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         p4.stdin.write("300\n")#width
         p4.stdin.write("300\n")#height
         p4.stdin.write("no\n")#crop to fit
         p4.stdin.write("yes\n")#pre cache
         p4.stdin.write("yes\n")#increment count
         print 'creating size \'photo_large\''
         p4=subprocess.Popen(["python "+manage_file_path+" plcreatesize photo_large"],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         p4.stdin.write("600\n")#width
         p4.stdin.write("600\n")#height
         p4.stdin.write("no\n")#crop to fit
         p4.stdin.write("yes\n")#pre cache
         p4.stdin.write("yes\n")#increment count
         print 'setting up markdown...'
         p4=subprocess.Popen(["cp -rf "+markdown_extension_file_path+" "+markdown_extension_path],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
         (out,err) = p4.communicate()
         if err != '':
              print err
              return
         print 'setting up development environment...'
         print 'creating first organization (for development only)'
         from core.models import Organization
         org = Organization(username="******",email="*****@*****.**")
         org.set_password("123456")
         org.save()
         print 'creating first user (for development only)'
         from core.models import User
         usr = User(first_name="W",last_name="TF",email="*****@*****.**")
         usr.set_password("123456")
         usr.save()
         print "site successfully deployed!"
     else:
         print self.usage_str
Esempio n. 5
0
class TestOrganizationProductSerializer(TestCase):
    def setUp(self):
        self.user_cache = get_user_model().objects.create_user(
            email="*****@*****.**",
            password='******',
            phone='+79261473805',
        )
        self.organization_cache = Organization(
            user=self.user_cache,
            name="Name",
            inn=146465464654,
            ogrn=146465464654,
            address_1="address",
            address_2="address",
            state="State",
            country="ru",
            email="*****@*****.**",
            phone="+37494303029",
        )
        self.category_cache = Category.objects.create(name="Category title")

        self.organization_cache.save()
        self.factory = RequestFactory()

    def get_test_data(self):
        return {
            'name': 'Product name',
            'category': str(self.category_cache.pk),
            'description': 'Some long smart text goes here',
            'price': '188.12',
            'quantity': '3',
            'kind': '1',
            'organization': str(self.organization_cache.pk),
            'is_featured': '1',
            'is_popular': '0',
            'image': create_in_memory_test_image()
        }

    def test_correct_create(self):
        data = self.get_test_data()
        serializer = OrganizationProductSerializer(
            data=data, context={'user': self.user_cache})
        self.assertTrue(serializer.is_valid(), serializer.errors)
        inst = serializer.save()

        self.assertEqual(inst.name, data['name'])
        self.assertEqual(inst.price, Decimal(data['price']))
        self.assertEqual(inst.description, data['description'])
        self.assertEqual(inst.quantity, int(data['quantity']))
        organization_product = inst.organizationproduct_set.first()
        self.assertEqual(organization_product.category, self.category_cache)
        self.assertEqual(organization_product.is_featured,
                         data['is_featured'] != '0')
        self.assertEqual(organization_product.is_popular,
                         data['is_popular'] != '0')

    def test_correct_update(self):
        data = self.get_test_data()
        serializer = OrganizationProductSerializer(
            data=data, context={'user': self.user_cache})
        self.assertTrue(serializer.is_valid(), serializer.errors)
        inst = serializer.save()

        data = self.get_test_data()
        data['name'] = 'Changed product name'
        data['price'] = '43423.123'
        data['is_featured'] = '0'
        data['is_popular'] = '1'
        serializer = OrganizationProductSerializer(
            data=data, instance=inst, context={'user': self.user_cache})
        self.assertTrue(serializer.is_valid(), serializer.errors)
        inst = serializer.save()

        self.assertEqual(inst.name, data['name'])
        self.assertEqual(inst.price, Decimal(data['price']))
        self.assertEqual(inst.description, data['description'])
        self.assertEqual(inst.kind, int(data['kind']))
        self.assertEqual(inst.quantity, int(data['quantity']))
        organization_product = inst.organizationproduct_set.first()
        self.assertEqual(organization_product.category, self.category_cache)
        self.assertEqual(organization_product.is_featured,
                         data['is_featured'] != '0')
        self.assertEqual(organization_product.is_popular,
                         data['is_popular'] != '0')
Esempio n. 6
0
class TestVisitorMessageSerializer(TestCase):
    def setUp(self):
        self.user_cache = get_user_model().objects.create_user(
            email="*****@*****.**",
            password='******',
            phone='+79261473805',
        )
        self.organization_cache = Organization(
            user=self.user_cache,
            name="Name",
            inn=146465464654,
            ogrn=146465464654,
            address_1="address",
            address_2="address",
            state="State",
            country="ru",
            email="*****@*****.**",
            phone="+37494303029",
        )
        self.organization_cache.save()
        self.factory = RequestFactory()
        self.test_data = {
            'email': '*****@*****.**',
            'phone': "+79261473805",
            'text': 'Some long smart text goes here',
            'send_to': '1',
            'organization': str(self.organization_cache.pk),
        }

    def test_correct_create(self):
        serializer = VisitorMessageSerializer(data=self.test_data)
        self.assertTrue(serializer.is_valid(), serializer.errors)
        instance = serializer.save()
        self.assertTrue(instance.phone_status == 0)
        self.assertTrue(instance.email_status == 0)
        self.assertEqual(instance.phone, self.test_data['phone'])
        self.assertEqual(instance.email, self.test_data['email'])
        self.assertEqual(str(instance.send_to), self.test_data['send_to'])

        # now we have an authorized user with unverified phone and email
        serializer = VisitorMessageSerializer(
            data=self.test_data, context={'user': self.user_cache})
        self.assertTrue(serializer.is_valid(), serializer.errors)
        instance = serializer.save()
        self.assertTrue(instance.phone_status == 0)
        self.assertTrue(instance.email_status == 0)
        self.assertEqual(instance.phone, self.test_data['phone'])
        self.assertEqual(instance.email, self.test_data['email'])

        # now we have an authorized user with verified phone and email
        self.user_cache.is_email_confirmed = True
        self.user_cache.is_phone_confirmed = True
        self.user_cache.save()
        serializer = VisitorMessageSerializer(
            data=self.test_data, context={'user': self.user_cache})
        self.assertTrue(serializer.is_valid(), serializer.errors)
        instance = serializer.save()
        self.assertTrue(instance.phone_status == 1)
        self.assertTrue(instance.email_status == 1)
        self.assertEqual(instance.phone, self.test_data['phone'])
        self.assertEqual(instance.email, self.test_data['email'])
Esempio n. 7
0
class TestVacancySerializer(TestCase):
    user_cache = None

    def setUp(self):
        self.user_cache = get_user_model().objects.create_user(
            email="*****@*****.**", password='******')
        self.factory = RequestFactory()
        self.organization_cache = Organization(
            user=self.user_cache,
            name="Name",
            inn=146465464654,
            ogrn=146465464654,
            address_1="address",
            address_2="address",
            state="State",
            country="ru",
            email="*****@*****.**",
            phone="+37494303029",
        )
        self.organization_cache.save()
        self.vacancy_data = {
            'organization': str(self.organization_cache.pk),
            'name': "Position Name",
            'description': "Long description goes here...",
            'specialization': 'Engineer',
            'degree': "2",
            'languages': 'English,Russian,German',
            'skills': 'Python,Django,MySQL,Oracle',
            'user': str(self.user_cache.pk),
        }

    def get_vacancy_data(self):
        ret = {}
        ret.update(self.vacancy_data)
        return ret

    def test_correct_input(self):
        data = self.get_vacancy_data()
        serializer = VacancySerializer(data=data,
                                       context={'user': self.user_cache})
        self.assertTrue(serializer.is_valid(), serializer.errors)
        vacancy = serializer.save()
        self.assertEqual(vacancy.skills.count(), 4)
        self.assertEqual(vacancy.languages.count(), 3)
        self.assertEqual(vacancy.degree, 2)
        self.assertEqual(vacancy.specialization, 'Engineer')

    def test_incorrect_input(self):
        data = self.get_vacancy_data()
        del data['specialization']
        serializer = VacancySerializer(data=data,
                                       context={'user': self.user_cache})
        self.assertFalse(serializer.is_valid())
        self.assertTrue('non_field_errors' in serializer.errors,
                        serializer.errors)
        self.assertEqual('Education value is incomplete',
                         serializer.errors['non_field_errors'][0],
                         serializer.errors['non_field_errors'][0])

    def test_correct_update(self):
        data = self.get_vacancy_data()
        serializer = VacancySerializer(data=data,
                                       context={'user': self.user_cache})
        serializer.is_valid(True)
        vacancy = serializer.save()
        data['degree'] = '3'
        data['languages'] = 'German,Italian,English'
        data['skills'] = 'Python,Django,NodeJS'
        data['name'] += '_changed'
        update_serializer = VacancySerializer(
            instance=vacancy, data=data, context={'user': self.user_cache})
        self.assertTrue(update_serializer.is_valid())
        instance = update_serializer.save()
        self.assertEqual(instance.skills.count(), 3,
                         [s.name for s in instance.skills.all()])
        self.assertEqual(instance.languages.count(), 3)
        self.assertEqual(instance.name, data['name'])

        # check for old values deleted
        self.assertEqual(Language.objects.all().count(), 3)
        self.assertEqual(Skill.objects.all().count(), 3)
Esempio n. 8
0
    def handle(self, *args, **kwargs):
        schema_name = kwargs['schema_name']

        public_orgs = Organization.objects.filter(schema_name='public')
        if schema_name != 'public' and not public_orgs.exists():
            print(f"[!] Error: 'public' organization must be created first")
            raise

        print(
            f"[+] Creating new Organization (schema_name: {schema_name}) "
            f"in 3s... (press Ctrl+C to cancel)"
        )
        sleep(3)
        org = Organization.objects.filter(schema_name=schema_name).last()
        if org:
            org.save()
            print(
                f"[i] Organization {schema_name} already exists:\n    "
                f"Organization #{org.short_id} ({org.name})"
            )
        else:
            org = Organization(
                id=None,
                schema_name=schema_name,
                name=schema_name,
            )
            org.save()
            print(
                f"[√] New organization {schema_name} created:\n    "
                f"Organization #{org.short_id} ({org.name})"
            )

        # Create tenant superuser
        if schema_name == 'public':
            print(f'[+] Creating global tenant admin tenant superuser...')
        else:
            print(f'[+] Creating {schema_name} tenant superuser...')

        user = (
            User.objects
                .filter(is_superuser=True, organization_id=org.id)
                .order_by('created')
                .last()
        )

        create_superuser = True
        if user:
            print(
                f"[i] Tenant superuser '{user.username}' already exists:\n    "
                f"User #{user.short_id} org: {user.organization}"
            )
            create_superuser =\
                input('Add another superuser? y/[n]: ')[0].lower() == 'y'

        if create_superuser:
            call_command('createsuperuser')
            user = User.objects\
                .filter(is_superuser=True).order_by('created').last()
            assert user is not None,\
                'A user did not exist after createsuperuser ran (did it fail?)'
            user.organization_id = org.id
            user.save()
            print(
                f"[√] New tenant superuser {user.username} was created:\n    "
                f"User #{user.short_id} org: {user.organization}"
            )

        orphaned_users = list(User.objects.filter(organization_id=None))
        if orphaned_users:
            print(f"[!] Warning: Users exist without an org: {orphaned_users}")