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 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 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
def add_org(): admin = None user = None data = request.get_json() if "name" not in data or "email" not in data or "admin" not in data or "pass" not in data: abort(400) # First, we need to check if there are already users with this email admin = Administrator.query.filter_by(email=data['email']).first() if admin is not None: abort(409) user = CommonUser.query.filter_by(email=data['email']).first() if user is not None: abort(409) # Creating new organization, add administrator and user org = Organization(data['name']) admin = Administrator(name=data['admin'], email=data['email']) user = CommonUser(name=data['admin'], email=data['email']) admin.hash_password(data['pass']) user.hash_password(data['pass']) org.administrators.append(admin) org.users.append(user) db_session.add(org) db_session.add(admin) db_session.add(user) db_session.commit() return jsonify(status="ok")
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()
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()
def test_organization_create(VO): ''' Test creation of organization ''' # instantiate and save VO.org = Organization(name='test_org_%s' % uuid.uuid4().hex, description='') VO.org.save() assert type(VO.org.id) == int
def get_or_create_dummy(cls, organization=None): """ Creates a POM with Checkout test merchant. Suitable for development, but try to use it in production and you'll get 500 ISE. """ from core.models import Organization if organization is None: organization, uwused = Organization.get_or_create_dummy() return cls.objects.get_or_create( organization=organization, defaults=META_DEFAULTS, )
def sign_up(): if request.method == "GET": return render_template("signup.html", title="Application :: Sign Up") else: data = request.get_json() try: if not data['name'] or not data['email'] or not data[ 'pass'] or not data['plan'] or not data['admin']: abort(safeglobals.http_bad_request, {'message': safeglobals.error_mandatory_missing}) except KeyError: abort(safeglobals.http_bad_request, {'message': safeglobals.error_mandatory_missing}) # Checking that no user with this "email" already exists user = Administrator.query.filter_by(email=data['email']).first() if user is not None: abort(safeglobals.http_conflict, {'message': safeglobals.error_account_exists}) user = CommonUser.query.filter_by(email=data['email']).first() if user is not None: abort(safeglobals.http_conflict, {'message': safeglobals.error_account_exists}) # Creating new Administrator admin = Administrator(data['admin'], data['email']) admin.hash_password(data['pass']) # Getting all services services = Service.query.all() # Common user user = CommonUser(data['admin'], data['email']) user.hash_password(data['pass']) user.services = services # Creating a plan plan = Plan.query.get(data['plan']) # Creating organization org = Organization(data['name']) org.administrators.append(admin) org.users.append(user) org.plan = plan org.set_expiration_values(data['plan']) org.set_premium(data['plan']) db_session.add(org) db_session.add(admin) db_session.add(user) db_session.commit() return jsonify( status=safeglobals.http_created), safeglobals.http_created
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_context_data(self, **kwargs): context = super(Account, self).get_context_data(**kwargs) try: organization = Organization.objects.get(user=self.request.user) context['organization_form'] = OrganizationForm(user=self.request.user, instance=organization) context['staff'] = Staff.objects.filter(organization=organization) context['instance'] = organization except ObjectDoesNotExist: context['organization_form'] = OrganizationForm(user=self.request.user) context['instance'] = Organization() context['new_account'] = self.is_new context['cv_form'] = CVForm() context['new_password_form'] = SetNewPasswordForm(self.request) context['user'] = self.request.user context['business_needed'] = self.business_needed context['categories'] = Category.objects.get_tree() return context
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}")
def list_orgs(): result = Organization.list() orgs = [] for item in result: orgs.append({"name": item.name, "id": item.id}) return jsonify(orgs)
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
class RelationshipOrganization: organization = Organization() relationship = Relationship()
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)
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')
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'])