From ad714765d9f79f09ac44f40d2a89d63bc3cc81c4 Mon Sep 17 00:00:00 2001
From: Jerome Reybert <jreybert@gmail.com>
Date: Fri, 11 Mar 2016 21:30:34 +0100
Subject: [PATCH] test/commit*: add tests for commit (fix #73)

---
 test/commit.vader                 | 78 +++++++++++++++++++++++++++++++
 test/commit/commit_commit1.expect | 31 ++++++++++++
 test/commit/commit_commit2.expect | 38 +++++++++++++++
 test/commit/commit_diff1.expect   | 13 ++++++
 test/commit/commit_diff2.expect   |  8 ++++
 test/commit/commit_diff3.expect   | 35 ++++++++++++++
 test/test.config                  |  1 +
 7 files changed, 204 insertions(+)
 create mode 100644 test/commit.vader
 create mode 100644 test/commit/commit_commit1.expect
 create mode 100644 test/commit/commit_commit2.expect
 create mode 100644 test/commit/commit_diff1.expect
 create mode 100644 test/commit/commit_diff2.expect
 create mode 100644 test/commit/commit_diff3.expect

diff --git a/test/commit.vader b/test/commit.vader
new file mode 100644
index 0000000..7e5823a
--- /dev/null
+++ b/test/commit.vader
@@ -0,0 +1,78 @@
+Include: setup.inc
+
+Execute (Stage untracked file with magit#stage_hunk on end hunk):
+    call Cd_test_sub()
+    Magit
+
+    Log("Stage first hunk")
+    call Search_file('unstaged', 0)
+    call magit#open_close_folding(1)
+    /^@@ 
+    call Move_relative(+3)
+    call Cursor_position()
+    call magit#stage_hunk(0)
+
+    Log("Check first stage")
+    call Cd_test()
+    let diff=Git_diff('staged', Get_filename(0))
+    call Expect_diff(g:test_script_dir . 'commit/commit_diff1.expect', diff)
+    call Cd_test_sub()
+
+    Log("Start a commit")
+    call magit#commit_command('CC')
+    call append(line('.'), ['Add bootstrap file', '', 'Some description text', 'On multiple lines', '', 'With blanks'])
+
+    Log("Stage a second hunk")
+    call Search_file('unstaged', 1)
+    call magit#stage_hunk(0)
+
+    Log("Check second stage")
+    call Cd_test()
+    let diff=Git_diff('staged', Get_filename(1))
+    call Expect_diff(g:test_script_dir . 'commit/commit_diff2.expect', diff)
+
+    Log("Complete commit message")
+    call magit#commit_command('CC')
+    call append(line('.'), ['Add more line after refresh', ''])
+    call Cd_test_sub()
+
+    Log("Update buffer")
+    call cursor(1, 0)
+    call magit#update_buffer()
+    call cursor(line('$'), 0)
+    call magit#update_buffer()
+
+    call magit#commit_command('CC')
+    call magit#commit_command('CC')
+    call Cd_test()
+    let commit_msg=Git_commit_msg('HEAD')
+    call Expect_diff(g:test_script_dir . 'commit/commit_commit1.expect', commit_msg)
+
+    Log("Stage third hunk")
+    call Search_file('unstaged', 0)
+    call magit#open_close_folding(1)
+    /^@@ 
+    call magit#stage_hunk(0)
+
+    Log("Check third stage")
+    call Cd_test()
+    let diff=Git_diff('staged', Get_filename(0))
+    call Expect_diff(g:test_script_dir . 'commit/commit_diff3.expect', diff)
+
+    Log("Start a commit")
+    call magit#commit_command('CC')
+    call append(line('.'), ['Dont want these lines'])
+    call Cd_test_sub()
+
+    Log("Close commit")
+    call magit#close_commit()
+
+    Log("Finish commit")
+    call magit#commit_command('CC')
+    call append(line('.'), ['Uber commit message'])
+    call magit#commit_command('CC')
+    call Cd_test()
+    let commit_msg=Git_commit_msg('HEAD')
+    call Expect_diff(g:test_script_dir . 'commit/commit_commit2.expect', commit_msg)
+
+Include: cleanup.inc
diff --git a/test/commit/commit_commit1.expect b/test/commit/commit_commit1.expect
new file mode 100644
index 0000000..86f78e9
--- /dev/null
+++ b/test/commit/commit_commit1.expect
@@ -0,0 +1,31 @@
+Add more line after refresh
+
+Add bootstrap file
+
+Some description text
+On multiple lines
+
+With blanks
+
+
+diff --git books/models.py books/models.py
+--- books/models.py
++++ books/models.py
+@@ -1,5 +1,9 @@
+ from django.db import models
+ 
++import urllib2 as urllib
++from PIL import Image
++import io
++
+ import isbn_search
+ 
+ class User(models.Model):
+diff --git bootstrap bootstrap
+new file mode 100755
+--- /dev/null
++++ bootstrap
+@@ -0,0 +1,3 @@
++pip install --user python-amazon-simple-product-api django
++python manage.py migrate
++python manage.py makemigrations books
diff --git a/test/commit/commit_commit2.expect b/test/commit/commit_commit2.expect
new file mode 100644
index 0000000..4c521ef
--- /dev/null
+++ b/test/commit/commit_commit2.expect
@@ -0,0 +1,38 @@
+Uber commit message
+
+
+diff --git books/models.py books/models.py
+--- books/models.py
++++ books/models.py
+@@ -24,20 +24,26 @@ class BookManager(models.Manager):
+ 				eisbn   = product.eisbn,
+ 				author  = product.author,
+ 				title   = product.title,
+-				edition = product.edition
++				edition = product.edition,
+ 				)
++		if product.cover_url is not '':
++			cover_img_bin = urllib.urlopen(product.cover_url)
++			cover_img_file = Image.open(io.BytesIO(cover_img_bin.read()))
++			book.cover_img.save("cover.jpg", cover_img_file)
+ 		return book
+ 
++def upload_path(book, filename):
++	return 'covers/%s/%s' % (book.isbn, filename)
++
+ class Book(models.Model):
+ 	isbn = models.CharField(max_length=10, unique=True)
+-	eisbn = models.CharField(max_length=13, blank=True)
++	eisbn = models.CharField(max_length=13, blank=True, null=True)
+ 	title = models.CharField(max_length=200)
+ 	author = models.CharField(max_length=200)
+-	edition = models.CharField(max_length=200, blank=True)
+-	cover = models.ImageField(upload_to='covers', blank=True)
++	edition = models.CharField(max_length=200, blank=True, null=True)
++	cover_img = models.ImageField(upload_to=upload_path)
+ 	def __unicode__(self):
+ 		return u'[%s] "%s" by %s' % (self.isbn, self.title, self.author,)
+-
+ 	objects = BookManager()
+ 
+ 
diff --git a/test/commit/commit_diff1.expect b/test/commit/commit_diff1.expect
new file mode 100644
index 0000000..4d9138a
--- /dev/null
+++ b/test/commit/commit_diff1.expect
@@ -0,0 +1,13 @@
+diff --git books/models.py books/models.py
+--- books/models.py
++++ books/models.py
+@@ -1,5 +1,9 @@
+ from django.db import models
+ 
++import urllib2 as urllib
++from PIL import Image
++import io
++
+ import isbn_search
+ 
+ class User(models.Model):
diff --git a/test/commit/commit_diff2.expect b/test/commit/commit_diff2.expect
new file mode 100644
index 0000000..76e066c
--- /dev/null
+++ b/test/commit/commit_diff2.expect
@@ -0,0 +1,8 @@
+diff --git bootstrap bootstrap
+new file mode 100755
+--- /dev/null
++++ bootstrap
+@@ -0,0 +1,3 @@
++pip install --user python-amazon-simple-product-api django
++python manage.py migrate
++python manage.py makemigrations books
diff --git a/test/commit/commit_diff3.expect b/test/commit/commit_diff3.expect
new file mode 100644
index 0000000..cdc0a2f
--- /dev/null
+++ b/test/commit/commit_diff3.expect
@@ -0,0 +1,35 @@
+diff --git books/models.py books/models.py
+--- books/models.py
++++ books/models.py
+@@ -24,20 +24,26 @@ class BookManager(models.Manager):
+ 				eisbn   = product.eisbn,
+ 				author  = product.author,
+ 				title   = product.title,
+-				edition = product.edition
++				edition = product.edition,
+ 				)
++		if product.cover_url is not '':
++			cover_img_bin = urllib.urlopen(product.cover_url)
++			cover_img_file = Image.open(io.BytesIO(cover_img_bin.read()))
++			book.cover_img.save("cover.jpg", cover_img_file)
+ 		return book
+ 
++def upload_path(book, filename):
++	return 'covers/%s/%s' % (book.isbn, filename)
++
+ class Book(models.Model):
+ 	isbn = models.CharField(max_length=10, unique=True)
+-	eisbn = models.CharField(max_length=13, blank=True)
++	eisbn = models.CharField(max_length=13, blank=True, null=True)
+ 	title = models.CharField(max_length=200)
+ 	author = models.CharField(max_length=200)
+-	edition = models.CharField(max_length=200, blank=True)
+-	cover = models.ImageField(upload_to='covers', blank=True)
++	edition = models.CharField(max_length=200, blank=True, null=True)
++	cover_img = models.ImageField(upload_to=upload_path)
+ 	def __unicode__(self):
+ 		return u'[%s] "%s" by %s' % (self.isbn, self.title, self.author,)
+-
+ 	objects = BookManager()
+ 
+ 
diff --git a/test/test.config b/test/test.config
index 2ad3ab9..2cbd58e 100644
--- a/test/test.config
+++ b/test/test.config
@@ -7,5 +7,6 @@ declare -A test_scripts=(
             [ignoreFile.vader]='bootstrap'
             [addDir.vader]='newdir\/'
             [jump.vader]='books\/models.py|27|60|books\/isbn_search.py|54'
+            [commit.vader]='books/models.py|bootstrap'
 #[addSubmodule.vader]='subdjooks'
             )
-- 
GitLab